init.rb
1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'design'
class ActionController::Base
# Declares that this controller uses design plugin to generate its layout.
# See the plugin README for options that can be passed to this method.
def self.design(config = {})
if (config.has_key?(:holder) && config.has_key?(:fixed)) || (!config.has_key?(:holder) && !config.has_key?(:fixed))
raise ArgumentError.new("You must supply either <tt>:holder</tt> or <tt>:fixed</tt> to design.")
end
@design_plugin_config = config
include Design
end
# declares this controller as a design editor, including in it all the
# functionalities to do that (besides those for using a design). Accepts the
# same options as design.
def self.design_editor(config = {})
self.design(config)
include Design::Editor
end
end
class ActiveRecord::Base
# declares an ActiveRecord class to be a design. The class is automatically
# associated with a +has_many+ associationto Design::Block.
#
# The underlying database table *must* have a column named +design_data+ of
# type +text+. +string+ should work too, but you may run into problems
# related to length limit, so unless you have a very good reason not to, use
# +text+ type.
def self.acts_as_design
has_many :boxes, :class_name => 'Design::Box', :as => :owner
def blocks
self.boxes.collect{|b| b.blocks}.flatten
end
end
end