diff options
Diffstat (limited to 'acf/model/node.lua')
-rw-r--r-- | acf/model/node.lua | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/acf/model/node.lua b/acf/model/node.lua index a879dac..6546bdc 100644 --- a/acf/model/node.lua +++ b/acf/model/node.lua @@ -11,7 +11,7 @@ local class = object.class local super = object.super local pth = require('acf.path') -local update = require('acf.util').update +local util = require('acf.util') BoundMember = class() @@ -51,7 +51,14 @@ TreeNode = class() function TreeNode:init(context) local mt = getmetatable(self) - update(mt, context) + util.update(mt, context) + + mt.meta = {} + if mt.parent then + mt.meta['ui-name'] = getmetatable(mt.parent).mmeta( + pth.name(mt.path) + )['ui-name'] + end function mt.save(k, v) rawset(self, k, v) end function mt.get(k, create) return mt.load(k, create) end @@ -110,10 +117,20 @@ function Collection:init(context, params) local mt = getmetatable(self) - mt.meta = {type='collection', members=field:meta('$')} + mt.meta.type = 'collection' + mt.meta.members = field:meta('$') + mt.meta['ui-member'] = params.ui_member or string.gsub( + mt.meta['ui-name'], 's$', '' + ) function mt.valid_member(name) return true end - function mt.mmeta(name) return mt.meta.members end + + function mt.mmeta(name) + local res = util.copy(mt.meta.members) + res['ui-name'] = mt.meta['ui-member']..' '..name + return res + end + function mt.members() return mt.txn:get(mt.addr, 'table') or {} end function mt.validate() @@ -135,8 +152,13 @@ Mixed = class(Collection) function Mixed:init(context, params) super(self, Mixed):init(context, params) + -- TODO dynamic meta: list non-leaf children - getmetatable(self).meta = {type='mixed'} + local mt = getmetatable(self) + mt.meta = {type='mixed', ['ui-name']=mt.path} + function mt.mmeta(name) + return {type='mixed', ['ui-name']=pth.join(mt.path, name)} + end end |