Module: RenderHelper

Extended by:
T::Sig
Defined in:
lib/frontman/helpers/render_helper.rb

Instance Method Summary collapse

Instance Method Details

#partial(template, data = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/frontman/helpers/render_helper.rb', line 18

def partial(template, data = {})
  partial_dir = Frontman::Config.get(
    :partial_dir, fallback: 'views/partials'
  )
  r = Frontman::Resource.from_path(
    File.join(partial_dir, template), nil, false
  )

  # While rendering, if there's no current page we set it to to the resource
  # This allows using `content_for` directives in partials
  current_page = Frontman::App.instance.current_page
  Frontman::App.instance.current_page = r if current_page.nil?

  content = r.render(nil, data)

  Frontman::App.instance.current_page = current_page

  content
end

#render_current_page(options = {}) ⇒ Object



56
57
58
# File 'lib/frontman/helpers/render_helper.rb', line 56

def render_current_page(options = {})
  render_page(Frontman::App.instance.current_page, options)
end

#render_erb(content, template_data = nil) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/frontman/helpers/render_helper.rb', line 74

def render_erb(content, template_data = nil)
  context = Frontman::Context.new

  if !template_data.nil? && template_data
    template_data.each do |key, value|
      context.singleton_class.send(:define_method, key) { value }
    end
  end

  compiled = Frontman::ErbRenderer.instance.compile(content)
  Frontman::ErbRenderer.instance.render(compiled, nil, context, {})
end

#render_markdown(content) ⇒ Object



61
62
63
64
65
66
# File 'lib/frontman/helpers/render_helper.rb', line 61

def render_markdown(content)
  compiled = Frontman::MarkdownRenderer.instance.compile(content)
  Frontman::MarkdownRenderer.instance.render(
    compiled, nil, Frontman::Context.new, {}
  )
end

#render_page(page, options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/frontman/helpers/render_helper.rb', line 43

def render_page(page, options = {})
  # We force not to render any layout
  options[:layout] = nil
  options[:ignore_page] = true

  # We don't need to cache here since it already done in the render function
  # of the resource
  page.render(nil, options)
end