Sha256: 08ac6a3e3a6cf16d12c020a23f7f210cf7bbd91d10c2a6020dded4d3c1a25eb5

Contents?: true

Size: 708 Bytes

Versions: 6

Compression:

Stored size: 708 Bytes

Contents

require 'erb'

module Arbre

  # A 'raw' text node - it just outputs the HTML escaped version of the string it's
  # built with.
  class TextNode < Element
    builder_method :text_node

    # Builds a raw element from a string.
    def self.from_string(string)
      new.tap { |node| node.build!(string) }
    end

    def children
      @children ||= ElementCollection.new.tap do |children|
        def children.<<(*) raise NotImplementedError end
        def children.add(*) raise NotImplementedError end
        def children.concat(*) raise NotImplementedError end
      end
    end

    attr_reader :text

    def build!(text)
      @text = text.to_s
    end

    def to_s
      text
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
arbre2-2.2.4 lib/arbre/text_node.rb
arbre2-2.2.3 lib/arbre/text_node.rb
arbre2-2.2.2 lib/arbre/text_node.rb
arbre2-2.2.1 lib/arbre/text_node.rb
arbre2-2.2.0 lib/arbre/text_node.rb
arbre2-2.1.0 lib/arbre/text_node.rb