Module: BuilderQuillContent
- Defined in:
- lib/builder_quill_content.rb,
lib/builder_quill_content/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- EMBED_KEYS =
Your code goes here…
%w[wk-image wk-youtube wk-tweet wk-instagram wk-divider waku-post wk-maps].freeze
- VERSION =
"0.1.2"
Instance Method Summary collapse
- #break_line(content, line, insert) ⇒ Object
- #embed_node?(node) ⇒ Boolean
- #end_of_line(content, line, attributes) ⇒ Object
- #inline(content, line, node) ⇒ Object
- #to_html(input) ⇒ Object
Instance Method Details
#break_line(content, line, insert) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/builder_quill_content.rb', line 35 def break_line(content, line, insert) insert.split(/(?<=\n)/).each do |text| if text.end_with?("\n") content += "<p>#{line}#{text.delete("\n")}</p>" line = '' else line += text end end [content, line] end |
#embed_node?(node) ⇒ Boolean
53 54 55 56 57 58 |
# File 'lib/builder_quill_content.rb', line 53 def (node) return false if node['insert'].is_a?(String) return false unless node['insert'].keys.find { |k| EMBED_KEYS.include?(k) } true end |
#end_of_line(content, line, attributes) ⇒ Object
30 31 32 33 |
# File 'lib/builder_quill_content.rb', line 30 def end_of_line(content, line, attributes) content += attributes.nil? ? "<p>#{line}</p>" : ConvertInline.new('insert' => line, 'attributes' => attributes).convert [content, ''] end |
#inline(content, line, node) ⇒ Object
47 48 49 50 51 |
# File 'lib/builder_quill_content.rb', line 47 def inline(content, line, node) return [content + ConvertInline.new(node).convert, line] if (node) [content, line + ConvertInline.new(node).convert] end |
#to_html(input) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/builder_quill_content.rb', line 11 def to_html(input) content_json = JSON.parse(input) line = content = '' while content_json.length.positive? node = content_json.shift if node['insert'] == "\n" content, line = end_of_line(content, line, node['attributes']) elsif node['insert'].include?("\n") content, line = break_line(content, line, node['insert']) else content, line = inline(content, line, node) end end content.gsub('</ul><ul>', '') end |