class Liquid::Assign
Assign sets a variable in your template.
{% assign foo = 'monkey' %}
You can then use the variable later in the page.
{{ foo }}
Constants
- Syntax
Attributes
from[R]
to[R]
Public Class Methods
new(tag_name, markup, options)
click to toggle source
Calls superclass method
Liquid::Tag.new
# File lib/liquid/tags/assign.rb, line 15 def initialize(tag_name, markup, options) super if markup =~ Syntax @to = $1 @from = Variable.new($2, options) else raise SyntaxError.new options[:locale].t("errors.syntax.assign".freeze) end end
Public Instance Methods
blank?()
click to toggle source
# File lib/liquid/tags/assign.rb, line 32 def blank? true end
render(context)
click to toggle source
# 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
Private Instance Methods
assign_score_of(val)
click to toggle source
# File lib/liquid/tags/assign.rb, line 38 def assign_score_of(val) if val.instance_of?(String) val.length elsif val.instance_of?(Array) || val.instance_of?(Hash) sum = 1 # Uses #each to avoid extra allocations. val.each { |child| sum += assign_score_of(child) } sum else 1 end end