Sha256: a206f21f6c593ea0843adc59f78661bef69f35c6ea3ad96003392bcce2248c2b
Contents?: true
Size: 1.31 KB
Versions: 1
Compression:
Stored size: 1.31 KB
Contents
module ActsAsLayoutable class LayoutBuilder < ActsAsLayoutable::Builder # the path to the template/view folder, so "app/views/posts" is "posts" def template(path = nil) self.item.path = path.to_s if path end alias path template # the REST actions your layout will respond to def actions(*args) end def description(text = nil) self.item.description = text.to_s if text end def areas(*args, &block) ActsAsLayoutable::AreaBuilder.define!(*args, &block).each do |area| self.item.areas << area end end def method_missing(meth, *args, &block) self.item = ActsAsLayoutable::Layout.find_or_create_by_name(meth.to_s) self.instance_eval(&block) if block_given? self.item.save self.collection << item self.item end end class Layout < ActiveRecord::Base acts_as_joinable has_many :areas, :class_name => "ActsAsLayoutable::Area" has_many :widgets, :class_name => "ActsAsLayoutable::Widget", :through => :areas before_save :assure_key validates_presence_of :name def assure_key self.key ||= self.name.underscore.downcase.gsub(/\s+/, "_") end def template raise "Layout doesn't have a template" unless self.path self.path end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
acts-as-layoutable-0.0.1.7 | lib/acts-as-layoutable/layout.rb |