Class: Kuhsaft::Brick
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Kuhsaft::Brick
show all
- Includes:
- BrickList
- Defined in:
- app/models/kuhsaft/brick.rb
Instance Method Summary
collapse
Methods included from BrickList
#allowed_brick_types, #brick_types, #collect_fulltext, included, #renders_own_childs?, #to_brick_item_id, #to_brick_list_id, #uploader?, #user_can_add_childs?, #user_can_delete?, #user_can_save?
Instance Method Details
#available_display_styles ⇒ Object
return a list of css classnames that can be applied to the brick
110
111
112
|
# File 'app/models/kuhsaft/brick.rb', line 110
def available_display_styles
[]
end
|
#backend_label(options = {}) ⇒ Object
120
121
122
123
124
125
126
127
|
# File 'app/models/kuhsaft/brick.rb', line 120
def backend_label(options = {})
label = self.class.model_name.human
if options[:parenthesis] == true
"(#{label})"
else
label
end
end
|
#brick_list_type ⇒ Object
95
96
97
|
# File 'app/models/kuhsaft/brick.rb', line 95
def brick_list_type
'Kuhsaft::Brick'
end
|
#cache_key ⇒ Object
133
134
135
|
# File 'app/models/kuhsaft/brick.rb', line 133
def cache_key
super + partial_digest(to_partial_path)
end
|
#has_siblings? ⇒ Boolean
59
60
61
|
# File 'app/models/kuhsaft/brick.rb', line 59
def has_siblings?
brick_list.present? && brick_list.bricks.any?
end
|
#parents ⇒ Object
74
75
76
77
78
79
80
81
82
83
|
# File 'app/models/kuhsaft/brick.rb', line 74
def parents
p = []
parent = brick_list.presence
while parent
p << parent
parent = parent.respond_to?(:brick_list) ? parent.brick_list : nil
end
p.reverse
end
|
#partial_digest(name) ⇒ Object
129
130
131
|
# File 'app/models/kuhsaft/brick.rb', line 129
def partial_digest(name)
ActionView::Digestor.digest(name, 'haml', ApplicationController.new.lookup_context, partial: true)
end
|
#set_position ⇒ Object
85
86
87
88
89
90
91
92
93
|
# File 'app/models/kuhsaft/brick.rb', line 85
def set_position
self.position = if self.position.present?
self.position
elsif self.respond_to?(:brick_list) && brick_list.respond_to?(:bricks)
brick_list.bricks.maximum(:position).to_i + 1
else
1
end
end
|
#to_edit_childs_partial_path ⇒ Object
The child partial can contain your own implementation of how the brick renders it’s child in the edit form. Returns the path to this partial.
68
69
70
71
72
|
# File 'app/models/kuhsaft/brick.rb', line 68
def to_edit_childs_partial_path
path = to_partial_path.split '/'
path << 'childs'
path.join '/'
end
|
#to_edit_partial_path ⇒ Object
53
54
55
56
57
|
# File 'app/models/kuhsaft/brick.rb', line 53
def to_edit_partial_path
path = to_partial_path.split '/'
path << 'edit'
path.join '/'
end
|
#to_style_class ⇒ Object
Returns a css classname suitable for use in the frontend
100
101
102
|
# File 'app/models/kuhsaft/brick.rb', line 100
def to_style_class
([self.class.to_s.underscore.dasherize.gsub('/', '-')] + display_styles).join(' ')
end
|
#to_style_id ⇒ Object
Returns a unique DOM id suitable for use in the frontend
105
106
107
|
# File 'app/models/kuhsaft/brick.rb', line 105
def to_style_id
"#{self.class.to_s.underscore.dasherize.gsub('/', '-')}-#{id}"
end
|
#translated_available_display_styles ⇒ Object
114
115
116
117
118
|
# File 'app/models/kuhsaft/brick.rb', line 114
def translated_available_display_styles
available_display_styles.map do |style|
[I18n.t("#{self.class.to_s.demodulize.underscore}.display_styles.#{style}"), style]
end
end
|
#update_fulltext ⇒ Object
TODO: yes. temporary workaround. see above
45
46
47
48
49
50
51
|
# File 'app/models/kuhsaft/brick.rb', line 45
def update_fulltext
if brick_list.is_a? Page
brick_list.update_fulltext
else
brick_list.brick_list.update_fulltext
end
end
|