Class: Qbrick::Brick

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
BrickList
Defined in:
app/models/qbrick/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



113
114
115
# File 'app/models/qbrick/brick.rb', line 113

def available_display_styles
  []
end

#backend_label(options = {}) ⇒ Object



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

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

#brick_list_typeObject



98
99
100
# File 'app/models/qbrick/brick.rb', line 98

def brick_list_type
  'Qbrick::Brick'
end

#cache_keyObject



136
137
138
# File 'app/models/qbrick/brick.rb', line 136

def cache_key
  super + partial_digest(to_partial_path)
end

#has_siblings?Boolean

Returns:

  • (Boolean)


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

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

#parentsObject



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

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



132
133
134
# File 'app/models/qbrick/brick.rb', line 132

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

#set_positionObject



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

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.



71
72
73
74
75
# File 'app/models/qbrick/brick.rb', line 71

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

#to_edit_partial_pathObject



56
57
58
59
60
# File 'app/models/qbrick/brick.rb', line 56

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



103
104
105
# File 'app/models/qbrick/brick.rb', line 103

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



108
109
110
# File 'app/models/qbrick/brick.rb', line 108

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

#translated_available_display_stylesObject



117
118
119
120
121
# File 'app/models/qbrick/brick.rb', line 117

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



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

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