Class: Kuhsaft::Brick

Inherits:
ActiveRecord::Base
  • Object
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_stylesObject

return a list of css classnames that can be applied to the brick

[View source]

112
113
114
# File 'app/models/kuhsaft/brick.rb', line 112

def available_display_styles
  []
end

#backend_label(options = {}) ⇒ Object

[View source]

122
123
124
125
126
127
128
129
# File 'app/models/kuhsaft/brick.rb', line 122

def backend_label(options = {})
  label = self.class.model_name.human
  if options[:parenthesis] == true
    "(#{label})"
  else
    label
  end
end

#brick_list_typeObject

[View source]

97
98
99
# File 'app/models/kuhsaft/brick.rb', line 97

def brick_list_type
  'Kuhsaft::Brick'
end

#cache_keyObject

[View source]

135
136
137
# File 'app/models/kuhsaft/brick.rb', line 135

def cache_key
  super +  partial_digest(to_partial_path)
end

#has_siblings?Boolean

Returns:

  • (Boolean)
[View source]

61
62
63
# File 'app/models/kuhsaft/brick.rb', line 61

def has_siblings?
  brick_list.present? && brick_list.bricks.any?
end

#parentsObject

[View source]

76
77
78
79
80
81
82
83
84
85
# File 'app/models/kuhsaft/brick.rb', line 76

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

[View source]

131
132
133
# File 'app/models/kuhsaft/brick.rb', line 131

def partial_digest(name)
  ActionView::Digestor.digest(name, 'haml',  ApplicationController.new.lookup_context, partial: true)
end

#set_positionObject

[View source]

87
88
89
90
91
92
93
94
95
# File 'app/models/kuhsaft/brick.rb', line 87

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_pathObject

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.

[View source]

70
71
72
73
74
# File 'app/models/kuhsaft/brick.rb', line 70

def to_edit_childs_partial_path
  path = to_partial_path.split '/'
  path << 'childs'
  path.join '/'
end

#to_edit_partial_pathObject

[View source]

55
56
57
58
59
# File 'app/models/kuhsaft/brick.rb', line 55

def to_edit_partial_path
  path = to_partial_path.split '/'
  path << 'edit'
  path.join '/'
end

#to_style_classObject

Returns a css classname suitable for use in the frontend

[View source]

102
103
104
# File 'app/models/kuhsaft/brick.rb', line 102

def to_style_class
  ([self.class.to_s.underscore.dasherize.gsub('/', '-')] + display_styles).join(' ')
end

#to_style_idObject

Returns a unique DOM id suitable for use in the frontend

[View source]

107
108
109
# File 'app/models/kuhsaft/brick.rb', line 107

def to_style_id
  "#{self.class.to_s.underscore.dasherize.gsub('/', '-')}-#{id}"
end

#translated_available_display_stylesObject

[View source]

116
117
118
119
120
# File 'app/models/kuhsaft/brick.rb', line 116

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_fulltextObject

TODO: yes. temporary workaround. see above

[View source]

47
48
49
50
51
52
53
# File 'app/models/kuhsaft/brick.rb', line 47

def update_fulltext
  if brick_list.is_a? Page
    brick_list.update_fulltext
  else
    brick_list.brick_list.update_fulltext
  end
end