Sha256: ba14c7e0b0ca831a9f143b956456f2ce3282dde6d50efd34d2bad8e24a404f1e

Contents?: true

Size: 736 Bytes

Versions: 2

Compression:

Stored size: 736 Bytes

Contents

module DraftjsHtml
  NokogiriNode = Struct.new(:node) do
    def to_nokogiri(_document)
      node
    end
  end

  StringNode = Struct.new(:raw) do
    def to_nokogiri(document)
      raw
      Nokogiri::XML::Text.new(raw, document)
    end
  end

  Node = Struct.new(:element_name, :attributes, :content) do
    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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
draftjs_html-0.5.1 lib/draftjs_html/node.rb
draftjs_html-0.5.0 lib/draftjs_html/node.rb