forked from bkiers/Liqp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix rendering of custom tags with more than one parameter (bkiers#301)
* Improved parsing of flavor-specific tag 'include_relative' * In Jekyll style, 'include_relative' was represented as token SimpleTag, instead of IncludeRelative, as expected since PR bkiers#288. * As a consequence, filename components were parsed as separate parameters instead of token file_name_or_output. This behaviour got unnoticed only because all parameters were incorrectly concatenated into one string (to be fixed outside of this commit) * In Liquid style, tag 'include_relative' is not defined (token InvalidTagId), but can be defined as a custom block (token SimpleBlock) or a tag (SimpleTag). * To facilitate flavor-specific lexical analysis, flag isLiquidStyleInclude was was added to LiquidLexer; same code as in the LiquidParser since bkiers#196 * Fixed custom tags with more than one parameter * All tag parameters were concatenated into one string, e.g. {% mu for foo as bar %} was presented as one node ["forfooasbar"] in Tag method render() * Caused by combining text of all childen of token 'other_tag_parameters' in NodeVisitor.visitSimple_tag(). Change to one string in bkiers#227 seems to be not intentional; reverting to a list * This commit separates each parameter to a distinct node, i.e. ["for", "foo", "as", "bar"]
- Loading branch information
Showing
4 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'pp' | ||
require_relative '_helpers.rb' | ||
|
||
# pp render({"val" => "here"}, "{{ val }}") | ||
|
||
if isJekyll | ||
context = jekyllContext("includes_dir" => "cases_variable_inside_import/_includes") | ||
# Tag 'render' is not defined in Jekyll. Use 'include' or 'include_relative' | ||
assertRaise do | ||
assertEqual("TEST", render({}, "{% render color.liquid %}", context)) | ||
end | ||
else | ||
Liquid::Template.file_system = Liquid::LocalFileSystem.new("cases_variable_inside_import/_includes", "%s.liquid") | ||
|
||
# liquid template name must be a quoted string | ||
assertRaise do | ||
assertEqual("there", render({"var" => "there", "tmpl" => "include_read_var"}, "{% render tmpl %}")) | ||
end | ||
# render variables | ||
assertEqual("", render({"var" => "there"}, "{% render 'include_read_var' %}")) | ||
assertEqual("here", render({"var" => "there"}, "{% render 'include_read_var', var: 'here' %}")) | ||
assertEqual("there", render({"var" => "there"}, "{% render 'include_read_var', var: var %}")) | ||
assertEqual("color: ''", render({"color" => "red"}, "{% render 'color' %}")) | ||
assertEqual("color: 'blue'", render({"color" => "red"}, "{% render 'color', color: 'blue' %}")) | ||
assertEqual("color: 'red'", render({"color" => "red"}, "{% render 'color', color: color %}")) | ||
# render with | ||
assertEqual("color: 'red'", render({"var" => "there"}, "{% render 'color' with 'red' %}")) | ||
assertEqual("color: 'red'", render({"var" => "there"}, "{% render 'color' with 'red', color: 'blue' %}")) | ||
assertEqual("color: 'blue'", render({"clr" => "blue"}, "{% render 'color' with clr %}")) | ||
assertEqual("color: 'blue'", render({"clr" => "blue"}, "{% render 'color' with clr, color: 'green' %}")) | ||
# render for | ||
assertEqual("color: 'r'color: 'g'color: 'b'", render({"colors" => ["r", "g", "b"]}, "{% render 'color' for colors %}")) | ||
assertEqual("rgb", render({"colors" => ["r", "g", "b"]}, "{% render 'include_read_var' for colors as var %}")) | ||
assertEqual("foofoofoo", render({"colors" => ["r", "g", "b"]}, "{% render 'include_read_var' for colors as clr, var: 'foo' %}")) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters