Module: Kuhsaft::BrickList

Included in:
Brick, ColumnBrick, Page, SliderBrick
Defined in:
lib/kuhsaft/brick_list.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/kuhsaft/brick_list.rb', line 4

def self.included(base)
  def base.acts_as_brick_list
    self.has_many :bricks,
      :class_name => 'Kuhsaft::Brick',
      :dependent => :destroy,
      :as => :brick_list
  end
end

Instance Method Details

#allowed_brick_typesObject

Return a list of classnames which can be added as childs Return an empty array if you want no constraints



77
78
79
# File 'lib/kuhsaft/brick_list.rb', line 77

def allowed_brick_types
  []
end

#brick_typesObject

Returns all possible brick types which can be added as child to this brick list instance



84
85
86
# File 'lib/kuhsaft/brick_list.rb', line 84

def brick_types
  @brick_types ||= Kuhsaft::BrickTypeFilter.new(self)
end

#collect_fulltextObject

Return relevant fulltext information for this brick (e.g: it’s name, description etc ).  It will be stored in the related Page. Implement how you see fit.



62
63
64
65
66
67
68
69
70
71
# File 'lib/kuhsaft/brick_list.rb', line 62

def collect_fulltext
  if respond_to?(:bricks)
    bricks.localized.inject('') do |text, brick|
      text << brick.collect_fulltext
      text
    end
  else
    ''
  end
end

#renders_own_childs?Boolean

When true, the brick must implement the rendering of its childs by itself by using the _childs partial When false, the default BrickList rendering is used See _brick_item partial

Returns:

  • (Boolean)


53
54
55
# File 'lib/kuhsaft/brick_list.rb', line 53

def renders_own_childs?
  false
end

#to_brick_item_idObject



13
14
15
# File 'lib/kuhsaft/brick_list.rb', line 13

def to_brick_item_id
  "brick-item-#{id}-#{self.class.to_s.underscore.gsub('/', '_')}"
end

#to_brick_list_idObject



17
18
19
# File 'lib/kuhsaft/brick_list.rb', line 17

def to_brick_list_id
  "brick-list-#{id}-#{self.class.to_s.underscore.gsub('/', '_')}"
end

#uploader?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/kuhsaft/brick_list.rb', line 88

def uploader?
  self.class.ancestors.include? CarrierWave::Mount::Extension
end

#user_can_add_childs?Boolean

See TwoColumnBrick as an example, which can only have to ColumBricks and the User should not be able to add more

Returns:

  • (Boolean)


25
26
27
# File 'lib/kuhsaft/brick_list.rb', line 25

def user_can_add_childs?
  true
end

#user_can_delete?Boolean

return true if the user should be able to delete the brick through the UI. return false if not. See ColumnBrick, which should not be deleted inside the TwoColumnBrick

Returns:

  • (Boolean)


34
35
36
# File 'lib/kuhsaft/brick_list.rb', line 34

def user_can_delete?
  true
end

#user_can_save?Boolean

Return true if the user can hit the save button Return false if not See column brick, which has no data on its own except childs, therefore no button is needed

Returns:

  • (Boolean)


43
44
45
# File 'lib/kuhsaft/brick_list.rb', line 43

def user_can_save?
  true
end