Sha256: b83145bb32c9c02866ee414555793c69fe1c952c8f8348ac30b6a151ec765aa4

Contents?: true

Size: 1.37 KB

Versions: 1

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/calculator'
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

1 entries across 1 versions & 1 rubygems

Version Path
hotcell-0.1.0 lib/hotcell/node.rb