Sha256: 8214f16ba657fd838000541c9593fc69c4e63c5ebbef1b1165eafd9b2a5e5135

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

module Hotcell
  class Node
    attr_accessor :name, :children, :options
    attr_reader :position, :source

    def self.build *args
      new(*args).optimize
    end

    def initialize name, *args
      @name = name
      @options = args.extract_options!
      @source = @options.delete(:source)
      @position = @options.delete(:position)
      @children = args
    end

    def position_info
      source.info(position).values_at(:line, :column)
    end

    def optimize
      self
    end

    def [] key
      children[key]
    end

    def render context
      process context, *render_children(context)
    end

    def process context, *values
      raise NotImplementedError
    end

    def render_nodes context, *values
      values.flatten.map do |node|
        node.is_a?(Hotcell::Node) ? node.render(context) : node
      end
    end

    def render_children context
      render_nodes context, children
    end

    def == other
      other.is_a?(self.class) &&
      name == other.name &&
      options == other.options &&
      children == other.children
    end
  end
end

require 'hotcell/node/expression'
require 'hotcell/node/assigner'
require 'hotcell/node/summoner'
require 'hotcell/node/arrayer'
require 'hotcell/node/hasher'
require 'hotcell/node/sequencer'
require 'hotcell/node/joiner'
require 'hotcell/node/tag'
require 'hotcell/node/command'
require 'hotcell/node/block'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hotcell-0.3.0 lib/hotcell/node.rb
hotcell-0.2.0 lib/hotcell/node.rb