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

#collect_fulltext, included, #renders_own_childs?, #to_brick_item_id, #to_brick_list_id, #user_can_add_childs?, #user_can_delete?, #user_can_save?

Instance Method Details

#backend_label(options = {}) ⇒ Object



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

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

#brick_list_typeObject



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

def brick_list_type
  'Kuhsaft::Brick'
end

#parentsObject



43
44
45
46
47
48
49
50
51
52
# File 'app/models/kuhsaft/brick.rb', line 43

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_localeObject



54
55
56
# File 'app/models/kuhsaft/brick.rb', line 54

def set_locale
  self.locale = self.locale.presence || I18n.locale
end

#set_positionObject



58
59
60
# File 'app/models/kuhsaft/brick.rb', line 58

def set_position
  self.position = self.position.presence || 1
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.



37
38
39
40
41
# File 'app/models/kuhsaft/brick.rb', line 37

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

#to_edit_partial_pathObject



26
27
28
29
30
# File 'app/models/kuhsaft/brick.rb', line 26

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

#to_style_classObject

Returns a css classname suitable for use in the frontend



67
68
69
# File 'app/models/kuhsaft/brick.rb', line 67

def to_style_class
  self.class.to_s.underscore.dasherize.gsub('/', '-')
end

#to_style_idObject

Returns a unique DOM id suitable for use in the frontend



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

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