Class: LiquidXlsx::TemplateParser
- Inherits:
-
Object
- Object
- LiquidXlsx::TemplateParser
- Defined in:
- lib/liquid_xlsx/template_parser.rb
Overview
Parses worksheet rows into an AST of template nodes.
Constant Summary collapse
- FOR_START =
rubocop:disable Metrics/ClassLength
/\A\{%-?\s*for\s+(\w+)\s+in\s+([\w.]+)\s*-?%\}\z/- FOR_END =
/\A\{%-?\s*endfor\s*-?%\}\z/- IF_START =
/\A\{%-?\s*if\s+((?:(?!%\}).)+)\s*-?%\}\z/- ELSIF =
/\A\{%-?\s*elsif\s+((?:(?!%\}).)+)\s*-?%\}\z/- ELSE_TAG =
/\A\{%-?\s*else\s*-?%\}\z/- ENDIF =
/\A\{%-?\s*endif\s*-?%\}\z/- STRUCTURAL_KEYWORDS =
/\A\{%-?\s*(for|endfor|if|elsif|else|endif)\b/- MIXED_STRUCTURAL =
/\{%-?\s*(?:for|endfor|if|elsif|else|endif)\b/- PURE_STRUCTURAL =
[FOR_START, FOR_END, IF_START, ELSIF, ELSE_TAG, ENDIF].freeze
- NON_STRUCTURAL_PAIR_RE =
Matches balanced pairs of non-structural Liquid blocks so they can be masked before MIXED_STRUCTURAL checks.
/ \{%-?\s* (case|unless|capture|comment|raw|tablerow) \b .*?%\} .*? \{%-?\s*end\1\s*-?%\} /mx
Instance Attribute Summary collapse
-
#sheet_name ⇒ Object
readonly
Returns the value of attribute sheet_name.
Instance Method Summary collapse
-
#initialize(rows, sheet_name = "Sheet1") ⇒ TemplateParser
constructor
A new instance of TemplateParser.
- #parse ⇒ Object
Constructor Details
#initialize(rows, sheet_name = "Sheet1") ⇒ TemplateParser
Returns a new instance of TemplateParser.
29 30 31 32 33 |
# File 'lib/liquid_xlsx/template_parser.rb', line 29 def initialize(rows, sheet_name = "Sheet1") @rows = rows @sheet_name = sheet_name @pos = 0 end |
Instance Attribute Details
#sheet_name ⇒ Object (readonly)
Returns the value of attribute sheet_name.
27 28 29 |
# File 'lib/liquid_xlsx/template_parser.rb', line 27 def sheet_name @sheet_name end |
Instance Method Details
#parse ⇒ Object
35 36 37 38 39 |
# File 'lib/liquid_xlsx/template_parser.rb', line 35 def parse nodes = [] nodes << parse_element while @pos < @rows.length nodes end |