block.rb
1 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
class Block < ActiveRecord::Base
# to be able to generate HTML
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
acts_as_list :scope => :box
belongs_to :box
serialize :settings, Hash
def settings
self[:settings] ||= Hash.new
end
def self.settings_item(name)
class_eval <<-CODE
def #{name}
settings[:#{name}]
end
def #{name}=(value)
settings[:#{name}] = value
end
CODE
end
def self.description
_('A dummy block.')
end
# TODO: must have some way to have access to request information (mainly the
# current user)
def content
"This is block number %d" % self.id
end
# must return a Hash with URL options poiting to the action that edits
# properties of the block
def editor
nil
end
# must always return false, except on MainBlock clas.
def main?
false
end
def owner
box ? box.owner : nil
end
def css_class_name
self.class.name.underscore.gsub('_', '-')
end
end