Class: RenderEditorjs::Document
- Inherits:
-
Object
- Object
- RenderEditorjs::Document
- Includes:
- ActionView::Helpers::OutputSafetyHelper
- Defined in:
- lib/render_editorjs/document.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
Instance Method Summary collapse
-
#initialize(content, renderer = RenderEditorjs::DefaultRenderer.new) ⇒ Document
constructor
A new instance of Document.
- #render ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(content, renderer = RenderEditorjs::DefaultRenderer.new) ⇒ Document
Returns a new instance of Document.
9 10 11 12 13 |
# File 'lib/render_editorjs/document.rb', line 9 def initialize(content, renderer = RenderEditorjs::DefaultRenderer.new) @renderer = renderer @content = content.is_a?(Hash) ? content : parse_json(content) @errors = [] end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
7 8 9 |
# File 'lib/render_editorjs/document.rb', line 7 def content @content end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/render_editorjs/document.rb', line 7 def errors @errors end |
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
7 8 9 |
# File 'lib/render_editorjs/document.rb', line 7 def renderer @renderer end |
Instance Method Details
#render ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/render_editorjs/document.rb', line 23 def render return "" unless valid_renderer? safe_join( content["blocks"].map do |block| block_renderer = block_renderers(block["type"]) next unless block_renderer block_renderer.render(block["data"]) end.compact ) end |
#valid? ⇒ Boolean
15 16 17 18 19 20 21 |
# File 'lib/render_editorjs/document.rb', line 15 def valid? return false unless valid_renderer? validate_blocks @errors.empty? end |