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)
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
- 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
[#790] Register variables with an API
[#790] Add filter to output an array into an unordered list
[#790] Replace TagList and VariableList tags with variables
[#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:
- It adds an API to register variables which can be either static or lazily evaluated
- It adds a
to_list
filter which formats all elements of an array as an unordered list - It removes the
variable_list
andtag_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