Sha256: e05f3ef1940ea7724b805e09b140b55ce2eb17ef7988da7f920fb839d6ff1a9e

Contents?: true

Size: 1.39 KB

Versions: 31

Compression:

Stored size: 1.39 KB

Contents

# @Opulent
module Opulent
  # @Nodes
  module Nodes
    # @Text
    #
    # The text class will output raw or escaped HTML text
    #
    class Text
      # Allow direct access to literal value and type
      attr_accessor :value, :escaped, :parent, :indent, :name

      # Initialize literal instance variables
      #
      # @param value stores the literal's explicit value
      #
      def initialize(value = nil, escaped = true, parent = nil, indent = 0)
        @value = value
        @escaped = escaped
        @parent = parent
        @indent = indent
        @name = :text
      end

      # Value evaluation method which returns the processed value of the
      # literal
      #
      def evaluate(context)
        value = context.evaluate "\"#{@value}\""

        evaluated_text = self.dup
        evaluated_text.value = @escaped ? Runtime.escape(value) : value
        return evaluated_text
      end
    end

    # @Print
    #
    # The print class will evaluate the ruby code and return a new text
    # node containing the escaped or unescaped eval sequence
    #
    class Print < Text
      # Value evaluation method which returns the processed value of the literal
      #
      def evaluate(context)
        value = context.evaluate @value

        evaluated_text = self.dup
        evaluated_text.value = @escaped ? Runtime.escape(value) : value
        return evaluated_text
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
opulent-1.1.9 .libold/opulent/nodes/text.rb
opulent-1.1.7 .libold/opulent/nodes/text.rb
opulent-1.1.6 .libold/opulent/nodes/text.rb
opulent-1.1.5 .libold/opulent/nodes/text.rb
opulent-1.1.0 .libold/opulent/nodes/text.rb
opulent-1.0.9 .libold/opulent/nodes/text.rb
opulent-1.0.8 .libold/opulent/nodes/text.rb
opulent-1.0.7 .libold/opulent/nodes/text.rb
opulent-1.0.4 .libold/opulent/nodes/text.rb
opulent-1.0.3 .libold/opulent/nodes/text.rb
opulent-1.0.2 .libold/opulent/nodes/text.rb