Class: Kuhsaft::Brick
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Kuhsaft::Brick
- Includes:
- BrickList
- Defined in:
- app/models/kuhsaft/brick.rb
Direct Known Subclasses
AnchorBrick, AssetBrick, ColumnBrick, ImageBrick, LinkBrick, PlaceholderBrick, SliderBrick, TextBrick, VideoBrick
Instance Method Summary collapse
-
#available_display_styles ⇒ Object
return a list of css classnames that can be applied to the brick.
- #backend_label(options = {}) ⇒ Object
- #brick_list_type ⇒ Object
- #has_siblings? ⇒ Boolean
- #parents ⇒ Object
- #set_position ⇒ Object
-
#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.
- #to_edit_partial_path ⇒ Object
-
#to_style_class ⇒ Object
Returns a css classname suitable for use in the frontend.
-
#to_style_id ⇒ Object
Returns a unique DOM id suitable for use in the frontend.
-
#update_fulltext ⇒ Object
TODO: yes.
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
107 108 109 |
# File 'app/models/kuhsaft/brick.rb', line 107 def available_display_styles [] end |
#backend_label(options = {}) ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'app/models/kuhsaft/brick.rb', line 111 def backend_label( = {}) label = self.class.model_name.human if [:parenthesis] == true "(#{label})" else label end end |
#brick_list_type ⇒ Object
92 93 94 |
# File 'app/models/kuhsaft/brick.rb', line 92 def brick_list_type 'Kuhsaft::Brick' end |
#has_siblings? ⇒ Boolean
54 55 56 57 58 |
# File 'app/models/kuhsaft/brick.rb', line 54 def has_siblings? if brick_list brick_list.bricks.any? end end |
#parents ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/kuhsaft/brick.rb', line 71 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 |
#set_position ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'app/models/kuhsaft/brick.rb', line 82 def set_position self.position = if self.position.present? self.position elsif self.respond_to?(:brick_list) && self.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.
65 66 67 68 69 |
# File 'app/models/kuhsaft/brick.rb', line 65 def to_edit_childs_partial_path path = self.to_partial_path.split '/' path << 'childs' path.join '/' end |
#to_edit_partial_path ⇒ Object
48 49 50 51 52 |
# File 'app/models/kuhsaft/brick.rb', line 48 def to_edit_partial_path path = self.to_partial_path.split '/' path << 'edit' path.join '/' end |
#to_style_class ⇒ Object
Returns a css classname suitable for use in the frontend
97 98 99 |
# File 'app/models/kuhsaft/brick.rb', line 97 def to_style_class ([self.class.to_s.underscore.dasherize.gsub('/', '-')] + self.display_styles).join(' ') end |
#to_style_id ⇒ Object
Returns a unique DOM id suitable for use in the frontend
102 103 104 |
# File 'app/models/kuhsaft/brick.rb', line 102 def to_style_id "#{self.class.to_s.underscore.dasherize.gsub('/', '-')}-#{id}" end |
#update_fulltext ⇒ Object
TODO: yes. temporary workaround. see above
40 41 42 43 44 45 46 |
# File 'app/models/kuhsaft/brick.rb', line 40 def update_fulltext if brick_list.is_a? Page brick_list.update_fulltext else brick_list.brick_list.update_fulltext end end |