Module: Releaf::Content::Builders::Tree
- Included in:
- Dialog, Nodes::IndexBuilder
- Defined in:
- app/builders/releaf/content/builders/tree.rb
Instance Method Summary collapse
- #body_classes ⇒ Object
- #empty_body ⇒ Object
- #root_level ⇒ Object
- #section_body ⇒ Object
- #tree ⇒ Object
- #tree_level(list, level) ⇒ Object
- #tree_resource(resource, level) ⇒ Object
- #tree_resource_blocks(resource, level, expanded) ⇒ Object
- #tree_resource_children(resource, level) ⇒ Object
- #tree_resource_collapser(resource, expanded) ⇒ Object
- #tree_resource_name(resource) ⇒ Object
- #tree_resource_name_button(resource) ⇒ Object
Instance Method Details
#body_classes ⇒ Object
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_body ⇒ Object
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_level ⇒ Object
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_body ⇒ Object
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 |
#tree ⇒ Object
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) = (layout_settings("content.tree.expanded.#{resource.id}") == true) classes = [] classes << 'collapsed' unless classes << 'has-children' unless resource.children.empty? tag(:li, class: classes, data: {level: level, id: resource.id}) do tree_resource_blocks(resource, level, ) 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, ) [tree_resource_collapser(resource, ), 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, ) return if resource.children.empty? tag(:div, class: "collapser-cell") do (nil, ( ? 'chevron-down' : 'chevron-right'), class: %w(secondary collapser trigger), title: t( ? "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 (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 (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 |