require 'wml_action/log' require 'set' module WMLAction class Tag include Log attr_accessor :name,:subs,:attrs,:macros,:filter, :actions Attribute = Struct.new(:name, :value) do def to_s(indent=0, dummy=0) "#{name}=#{value}" end end Macro = Struct.new(:value) do def to_s(indent=0, dummy=0) value.to_s end end Action = Struct.new(:object, :action) do def to_s(indent=0, dummy=0) "#{action} #{object.to_s(indent,0)}" end end Filter = Struct.new(:value) do def to_s(indent=0, dummy=0) "/ #{ value }" end end def initialize(values={}) @name=values[:name]||"" @subs=values[:subs]||Array.new @attrs=values[:attrs]||Hash.new @macros=values[:macros]||Set.new @filter=values[:filter]||Array.new @actions=values[:actions]||Array.new load_content( values[:content] ) if values.key? :content end def <<(content) case content when Action then @actions << content when Attribute then @attrs.merge!( Hash[*content] ) when Macro then @macros.add( content.value ) when Filter then @filter << content.value when Tag then @subs << content else raise TypeError.new("Can not add #{content.class}: #{content} to a Tag") end return self end def load_content(contents) contents.each { |c| self<