Class: Coradoc::Html::LayoutRenderer

Inherits:
Object
  • Object
show all
Includes:
TemplateCaching
Defined in:
lib/coradoc/html/layout_renderer.rb

Constant Summary collapse

LAYOUT_DIR =
Pathname.new(File.join(File.dirname(__FILE__), 'templates', 'layouts'))

Instance Method Summary collapse

Constructor Details

#initializeLayoutRenderer

Returns a new instance of LayoutRenderer.



13
14
15
16
# File 'lib/coradoc/html/layout_renderer.rb', line 13

def initialize
  @template_cache = {}
  @dist_assets_cache = {}
end

Instance Method Details

#render_spa(document, options, body_html, toc_data) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/coradoc/html/layout_renderer.rb', line 25

def render_spa(document, options, body_html, toc_data)
  dist_dir = options[:dist_dir] || File.expand_path('../../../frontend/dist', __dir__)
  assets = load_dist_assets(dist_dir)

  content_data = build_spa_content_data(document, body_html, options, toc_data)
  safe_json = Escape.safe_json(content_data)

  layout_template = load_layout('spa')
  if layout_template
    layout_template.render(build_spa_layout_data(document, options, assets, safe_json)).strip
  else
    build_spa_fallback(document, options, assets, safe_json)
  end
end

#render_static(document, body_html, options) ⇒ Object



18
19
20
21
22
23
# File 'lib/coradoc/html/layout_renderer.rb', line 18

def render_static(document, body_html, options)
  layout_template = load_layout('default')
  return build_static_fallback(document, body_html, options) unless layout_template

  layout_template.render(build_static_layout_data(document, body_html, options)).strip
end