"DTD/xhtml1-strict.dtd">
Class Amrita::AttrArray
In: lib/amrita/node_expand.rb
lib/amrita/node.rb
lib/amrita/compiler.rb
Parent: Object

Array of Attr s. It can hold body part for using as a model data for Node#expand. Amrita#a() method is a shortcut for Attr.new

Methods
<<    ==    []    []=    amrita_expand_node    amrita_generate_hint    clear    each    inspect    new    size    to_ruby   
Attributes
:array  [R] 

If you call a() { ... }, block yields to body

:body  [R] 

If you call a() { ... }, block yields to body

:shared  [RW] 

internal use only, never touch it!

true if this instance is shared by two or more elements

Included modules
Enumerable
Public Class methods
new(*attrs, &block) {|| ...}

Don't use AttrArray.new use a() instead

# File lib/amrita/node.rb, line 94
    def initialize(*attrs, &block)
      @array = []
      @shared = false
      attrs.each do |a|
        case a
        when Array, AttrArray
          a.each do |aa|
            self << aa
          end
        when Hash
          attrs[0].each do |k, v|
            self << Attr.new(k, v)
          end
        else
          self << a
        end
      end

      if block_given?
        @body = yield 
      else
        @body = Null
      end
    end
Public Instance methods
amrita_expand_node(n, context)
# File lib/amrita/node_expand.rb, line 258
    def amrita_expand_node(n, context)
      raise Amrita::ModelMisMatch(type, n.type)
    end
==(x)

AttrArray#== concerns the order of Attr

# File lib/amrita/node.rb, line 120
    def ==(x)
      return true if id == x.id
      return false unless x.kind_of?(AttrArray)
      each_with_index do |a, n|
        return false unless a == x[n]
      end
      true
    end
inspect()
# File lib/amrita/node.rb, line 129
    def inspect
      to_ruby
    end
<<(a)

add an Attr

# File lib/amrita/node.rb, line 134
    def <<(a)
      raise "must be Attr not #{a.class}" unless a.kind_of?(Attr)
      @array << a
    end
clear()
# File lib/amrita/node.rb, line 139
    def clear
      @array.clear
    end
[](index)
# File lib/amrita/node.rb, line 143
    def [](index)
      @array[index]
    end
[]=(index, val)
# File lib/amrita/node.rb, line 147
    def []=(index, val)
      @array[index] = val
      val
    end
each(&block)

iterate on each Attr

# File lib/amrita/node.rb, line 153
    def each(&block)
      @array.each(&block)
    end
size()
# File lib/amrita/node.rb, line 157
    def size
      @array.size
    end
to_ruby()
# File lib/amrita/node.rb, line 161
    def to_ruby
      ret = "a(" + @array.collect {|a| ":#{a.key}, #{a.value}"}.join(", ") + ")"
      case @body
      when nil, Null
      when Node
        ret += body.to_ruby
      else
        ret += body.inspect
      end
      ret
    end
amrita_generate_hint()
# File lib/amrita/compiler.rb, line 58
    def amrita_generate_hint
      if body
        Amrita::HtmlCompiler::AttrData[body.amrita_generate_hint]
      else
        Amrita::HtmlCompiler::AttrData.new
      end
    end