Sha256: 7f828d5ef646dd3fe2114c742083d93815ef917706597c97134731a5428a6edc

Contents?: true

Size: 1.76 KB

Versions: 21

Compression:

Stored size: 1.76 KB

Contents

# @Opulent
module Opulent
  # @Compiler
  class Compiler
    # Generate the code for a standard node element, with closing tags or
    # self enclosing elements
    #
    # @param node [Array] Node code generation data
    # @param indent [Fixnum] Size of the indentation to be added
    #
    def node(node, indent)
      indentation = ' ' * indent

      # Add the tag opening, with leading whitespace to the code buffer
      buffer_freeze ' ' if node[@options][:leading_whitespace]
      buffer_freeze "<#{node[@value]}"

      # Evaluate node extension in the current context
      if node[@options][:extension]
        extension_name = buffer_set_variable :extension,
                                             node[@options][:extension][@value]

        extension = {
          name: extension_name,
          escaped: node[@options][:extension][@options][:escaped]
        }
      end

      # Evaluate and generate node attributes, then process each one to
      # by generating the required attribute code
      # attributes = {}
      buffer_attributes node[@options][:attributes],
                        extension


      # Check if the current node is self enclosing. Self enclosing nodes
      # do not have any child elements
      if node[@options][:self_enclosing]
        # If the tag is self enclosing, it cannot have any child elements.
        buffer_freeze '>'
      else
        # Set tag ending code
        buffer_freeze '>'

        # Process each child element recursively, increasing indentation
        node[@children].each do |child|
          root child, indent + @settings[:indent]
        end

        # Set tag closing code
        buffer_freeze "</#{node[@value]}>"
        buffer_freeze ' ' if node[@options][:trailing_whitespace]
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
opulent-1.7.11 lib/opulent/compiler/node.rb
opulent-1.7.10 lib/opulent/compiler/node.rb
opulent-1.7.9 lib/opulent/compiler/node.rb
opulent-1.7.8 lib/opulent/compiler/node.rb
opulent-1.7.7 lib/opulent/compiler/node.rb
opulent-1.7.6 lib/opulent/compiler/node.rb
opulent-1.7.5 lib/opulent/compiler/node.rb
opulent-1.7.4 lib/opulent/compiler/node.rb
opulent-1.7.3 lib/opulent/compiler/node.rb
opulent-1.7.2 lib/opulent/compiler/node.rb
opulent-1.7.1 lib/opulent/compiler/node.rb
opulent-1.7.0 lib/opulent/compiler/node.rb
opulent-1.6.9 lib/opulent/compiler/node.rb
opulent-1.6.8 lib/opulent/compiler/node.rb
opulent-1.6.7 lib/opulent/compiler/node.rb
opulent-1.6.6 lib/opulent/compiler/node.rb
opulent-1.6.5 lib/opulent/compiler/node.rb
opulent-1.6.3 lib/opulent/compiler/node.rb
opulent-1.6.2 lib/opulent/compiler/node.rb
opulent-1.6.1 lib/opulent/compiler/node.rb