Class: Rain::Raindown

Inherits:
Object
  • Object
show all
Defined in:
lib/pages/raindown/raindown.rb

Instance Method Summary collapse

Constructor Details

#initialize(metadata: {}) ⇒ Raindown

Returns a new instance of Raindown.



9
10
11
# File 'lib/pages/raindown/raindown.rb', line 9

def initialize(metadata: {})
  @metadata = 
end

Instance Method Details

#render(markdown:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pages/raindown/raindown.rb', line 13

def render(markdown:)
  template = markdown.gsub('<{', '<!-- ANTLERS').gsub('}>', 'ANTLERS -->')

  doc = Commonmarker.parse(template)
  doc.walk do |node|
    if node.type == :code || node.type == :code_block
      node.string_content = node.string_content.gsub('<!-- ANTLERS', '<{').gsub('ANTLERS -->', '}>')
    end
  end

  template = doc.to_html(options: { render: { unsafe: true } })
  template = template.gsub('<!-- ANTLERS', '<{').gsub('ANTLERS -->', '}>')

  return template unless template.include?('<{') || template.include?('{')

  ast = Antlers.ast(template:, elements: Antlers::Elements[:html, :prop] + Rain::Elements[:toc])

  Antlers.render(ast:, current_binding: binding)
end