Class: PandaCms::EditorJs::Renderer
- Inherits:
-
Object
- Object
- PandaCms::EditorJs::Renderer
- Defined in:
- app/lib/panda_cms/editor_js/renderer.rb
Instance Attribute Summary collapse
-
#cache_store ⇒ Object
readonly
Returns the value of attribute cache_store.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#custom_renderers ⇒ Object
readonly
Returns the value of attribute custom_renderers.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #article(blocks, title: nil) ⇒ Object
-
#initialize(content, options = {}) ⇒ Renderer
constructor
A new instance of Renderer.
- #render ⇒ Object
- #section(blocks) ⇒ Object
Constructor Details
#initialize(content, options = {}) ⇒ Renderer
Returns a new instance of Renderer.
6 7 8 9 10 11 12 |
# File 'app/lib/panda_cms/editor_js/renderer.rb', line 6 def initialize(content, = {}) @content = content @options = @custom_renderers = .delete(:custom_renderers) || {} @cache_store = .delete(:cache_store) || Rails.cache @validate_html = .delete(:validate_html) || false end |
Instance Attribute Details
#cache_store ⇒ Object (readonly)
Returns the value of attribute cache_store.
4 5 6 |
# File 'app/lib/panda_cms/editor_js/renderer.rb', line 4 def cache_store @cache_store end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
4 5 6 |
# File 'app/lib/panda_cms/editor_js/renderer.rb', line 4 def content @content end |
#custom_renderers ⇒ Object (readonly)
Returns the value of attribute custom_renderers.
4 5 6 |
# File 'app/lib/panda_cms/editor_js/renderer.rb', line 4 def custom_renderers @custom_renderers end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'app/lib/panda_cms/editor_js/renderer.rb', line 4 def @options end |
Instance Method Details
#article(blocks, title: nil) ⇒ Object
27 28 29 30 31 32 |
# File 'app/lib/panda_cms/editor_js/renderer.rb', line 27 def article(blocks, title: nil) content = [] content << "<h1>#{title}</h1>" if title content << render_blocks(blocks) "<article>#{content.join("\n")}</article>" end |
#render ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'app/lib/panda_cms/editor_js/renderer.rb', line 14 def render return "" if content.nil? || !content.is_a?(Hash) || !content["blocks"] blocks = remove_empty_paragraphs(content["blocks"]) rendered = blocks.map { |block| render_block_with_cache(block) }.join("\n") @validate_html ? validate_html(rendered) : rendered end |
#section(blocks) ⇒ Object
23 24 25 |
# File 'app/lib/panda_cms/editor_js/renderer.rb', line 23 def section(blocks) "<section class=\"content-section\">#{render_blocks(blocks)}</section>" end |