Class: DraftjsHtml::StringNode

Inherits:
Struct
  • Object
show all
Defined in:
lib/draftjs_html/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rawObject

Returns the value of attribute raw

Returns:

  • (Object)

    the current value of raw



16
17
18
# File 'lib/draftjs_html/node.rb', line 16

def raw
  @raw
end

Instance Method Details

#to_nokogiri(document) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/draftjs_html/node.rb', line 17

def to_nokogiri(document)
  lines = raw.lines
  text_nodes = lines.flat_map.with_index do |text, i|
    nodes = [Nokogiri::XML::Text.new(text.chomp, document)]
    nodes << Nokogiri::XML::Node.new('br', document) if text.end_with?("\n")
    nodes
  end

  Nokogiri::XML::NodeSet.new(document, text_nodes)
end

#to_sObject



32
33
34
# File 'lib/draftjs_html/node.rb', line 32

def to_s
  raw.to_s
end

#wrap(tagname, attrs = {}) ⇒ Object



28
29
30
# File 'lib/draftjs_html/node.rb', line 28

def wrap(tagname, attrs = {})
  Node.new(tagname, attrs, self)
end