working on pages...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-04-21 18:33:08 +03:00
parent 6f3a0c75a6
commit cd5171848f
2 changed files with 75 additions and 30 deletions

View File

@ -1,10 +1,15 @@
BOOTSTRAP_FILES := \ BOOTSTRAP_FILES := \
$(wildcard bootstrap/*) \ $(wildcard bootstrap/*) \
$(wildcard bootstrap/*/*) \ $(wildcard bootstrap/*/*) \
README.md README.md
LOCAL_MODULES := \
node_modules/ig-object/object.js \
node_modules/ig-actions/actions.js \
node_modules/ig-features/features.js
@ -21,11 +26,8 @@ node_modules:
npm install npm install
dev: node_modules dev: node_modules $(LOCAL_MODULES)
cp $</ig-object/object.js lib/ cp $(LOCAL_MODULES) lib/
cp $</ig-actions/actions.js lib/
cp $</ig-features/features.js lib/
clean: clean:

View File

@ -20,6 +20,10 @@
(function(require){ var module={} // make module AMD/node compatible... (function(require){ var module={} // make module AMD/node compatible...
/*********************************************************************/ /*********************************************************************/
// XXX
//var object = require('lib/object')
var object = require('ig-object')
/*********************************************************************/ /*********************************************************************/
@ -138,7 +142,11 @@ module.path = {
var store = var store =
module.store = { module.store = {
exists: function(path){ exists: function(path){
return module.path.normalize(path, 'string') in this }, path = module.path.normalize(path, 'string')
return path in this
|| (path[0] == '/' ?
path.slice(1) in this
: ('/'+ path) in this) },
paths: function(){ paths: function(){
return Object.keys(this) }, return Object.keys(this) },
@ -268,7 +276,7 @@ module.actions = {
__proto__: store, __proto__: store,
// base actions (virtual pages)... // base actions (virtual pages)...
'/System/raw': function(page, path){ 'System/raw': function(page, path){
return { text: this.get(path +'/..') } }, return { text: this.get(path +'/..') } },
// XXX ... // XXX ...
} }
@ -284,31 +292,66 @@ function(name){
...args) } } ...args) } }
// page interface... // page interface...
var page = var BasePage =
module.page = { module.BasePage =
object.Constructor('BasePage', {
store: undefined, store: undefined,
path: undefined, path: undefined,
referrer: undefined, referrer: undefined,
text: undefined, get data(){
return this.store.get(this.path) },
// XXX need to support pattern pages...
set data(value){
this.store.update(this.path, value) },
// shorthands...
// XXX need to support pattern pages...
get text(){
return this.data.text },
// XXX need to support pattern pages...
set text(value){
this.store.update(this.path, {text: value}) },
// relative proxies to store... // relative proxies to store...
exists: relProxy('exists'), exists: relProxy('exists'),
match: relProxy('match'), match: relProxy('match'),
// XXX should this return page objects???
get: relProxy('get'),
update: function(path='.', data, mode){
if(arguments.length == 1){
data = path
path = '.' }
return this.store.update(module.path.relative(this.path, path), data, mode) },
delete: relProxy('delete'), delete: relProxy('delete'),
// XXX get: function(path, referrer){
clear: function(){ return this.constructor(
}, this.store,
} module.path.relative(
this.path,
path
?? this.path),
referrer
?? this.path) },
// XXX should this be an iterator???
each: function(path){
var that = this
var paths = this.match(path)
paths = paths instanceof Array ?
paths
: [paths]
return paths
.map(function(path){
return that.get(path) }) },
map: function(func){
return this.each().map(func) },
filter: function(func){
return this.each().filter(func) },
reduce: function(func, dfl){
return this.each().reduce(func, dfl) },
__init__: function(store, path, referrer){
this.store = store
this.path = path
this.referrer = referrer },
})
//--------------------------------------------------------------------- //---------------------------------------------------------------------
@ -524,9 +567,7 @@ function*(str){
// XXX closure: macros // XXX closure: macros
var expand = var expand =
module.expand = module.expand =
function*(ast, state={}){ function*(page, ast, state={}){
// XXX PAGE...
var page
while(true){ while(true){
var {value, done} = ast.next() var {value, done} = ast.next()
if(done){ if(done){
@ -551,11 +592,13 @@ function*(ast, state={}){
yield res } } } yield res } } }
// XXX var Page =
var expandPage = module.Page =
module.expandPage = object.Constructor('Page', BasePage, {
function(page){ expand: function(state={}){
} return expand(this, parse(this.text), state)
.join('') },
})