lib/draftjs_html/node.rb in draftjs_html-0.6.0 vs lib/draftjs_html/node.rb in draftjs_html-0.7.0

- old
+ new

@@ -1,10 +1,18 @@ module DraftjsHtml NokogiriNode = Struct.new(:node) do def to_nokogiri(_document) node end + + def wrap(tagname, attrs = {}) + Node.new(tagname, attrs, self) + end + + def to_s + node.to_s + end end StringNode = Struct.new(:raw) do def to_nokogiri(document) lines = raw.lines @@ -14,10 +22,18 @@ nodes end Nokogiri::XML::NodeSet.new(document, text_nodes) end + + def wrap(tagname, attrs = {}) + Node.new(tagname, attrs, self) + end + + def to_s + raw.to_s + end end Node = Struct.new(:element_name, :attributes, :content) do def self.of(thing) case thing @@ -28,11 +44,19 @@ end end def to_nokogiri(document) Nokogiri::XML::Node.new(element_name, document).tap do |node| - node.content = content + node << content.to_nokogiri(document) if content (attributes || {}).each { |k, v| node[k] = v } end + end + + def wrap(tagname, attrs = {}) + Node.new(tagname, attrs, self) + end + + def to_s + content.to_s end end end