ChiliProject is not maintained anymore. Please be advised that there will be no more updates.

We do not recommend that you setup new ChiliProject instances and we urge all existing users to migrate their data to a maintained system, e.g. Redmine. We will provide a migration script later. In the meantime, you can use the instructions by Christian Daehn.

Allow plugins to register custom static and lazy evaluated variables (Feature #790)


Added by Holger Just at 2011-12-26 12:05 pm. Updated at 2012-01-05 10:47 pm.


Status:Closed Start date:2011-12-26
Priority:Normal Due date:
Assignee:Holger Just % Done:

0%

Category:Text formatting
Target version:3.0.0
Remote issue URL: Affected version:3.0.0

Description

Currently, it is impossible for plugins to register custom variables to Liquid. This should be changed.

I propose the following API to register variables (Pull Request forthcoming):

 1ChiliProject::Liquid::Variables.register "macro_list",
 2  "Use '{{ variables | to_list: \"Variables\" }}' to see all Liquid variables and '{{ tags | to_list: \"Tags\" }}' to see all of the Liquid tags." 
 3
 4ChiliProject::Liquid::Variables.register "tags" do
 5  ::Liquid::Template.tags.keys.sort
 6end
 7
 8ChiliProject::Liquid::Variables.register "variables" do |context|
 9  vars = []
10
11  vars = context.environments.first.keys.reject do |var|
12    # internal variable
13    var == "text" 
14  end if context.environments.present?
15  vars += context.scopes.collect(&:keys).flatten
16  vars.uniq.sort
17end

The API will allow to register static variables (which contain data generated during loading of the Application) or lazily evaluated variables. These will be evaluated every time they are used.

The main difference to Drops is that these variables can be easily overwritten and act exactly the same as user-defined variables.


Associated revisions

Revision 4458a728
Added by Jean-Philippe Lang at 2008-03-07 06:15 pm

Translations (closes #789, #790, #798, #803, #809):
  • Danish added (Mads Vestergaard)
  • Polish updated (Mariusz Olejnik)
  • Finnish updated (Antti Perkiömäki)
  • Simplified Chinese updated (chaoqun zou)
  • Traditional Chinese updated (shortie lo)

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1204 e93f8b46-1217-0410-a6f0-8f06a7374b81

Revision 3c3eb2f7
Added by Holger Just at 2012-01-05 11:36 pm

[#790] Register variables with an API

Revision 446f9439
Added by Holger Just at 2012-01-05 11:36 pm

[#790] Add filter to output an array into an unordered list

Revision f1324e6a
Added by Holger Just at 2012-01-05 11:36 pm

[#790] Replace TagList and VariableList tags with variables

Revision b080ad14
Added by Holger Just at 2012-01-05 11:36 pm

[#790] Test the lazy variables

History

Updated by Holger Just at 2011-12-26 01:14 pm

See the pull request at https://github.com/chiliproject/chiliproject/pull/147

It would be great if somebody could quickly review it if that is the concept we would like to follow.

Basically, it does three things:

  1. It adds an API to register variables which can be either static or lazily evaluated
  2. It adds a to_list filter which formats all elements of an array as an unordered list
  3. It removes the variable_list and tag_list tags in favor of variables formatted with the new filter

Updated by Holger Just at 2011-12-26 03:34 pm

  • Status changed from Open to Ready for review

Updated by Holger Just at 2012-01-05 10:47 pm

I just merged the pull request.

  • Status changed from Ready for review to Closed

Also available in: Atom PDF