Class: LiquidXlsx::Validation::LiquidUsage

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid_xlsx/validation/liquid_usage.rb

Overview

Walks a parsed Liquid template and collects what it refers to: variable paths, filter names, and the names it binds itself.

The point of doing this here rather than in the host application is that the host would have to parse every fragment a second time — and parse it with this gem's Liquid environment, or {% sheet %} and {% image_tag %} would come back as unknown tags. Handing back extracted usages keeps Liquid entirely on this side of the boundary.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLiquidUsage

Returns a new instance of LiquidUsage.



24
25
26
27
28
29
# File 'lib/liquid_xlsx/validation/liquid_usage.rb', line 24

def initialize
  @variables = []
  @filters   = []
  @assigns   = []
  @locals    = []
end

Instance Attribute Details

#assignsObject (readonly)

Returns the value of attribute assigns.



22
23
24
# File 'lib/liquid_xlsx/validation/liquid_usage.rb', line 22

def assigns
  @assigns
end

#filtersObject (readonly)

Returns the value of attribute filters.



22
23
24
# File 'lib/liquid_xlsx/validation/liquid_usage.rb', line 22

def filters
  @filters
end

#localsObject (readonly)

Returns the value of attribute locals.



22
23
24
# File 'lib/liquid_xlsx/validation/liquid_usage.rb', line 22

def locals
  @locals
end

#variablesObject (readonly)

Returns the value of attribute variables.



22
23
24
# File 'lib/liquid_xlsx/validation/liquid_usage.rb', line 22

def variables
  @variables
end

Class Method Details

.call(root) ⇒ Object

Tags whose bodies Liquid exposes through an attachment rather than a nodelist (case % branches).



16
17
18
19
20
# File 'lib/liquid_xlsx/validation/liquid_usage.rb', line 16

def self.call(root)
  collector = new
  collector.walk(root)
  collector
end

Instance Method Details

#walk(node) ⇒ Object



31
32
33
34
# File 'lib/liquid_xlsx/validation/liquid_usage.rb', line 31

def walk(node)
  visit(node)
  each_child(node) { |child| walk(child) }
end