Module: Chiridion::Engine::TemplateRenderer::Filters
- Defined in:
- lib/chiridion/engine/template_renderer.rb
Overview
Custom Liquid filters for documentation rendering.
Instance Method Summary collapse
-
#escape_pipes(input) ⇒ Object
Escape pipe characters for markdown table cells.
-
#kebab_case(input) ⇒ Object
Convert to kebab case for file paths.
-
#normalize_headers(input, min_level = 3) ⇒ Object
Normalize markdown headers to be subordinate to a given level.
-
#strip_newlines(input) ⇒ Object
Remove newlines for single-line table cells.
-
#strip_rbs_blocks(input) ⇒ Object
Strip @rbs! blocks from docstrings (type metadata shouldn’t be in docs).
Instance Method Details
#escape_pipes(input) ⇒ Object
Escape pipe characters for markdown table cells.
21 22 23 24 25 |
# File 'lib/chiridion/engine/template_renderer.rb', line 21 def escape_pipes(input) return "" if input.nil? input.to_s.gsub("|", "\\|") end |
#kebab_case(input) ⇒ Object
Convert to kebab case for file paths.
35 36 37 38 39 40 41 42 43 |
# File 'lib/chiridion/engine/template_renderer.rb', line 35 def kebab_case(input) return "" if input.nil? input.to_s .gsub(/([A-Za-z])([vV]\d+)/, '\1-\2') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1-\2') .gsub(/([a-z\d])([A-Z])/, '\1-\2') .downcase end |
#normalize_headers(input, min_level = 3) ⇒ Object
Normalize markdown headers to be subordinate to a given level. Usage: docstring | normalize_headers: 4 } Adjusts all headers so the minimum level becomes the specified level.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/chiridion/engine/template_renderer.rb', line 55 def normalize_headers(input, min_level = 3) return "" if input.nil? || input.to_s.empty? text = input.to_s lines = text.lines # Find the minimum header level in the text header_levels = lines.filter_map do |line| match = line.match(/^(#+)\s/) match[1].length if match end return text if header_levels.empty? current_min = header_levels.min offset = min_level.to_i - current_min return text if offset <= 0 # Prepend offset number of # to all header lines prefix = "#" * offset lines.map do |line| if line.match?(/^#+\s/) prefix + line else line end end.join end |
#strip_newlines(input) ⇒ Object
Remove newlines for single-line table cells.
28 29 30 31 32 |
# File 'lib/chiridion/engine/template_renderer.rb', line 28 def strip_newlines(input) return "" if input.nil? input.to_s.gsub(/\s*\n\s*/, " ").strip end |
#strip_rbs_blocks(input) ⇒ Object
Strip @rbs! blocks from docstrings (type metadata shouldn’t be in docs).
46 47 48 49 50 |
# File 'lib/chiridion/engine/template_renderer.rb', line 46 def strip_rbs_blocks(input) return "" if input.nil? input.to_s.gsub(/@rbs![\s\S]*?(?=\n\n|\z)/, "").strip end |