Module: Releaf::Content::Builders::Tree

Included in:
Dialog, Nodes::IndexBuilder
Defined in:
app/builders/releaf/content/builders/tree.rb

Instance Method Summary collapse

Instance Method Details

#body_classesObject



9
10
11
12
13
# File 'app/builders/releaf/content/builders/tree.rb', line 9

def body_classes
  classes = [:body]
  classes << :empty if collection.size < 1
  classes
end

#empty_bodyObject



26
27
28
29
30
# File 'app/builders/releaf/content/builders/tree.rb', line 26

def empty_body
  tag(:div, class: "nothing-found") do
    t("Nothing found")
  end
end

#root_levelObject



21
22
23
24
# File 'app/builders/releaf/content/builders/tree.rb', line 21

def root_level
  return empty_body if collection.size < 1
  tree_level(collection, 1)
end

#section_bodyObject



3
4
5
6
7
# File 'app/builders/releaf/content/builders/tree.rb', line 3

def section_body
  tag(:div, class: body_classes) do
    tree
  end
end

#treeObject



15
16
17
18
19
# File 'app/builders/releaf/content/builders/tree.rb', line 15

def tree
  tag(:div, class: "collection") do
    root_level
  end
end

#tree_level(list, level) ⇒ Object



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

def tree_level(list, level)
  tag(:ul, "data-level" => level) do
    list.collect do |resource|
      tree_resource(resource, level)
    end
  end
end

#tree_resource(resource, level) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'app/builders/releaf/content/builders/tree.rb', line 40

def tree_resource(resource, level)
  expanded = (layout_settings("content.tree.expanded.#{resource.id}") == true)
  classes = []
  classes << 'collapsed' unless expanded
  classes << 'has-children' unless resource.children.empty?

  tag(:li, class: classes, data: {level: level, id: resource.id}) do
    tree_resource_blocks(resource, level, expanded)
  end
end

#tree_resource_blocks(resource, level, expanded) ⇒ Object



51
52
53
54
# File 'app/builders/releaf/content/builders/tree.rb', line 51

def tree_resource_blocks(resource, level, expanded)
  [tree_resource_collapser(resource, expanded),
   tree_resource_name(resource), tree_resource_children(resource, level)]
end

#tree_resource_children(resource, level) ⇒ Object



63
64
65
66
# File 'app/builders/releaf/content/builders/tree.rb', line 63

def tree_resource_children(resource, level)
  return if resource.children.empty?
  tree_level(resource.children, level + 1)
end

#tree_resource_collapser(resource, expanded) ⇒ Object



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

def tree_resource_collapser(resource, expanded)
  return if resource.children.empty?
  tag(:div, class: "collapser-cell") do
    button(nil, (expanded ? 'chevron-down' : 'chevron-right'), class: %w(secondary collapser trigger), title: t(expanded ? "collapse" : "expand"))
  end
end

#tree_resource_name(resource) ⇒ Object



68
69
70
71
72
73
74
75
# File 'app/builders/releaf/content/builders/tree.rb', line 68

def tree_resource_name(resource)
  classes = ["node-cell"]
  classes << "active" if resource.active?

  tag(:div, class: classes) do
    tree_resource_name_button(resource)
  end
end

#tree_resource_name_button(resource) ⇒ Object



77
78
79
80
81
82
# File 'app/builders/releaf/content/builders/tree.rb', line 77

def tree_resource_name_button(resource)
  title = resource.content_id.present? ? "#{resource.content_type} ##{resource.content_id}" : resource.content_type
  tag(:a, class: "trigger", href: url_for(action: "edit", id: resource.id), title: title) do
    tag(:span, resource.name)
  end
end