Sha256: b9b281be33047c84041c87aad2287bcc7cf44b918ad784a3d28dda380eb85da2

Contents?: true

Size: 1.66 KB

Versions: 18

Compression:

Stored size: 1.66 KB

Contents

# @Opulent
module Opulent
  # @Compiler
  class Compiler
    # Generate the code for a standard text node
    #
    # @param node [Array] Node code generation data
    # @param indent [Fixnum] Size of the indentation to be added
    # @param context [Context] Processing environment data
    #
    def plain(node, indent, context)
      indentation = " " * indent

      inline = @inline_node.include? @node_stack.last

      # Evaluate text node if it's marked as such and print nodes in the
      # current context
      if node[@value] == :text
        if node[@options][:evaluate]
          value = context.evaluate "\"#{node[@options][:value]}\""
        else
          value = node[@options][:value]
        end
      else
        value = if node[@options][:value] == 'yield'
          context.evaluate_yield
        else
          context.evaluate(node[@options][:value])
        end
      end

      # Indent all the lines with the given indentation
      value = indent_lines value, indentation

      # If the last node was an inline node, we remove the trailing newline
      # character and we left strip the value
      #pp @node_stack
      if @node_stack.last == :text
        remove_trailing_newline
        value = " " + value.lstrip
      elsif inline
        remove_trailing_newline
        value.lstrip!
      end
      value.rstrip!

      # Escape the value unless explicitly set to false
      value = node[@options][:escaped] ? escape(value) : value

      # Create the text tag to be added
      text_tag = "#{value}"
      text_tag += "\n"

      # Set the current child node as last processed node
      @node_stack << :text

      @code += text_tag
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
opulent-1.4.0 lib/opulent/compiler/text.rb
opulent-1.3.3 lib/opulent/compiler/text.rb
opulent-1.3.2 lib/opulent/compiler/text.rb
opulent-1.3.1 lib/opulent/compiler/text.rb
opulent-1.3.0 lib/opulent/compiler/text.rb
opulent-1.2.1 lib/opulent/compiler/text.rb
opulent-1.2.0 lib/opulent/compiler/text.rb
opulent-1.1.9 lib/opulent/compiler/text.rb
opulent-1.1.7 lib/opulent/compiler/text.rb
opulent-1.1.6 lib/opulent/compiler/text.rb
opulent-1.1.5 lib/opulent/compiler/text.rb
opulent-1.1.0 lib/opulent/compiler/text.rb
opulent-1.0.9 lib/opulent/compiler/text.rb
opulent-1.0.8 lib/opulent/compiler/text.rb
opulent-1.0.7 lib/opulent/compiler/text.rb
opulent-1.0.4 lib/opulent/compiler/text.rb
opulent-1.0.3 lib/opulent/compiler/text.rb
opulent-1.0.2 lib/opulent/compiler/text.rb