Class: DraftjsHtml::Node

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes

Returns:

  • (Object)

    the current value of attributes



37
38
39
# File 'lib/draftjs_html/node.rb', line 37

def attributes
  @attributes
end

#contentObject

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



37
38
39
# File 'lib/draftjs_html/node.rb', line 37

def content
  @content
end

#element_nameObject

Returns the value of attribute element_name

Returns:

  • (Object)

    the current value of element_name



37
38
39
# File 'lib/draftjs_html/node.rb', line 37

def element_name
  @element_name
end

Class Method Details

.of(thing) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/draftjs_html/node.rb', line 38

def self.of(thing)
  case thing
  when Nokogiri::XML::Node then NokogiriNode.new(thing)
  when self.class then thing
  when String then StringNode.new(thing)
  else thing
  end
end

Instance Method Details

#to_nokogiri(document) ⇒ Object



47
48
49
50
51
52
# File 'lib/draftjs_html/node.rb', line 47

def to_nokogiri(document)
  Nokogiri::XML::Node.new(element_name, document).tap do |node|
    node << content.to_nokogiri(document) if content
    (attributes || {}).each { |k, v| node[k] = v }
  end
end

#to_sObject



58
59
60
# File 'lib/draftjs_html/node.rb', line 58

def to_s
  content.to_s
end

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



54
55
56
# File 'lib/draftjs_html/node.rb', line 54

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