Class: Ligarb::MermaidChecker
- Inherits:
-
Object
- Object
- Ligarb::MermaidChecker
- Defined in:
- lib/ligarb/mermaid_checker.rb
Overview
Build-time syntax check for mermaid blocks. Runs the downloaded mermaid.min.js under Node (assets/mermaid_check.mjs) and calls mermaid.parse() on each block. Reports syntax errors as warnings with file:line locations; never fails the build (the generated HTML already shows an error box for broken diagrams at view time).
Constant Summary collapse
- HARNESS =
File.("../../assets/mermaid_check.mjs", __dir__)
Class Method Summary collapse
-
.check(chapters, mermaid_js) ⇒ Object
chapters: Chapter objects (mermaid_blocks may be empty) mermaid_js: path to the provisioned mermaid.min.js Returns the number of blocks with syntax errors.
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(chapters, mermaid_js) ⇒ MermaidChecker
constructor
A new instance of MermaidChecker.
Constructor Details
#initialize(chapters, mermaid_js) ⇒ MermaidChecker
Returns a new instance of MermaidChecker.
22 23 24 25 |
# File 'lib/ligarb/mermaid_checker.rb', line 22 def initialize(chapters, mermaid_js) @chapters = chapters @mermaid_js = mermaid_js end |
Class Method Details
.check(chapters, mermaid_js) ⇒ Object
chapters: Chapter objects (mermaid_blocks may be empty) mermaid_js: path to the provisioned mermaid.min.js Returns the number of blocks with syntax errors.
18 19 20 |
# File 'lib/ligarb/mermaid_checker.rb', line 18 def self.check(chapters, mermaid_js) new(chapters, mermaid_js).check end |
Instance Method Details
#check ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ligarb/mermaid_checker.rb', line 27 def check blocks = collect_blocks return 0 if blocks.empty? unless File.exist?(@mermaid_js) warn "Warning: #{@mermaid_js} not found; skipping mermaid syntax check" return 0 end results = run_harness(blocks) return 0 unless results error_count = 0 results.each do |result| error = result["error"] next unless error error_count += 1 block = blocks[result["id"]] warn "Warning: mermaid syntax error in #{block[:location]}" error.each_line { |l| warn " #{l.chomp}" } end error_count end |