Class: LiquidMarkdown::Render

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid_markdown/render.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, liquid_hash = {}) ⇒ Render

Returns a new instance of Render.



9
10
11
12
13
14
15
# File 'lib/liquid_markdown/render.rb', line 9

def initialize(template, liquid_hash={})
  @template = template
  @liquid_hash = liquid_hash
  @markdown_settings = {auto_ids: false, parse_block_html: true}
  @liquid_settings = {strict_filters: true, strict_variables: true}
  @global_filter_proc = ->(output) { output.is_a?(String) ? output.strip_html_tags : output }
end

Instance Attribute Details

#global_filter_procObject (readonly)

setup your html layout layout to wrap around your LiquidMarkdown output layout = “<html><head></head><body>{yield}</body></html>”



5
6
7
# File 'lib/liquid_markdown/render.rb', line 5

def global_filter_proc
  @global_filter_proc
end

#layoutObject



41
42
43
# File 'lib/liquid_markdown/render.rb', line 41

def layout
  @layout ||= ''
end

#liquid_hashObject (readonly)

setup your html layout layout to wrap around your LiquidMarkdown output layout = “<html><head></head><body>{yield}</body></html>”



5
6
7
# File 'lib/liquid_markdown/render.rb', line 5

def liquid_hash
  @liquid_hash
end

#liquid_settingsObject

Returns the value of attribute liquid_settings.



7
8
9
# File 'lib/liquid_markdown/render.rb', line 7

def liquid_settings
  @liquid_settings
end

#markdown_settingsObject

Returns the value of attribute markdown_settings.



7
8
9
# File 'lib/liquid_markdown/render.rb', line 7

def markdown_settings
  @markdown_settings
end

#templateObject (readonly)

setup your html layout layout to wrap around your LiquidMarkdown output layout = “<html><head></head><body>{yield}</body></html>”



5
6
7
# File 'lib/liquid_markdown/render.rb', line 5

def template
  @template
end

Instance Method Details

#htmlObject



17
18
19
20
# File 'lib/liquid_markdown/render.rb', line 17

def html
  rendered_content = markdown(liquidize)
  insert_into_template(rendered_content.to_html)
end

#insert_into_template(rendered_content) ⇒ Object



36
37
38
39
# File 'lib/liquid_markdown/render.rb', line 36

def insert_into_template(rendered_content)
  return rendered_content if layout == ''
  layout.sub('{{yield}}', rendered_content)
end

#liquidizeObject



31
32
33
34
# File 'lib/liquid_markdown/render.rb', line 31

def liquidize
  Liquid::Template.parse(@template)
      .render(@liquid_hash, @liquid_settings, global_filter: @global_filter_proc)
end

#markdown(template_value) ⇒ Object



27
28
29
# File 'lib/liquid_markdown/render.rb', line 27

def markdown(template_value)
  Kramdown::Document.new(template_value, @markdown_settings)
end

#textObject



22
23
24
25
# File 'lib/liquid_markdown/render.rb', line 22

def text
  rendered_content = markdown(liquidize)
  rendered_content.to_plain_text
end