Class: Liquid::Assign
Overview
Assign sets a variable in your template.
{% assign foo = 'monkey' %}
You can then use the variable later in the page.
{{ foo }}
Defined Under Namespace
Classes: ParseTreeVisitor
Constant Summary collapse
- Syntax =
/(#{VariableSignature}+)\s*=\s*(.*)\s*/om
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Attributes inherited from Tag
#line_number, #nodelist, #parse_context, #tag_name
Instance Method Summary collapse
- #blank? ⇒ Boolean
-
#initialize(tag_name, markup, options) ⇒ Assign
constructor
A new instance of Assign.
- #render(context) ⇒ Object
Methods inherited from Tag
Methods included from ParserSwitching
Constructor Details
#initialize(tag_name, markup, options) ⇒ Assign
Returns a new instance of Assign.
15 16 17 18 19 20 21 22 23 |
# File 'lib/liquid/tags/assign.rb', line 15 def initialize(tag_name, markup, ) super if markup =~ Syntax @to = $1 @from = Variable.new($2, ) else raise SyntaxError.new [:locale].t("errors.syntax.assign".freeze) end end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
13 14 15 |
# File 'lib/liquid/tags/assign.rb', line 13 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
13 14 15 |
# File 'lib/liquid/tags/assign.rb', line 13 def to @to end |
Instance Method Details
#blank? ⇒ Boolean
32 33 34 |
# File 'lib/liquid/tags/assign.rb', line 32 def blank? true end |
#render(context) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/liquid/tags/assign.rb', line 25 def render(context) val = @from.render(context) context.scopes.last[@to] = val context.resource_limits.assign_score += assign_score_of(val) ''.freeze end |