Class: LiquidXlsx::Validator
- Inherits:
-
Object
- Object
- LiquidXlsx::Validator
- Defined in:
- lib/liquid_xlsx/validator.rb
Overview
Checks a template without rendering it and without any data.
Why this is not "render and see what happens": the renderer parses only the Liquid it actually executes (Renderer#cached_parse), so a typo inside an if % branch that this document does not take, or inside a loop over an empty collection, stays invisible until the day some other document takes that branch. It also stops at the first failure, and rendering executes the template against live records — printing a document is a side effect nobody asked for when all they did was upload a file.
So: parse everything, execute nothing, and report every problem found.
Constant Summary collapse
- LIQUID_MARKER =
/\{\{|\{%/
Instance Method Summary collapse
- #call ⇒ Validation::Result
-
#initialize(template_path, dynamic_sheets: false, known_filters: nil) ⇒ Validator
constructor
A new instance of Validator.
Constructor Details
#initialize(template_path, dynamic_sheets: false, known_filters: nil) ⇒ Validator
Returns a new instance of Validator.
23 24 25 26 27 28 |
# File 'lib/liquid_xlsx/validator.rb', line 23 def initialize(template_path, dynamic_sheets: false, known_filters: nil) @template_path = template_path @dynamic_sheets = dynamic_sheets @known_filters = known_filters&.map(&:to_s) @result = Validation::Result.new end |
Instance Method Details
#call ⇒ Validation::Result
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/liquid_xlsx/validator.rb', line 31 def call package = open_package return @result if package.nil? sheet_names = safe_sheet_names(package) @result.sheets.concat(sheet_names) package.sheets.each { |sheet_info| validate_sheet(package, sheet_info) } (sheet_names) check_filters @result rescue Nokogiri::XML::SyntaxError => e invalid_xlsx("Corrupt XML inside the workbook: #{e.}") end |