Class: BlockKind

Inherits:
Forest::ApplicationRecord show all
Defined in:
app/models/block_kind.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Forest::ApplicationRecord

cache_key, cache_key_name, csv_columns, #expire_cache_key, expire_cache_key, statusable?, #statusable?, to_csv_template, #to_friendly_param, #to_select2_selection, versionable, #versionable

Class Method Details

.block_kind_paramsObject

TODO: - set up a BlockKind has_many blocks association?

- when destroying a BlockKind, also destroy all associated blocks?


9
10
11
12
13
# File 'app/models/block_kind.rb', line 9

def self.block_kind_params
  self.all.collect do |block_kind|
    block_kind.block.permitted_params + [:id, :_destroy]
  end
end

.resource_descriptionObject



15
16
17
# File 'app/models/block_kind.rb', line 15

def self.resource_description
  "A block kind represents the different types of blocks that may be used to add content to a page."
end

Instance Method Details

#blockObject



19
20
21
# File 'app/models/block_kind.rb', line 19

def block
  @block ||= self.name.constantize
end

#display_iconObject



31
32
33
# File 'app/models/block_kind.rb', line 31

def display_icon
  block.display_icon
end

#display_nameObject



23
24
25
# File 'app/models/block_kind.rb', line 23

def display_name
  block.display_name
end

#to_labelObject



27
28
29
# File 'app/models/block_kind.rb', line 27

def to_label
  display_name
end

#to_select2_responseObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/block_kind.rb', line 35

def to_select2_response
  r = ''
  r << '<div>'
  r << "<span class='block-kind__select2-response__icon #{display_icon}'></span> "
  r << '<strong>'
  r << display_name
  r << '</strong>'
  r << '</div>'

  if description.present?
    r << '<div class="text-muted">'
    r << '<smaller>'
    r << description
    r << '</smaller>'
    r << '</div>'
  end

  r
end