class BuilderQuillContent

Constants

EMBED_KEYS
VERSION

Attributes

args[RW]

Your code goes here…

input[RW]

Your code goes here…

Public Class Methods

new(input, args = {}) click to toggle source
# File lib/builder_quill_content.rb, line 13
def initialize(input, args = {})
  @input = input
  @args  = args
  @line  = @content = ''
end

Public Instance Methods

break_line(insert) click to toggle source
# File lib/builder_quill_content.rb, line 45
def break_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
end
embed_node?(node) click to toggle source
# File lib/builder_quill_content.rb, line 60
def embed_node?(node)
  return false if node['insert'].is_a?(String)

  node['insert'].keys.find { |k| EMBED_KEYS.include?(k) }
end
end_of_line(attributes) click to toggle source
# File lib/builder_quill_content.rb, line 40
def end_of_line(attributes)
  @content += attributes.nil? ? "<p>#{@line}</p>" : ConvertInline.new({ 'insert' => @line, 'attributes' => attributes }, args).convert
  @line = ''
end
inline(node) click to toggle source
# File lib/builder_quill_content.rb, line 56
def inline(node)
  embed_node?(node) ? @content += ConvertInline.new(node, args).convert : @line += ConvertInline.new(node, args).convert
end
to_html() click to toggle source
# File lib/builder_quill_content.rb, line 19
def to_html
  content_json = JSON.parse(@input)

  while content_json.length.positive?
    node = content_json.shift

    if node['insert'] == "\n"
      end_of_line(node['attributes'])
    elsif node['insert'].include?("\n")
      break_line(node['insert'])
    else
      inline(node)
    end
  end

  @content += @line unless @line.strip.empty?
  @content.gsub('</ul><ul>', '')
rescue JSON::ParserError
  'No content'
end