Sha256: d5aadb3bca7f87de51bdfdeda2541be84b63b546b31402a1ce0aa389faa828ab

Contents?: true

Size: 601 Bytes

Versions: 3

Compression:

Stored size: 601 Bytes

Contents

# frozen_string_literal: true
require 'erb'

module Arbre
  module HTML

    class TextNode < Element
      builder_method :text_node

      # Builds a text node from a string
      def self.from_string(string)
        node = new
        node.build(string)
        node
      end

      def add_child(*args)
        raise "TextNodes do not have children"
      end

      def build(string)
        @content = string
      end

      def class_list
        []
      end

      def tag_name
        nil
      end

      def to_s
        ERB::Util.html_escape(@content.to_s)
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
arbre-2.0.2 lib/arbre/html/text_node.rb
arbre-2.0.1 lib/arbre/html/text_node.rb
arbre-2.0.0 lib/arbre/html/text_node.rb