Class: Releaf::Content::ContentTypeDialogBuilder

Inherits:
Object
  • Object
show all
Includes:
Builders::Dialog
Defined in:
app/builders/releaf/content/content_type_dialog_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Builders::Dialog

#cancel_button, #footer_primary_tools

Methods included from Builders::Tree

#body_classes, #build_tree, #empty_body, #root_level, #sort_tree, #sorted_tree, #tree, #tree_level, #tree_resource, #tree_resource_blocks, #tree_resource_children, #tree_resource_collapser, #tree_resource_name, #tree_resource_name_button

Constructor Details

#initialize(template) ⇒ ContentTypeDialogBuilder

Returns a new instance of ContentTypeDialogBuilder.



6
7
8
9
# File 'app/builders/releaf/content/content_type_dialog_builder.rb', line 6

def initialize(template)
  super
  self.content_types = template_variable("content_types")
end

Instance Attribute Details

#content_typesObject

Returns the value of attribute content_types.



4
5
6
# File 'app/builders/releaf/content/content_type_dialog_builder.rb', line 4

def content_types
  @content_types
end

Instance Method Details

#content_type_item(content_type) ⇒ Object



56
57
58
59
60
61
# File 'app/builders/releaf/content/content_type_dialog_builder.rb', line 56

def content_type_item(content_type)
  url = url_for(controller: controller.controller_path, action: "new", parent_id: params[:parent_id], content_type: content_type.name)
  tag(:li) do
    link_to(I18n.t(content_type.name.underscore, scope: 'admin.content_types'), url)
  end
end

#content_type_slice(slice) ⇒ Object



48
49
50
51
52
53
54
# File 'app/builders/releaf/content/content_type_dialog_builder.rb', line 48

def content_type_slice(slice)
  tag(:ul) do
    slice.collect do|content_type|
      content_type_item(content_type)
    end
  end
end

#content_types_listObject



40
41
42
43
44
45
46
# File 'app/builders/releaf/content/content_type_dialog_builder.rb', line 40

def content_types_list
  tag(:div, class: "content-types") do
    content_types_slices.collect do |slice|
      content_type_slice(slice)
    end
  end
end

#content_types_slicesObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/builders/releaf/content/content_type_dialog_builder.rb', line 11

def content_types_slices
  min_items_per_column = 4
  items_per_column = (content_types.length / 2.0).ceil

  if items_per_column < min_items_per_column
    items_per_column = min_items_per_column
  end

  slices = []
  slices.push content_types[0...items_per_column]
  if items_per_column < content_types.length
    slices.push content_types[items_per_column..-1]
  end

  slices
end

#section_attributesObject



28
29
30
31
32
# File 'app/builders/releaf/content/content_type_dialog_builder.rb', line 28

def section_attributes
  attributes = super
  attributes['data-columns'] = content_types_slices.length
  attributes
end

#section_bodyObject



34
35
36
37
38
# File 'app/builders/releaf/content/content_type_dialog_builder.rb', line 34

def section_body
  tag(:div, class: "body") do
    [section_body_description, content_types_list]
  end
end

#section_body_descriptionObject



64
65
66
67
68
# File 'app/builders/releaf/content/content_type_dialog_builder.rb', line 64

def section_body_description
  tag(:div, class: "description") do
    t("Select content type of new node")
  end
end

#section_header_textObject



70
71
72
# File 'app/builders/releaf/content/content_type_dialog_builder.rb', line 70

def section_header_text
  t("Create new resource")
end