Class: Liquid::Autoescape::TemplateVariable
- Inherits:
-
Object
- Object
- Liquid::Autoescape::TemplateVariable
- Defined in:
- lib/liquid/autoescape/template_variable.rb
Overview
A wrapper around a Liquid variable used in a template
This provides a consistent interface to a Liquid variable, accounting for structural differences in variables between different Liquid versions and exposing a simple list of applied filters. All exemptions are determined by examining instances of this object.
Instance Attribute Summary collapse
-
#filters ⇒ Array<Symbol>
readonly
The names of the filters applied to the variable.
-
#name ⇒ String
readonly
The name of the variable.
Class Method Summary collapse
-
.from_liquid_variable(variable) ⇒ Liquid::Autoescape::TemplateVariable
Create a wrapper around a Liquid variable instance.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ TemplateVariable
constructor
Create a wrapper around a Liquid variable used in a template.
Constructor Details
#initialize(options = {}) ⇒ TemplateVariable
Create a wrapper around a Liquid variable used in a template
66 67 68 69 |
# File 'lib/liquid/autoescape/template_variable.rb', line 66 def initialize(={}) @name = .fetch(:name) @filters = [:filters] || [] end |
Instance Attribute Details
#filters ⇒ Array<Symbol> (readonly)
The names of the filters applied to the variable
20 21 22 |
# File 'lib/liquid/autoescape/template_variable.rb', line 20 def filters @filters end |
#name ⇒ String (readonly)
The name of the variable
15 16 17 |
# File 'lib/liquid/autoescape/template_variable.rb', line 15 def name @name end |
Class Method Details
.from_liquid_variable(variable) ⇒ Liquid::Autoescape::TemplateVariable
Create a wrapper around a Liquid variable instance
This normalizes the variable’s information, since Liquid handles variable names differently across versions.
31 32 33 34 35 36 |
# File 'lib/liquid/autoescape/template_variable.rb', line 31 def from_liquid_variable(variable) name = normalize_variable_name(variable) filters = variable.filters.map { |f| f.first.to_sym } new(:name => name, :filters => filters) end |