module ActsAsLayoutable class Builder class << self def define!(*args, &block) new(*args, &block).collection.uniq end end attr_accessor :item, :collection def collection @collection ||= [] end def klazz self.class.to_s.gsub("Builder", "").constantize end def initialize(*args, &block) args.each do |name| self.collection << klazz.create!(:name => name.to_s) end instance_eval(&block) if block_given? end def templates(*args, &block) TemplateBuilder.define!(*args, &block) end alias paths templates def layouts(*args, &block) LayoutBuilder.define!(*args, &block) end alias grids layouts def areas(*args, &block) AreaBuilder.define!(*args, &block) end def widgets(*args, &block) WidgetBuilder.define!(*args, &block) end alias cells widgets def method_missing(meth, *args, &block) if context result = "ActsAsLayoutable::#{context.singularize.camelize}".constantize.new result.instance_eval(&block) if block_given? return result else super(meth, *args, &block) end end private def context @context end end end