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, options, body_html, toc_data) ⇒ Object
- #render_static(document, body_html, options) ⇒ 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, 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, , body_html, toc_data) dist_dir = [:dist_dir] || File.('../../../frontend/dist', __dir__) assets = load_dist_assets(dist_dir) content_data = build_spa_content_data(document, body_html, , 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, , assets, safe_json)).strip else build_spa_fallback(document, , 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, ) layout_template = load_layout('default') return build_static_fallback(document, body_html, ) unless layout_template layout_template.render(build_static_layout_data(document, body_html, )).strip end |