[Sputnik-list] activators

Yuri Takhteyev yuri at sims.berkeley.edu
Tue Feb 19 05:42:50 GMT+2 2008


 >  For the "Ticket:16" : I tracked it down to SmartNode:new
 >     self.activators.lua = function(value, helpers)
 >        return versium.luaenv.Sandbox:new(helpers.config):do_lua(value
 >  or "")
 >     end
 >  But I can't grasp what activators represent an when function get
 >  executed.

 (Adding the list to CC.)

 Activators turn the content of a field into something other than a
 string.  Eventually there will be pluggable activators, but for now
 versium.smart.smartnode hard-codes two options:

 "lua": assumes that the field contains Lua code, runs it, and sets the
 field to the environment created by that Lua code.

 For instance if the field is set to [[ x = 2; y = 3]] and it's
 activator is set to "lua" then this field will be available to Sputnik
 as a table with two fields: x and y.

 "node_list": assumes that the field's value is a new-line delimited
 list of node IDs, and sets the field to a table of node IDs.

 So, if the field is set to

 [[_templates
 _templates_blueprint]]

 and it's activator is "node_list" then the field will eventually get
 set to {"_templates", "_templates_blueprint"}

 If you are wondering why this makes sense, consider that the "initial"
 value of the field includes inherited value.  So, let's say that "Foo"
 has @Root as a prototype.  @Root sets:

 translations= [=[_translations]=]
 fields.translations    = {0.51, proto="concat", activate="node_list"}

 Foo sets:

 translations=[=[_translations_for_foo]=]

 I.e., when editing "Foo" the user just need to type
 "_translations_for_foo" for the translations field, no braces, etc.

 However, when Foo is loaded, translations gets set to
 @Root.translations.."\n"..Foo.translations (because
 Foo.fields.translations.proto=="concat") and then to {"_translations",
 "_translations_for_foo"} (because
 Foo.fields.translations.activate=="node_list").  The rest of the code
 can assume that Foo.translations is a table.

 (BTW, .51 is a weight that determines the order in the edit form, so
 don't worry about it.)

  - yuri



More information about the Sputnik-list mailing list