Class: Coradoc::Html::LayoutRenderer
- Inherits:
-
Object
- Object
- Coradoc::Html::LayoutRenderer
- 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
-
#initialize ⇒ LayoutRenderer
constructor
A new instance of LayoutRenderer.
- #render_spa(document, opts, body_html, toc_data) ⇒ Object
- #render_static(document, body_html, opts) ⇒ Object
Constructor Details
#initialize ⇒ LayoutRenderer
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, opts, body_html, toc_data) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/coradoc/html/layout_renderer.rb', line 26 def render_spa(document, opts, body_html, toc_data) opts = RenderOptions.new(**opts) unless opts.is_a?(RenderOptions) dist_dir = opts.dist_dir || File.('../../../frontend/dist', __dir__) assets = load_dist_assets(dist_dir) content_data = build_spa_content_data(document, body_html, opts, 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, opts, assets, safe_json)).strip else build_spa_fallback(document, opts, assets, safe_json) end end |
#render_static(document, body_html, opts) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/coradoc/html/layout_renderer.rb', line 18 def render_static(document, body_html, opts) opts = RenderOptions.new(**opts) unless opts.is_a?(RenderOptions) layout_template = load_layout('default') return build_static_fallback(document, body_html, opts) unless layout_template layout_template.render(build_static_layout_data(document, body_html, opts)).strip end |