Class: RenderEditorjs::Blocks::List
- Defined in:
- lib/render_editorjs/blocks/list.rb
Overview
Render for github.com/editor-js/nested-list
Constant Summary collapse
- SAFE_TAGS =
TODO: Consider extract it and the sanitize method with the other on Paragraph block to the DefaultRenderer
{ "b" => nil, "i" => nil, "u" => ["class"], "del" => ["class"], "a" => ["href"], "mark" => ["class"], "code" => ["class"] }.freeze
- SCHEMA =
YAML.safe_load(<<~YAML) type: object additionalProperties: false definitions: Items: type: array properties: content: type: string items: type: Items properties: style: type: string pattern: ^(un)?ordered$ items: type: Items YAML
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
38 39 40 |
# File 'lib/render_editorjs/blocks/list.rb', line 38 def @options end |
Instance Method Details
#render(data) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/render_editorjs/blocks/list.rb', line 40 def render(data) return unless valid?(data) tag = data["style"] == "unordered" ? :ul : :ol render_list(tag, data["items"]) end |
#render_list(tag, items) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/render_editorjs/blocks/list.rb', line 47 def render_list(tag, items) return "" unless items content_tag(tag) do children_tag_string = "" items.each do |v| item = sanitize(v["content"]) item << render_list(tag, v["items"]) if v["items"] children_tag_string += content_tag(:li, item.html_safe) end children_tag_string.html_safe end end |