container_block.rb
1.13 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class ContainerBlockPlugin::ContainerBlock < Block
after_create :create_box
after_destroy :destroy_children
after_destroy :destroy_box
settings_items :container_box_id, :type => Integer, :default => nil
settings_items :children_settings, :type => Hash, :default => {}
def self.description
_('Container')
end
def help
_('This block acts as a container for another blocks')
end
def layout_template
nil
end
def destroy_children
blocks.destroy_all
end
def create_box
box = Box.create!(:owner => owner)
settings[:container_box_id] = box.id
save!
end
def destroy_box
container_box.destroy
end
def container_box
owner.boxes.find(container_box_id)
end
def block_classes=(classes)
classes.each { |c| block = c.constantize.create!(:box => container_box) } if classes
end
def blocks
container_box.blocks
end
def child_width(child_id)
children_settings[child_id][:width] if children_settings[child_id]
end
def content(args={})
block = self
lambda do
render :file => 'blocks/container.rhtml', :locals => {:block => block}
end
end
end