Module: Cms::SectionNodesHelper

Defined in:
app/helpers/cms/section_nodes_helper.rb

Instance Method Summary collapse

Instance Method Details



17
18
19
20
# File 'app/helpers/cms/section_nodes_helper.rb', line 17

def add_link_path_data(section_node, parent_section_node)
  section = figure_out_target_section(parent_section_node, section_node)
  new_section_link_path(section)
end

#add_page_path_data(section_node, parent_section_node) ⇒ Object



12
13
14
15
# File 'app/helpers/cms/section_nodes_helper.rb', line 12

def add_page_path_data(section_node, parent_section_node)
  section = figure_out_target_section(parent_section_node, section_node)
  new_section_page_path(section)
end

#add_section_path_data(section_node, parent_section_node) ⇒ Object



22
23
24
25
# File 'app/helpers/cms/section_nodes_helper.rb', line 22

def add_section_path_data(section_node, parent_section_node)
  section = figure_out_target_section(parent_section_node, section_node)
  new_section_path(section_id: section)
end

#closable_data(section_node, children) ⇒ Object

Marks a section to determine if it can be opened/closed in the sitemap.



78
79
80
81
82
83
84
85
86
# File 'app/helpers/cms/section_nodes_helper.rb', line 78

def closable_data(section_node, children)
  if section_node.root?
    false
  elsif !children.empty?
    true
  else
    false
  end
end

#current_user_can_modify(modifiable_sections, section_node, parent_section_node) ⇒ Object



88
89
90
91
92
93
94
# File 'app/helpers/cms/section_nodes_helper.rb', line 88

def current_user_can_modify(modifiable_sections, section_node, parent_section_node)
  if section_node.section?
    modifiable_sections.include?(section_node.node)
  else
    modifiable_sections.include?(parent_section_node.node)
  end
end

#draggable_class?(modifiable_sections, section_node, parent) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
# File 'app/helpers/cms/section_nodes_helper.rb', line 4

def draggable_class?(modifiable_sections, section_node, parent)
  if !section_node.root? && current_user_can_modify(modifiable_sections, section_node, parent)
    'draggable'
  else
    ''
  end
end

#guest_accessible_icon_tag(parent, content) ⇒ Object



49
50
51
52
53
54
55
# File 'app/helpers/cms/section_nodes_helper.rb', line 49

def guest_accessible_icon_tag(parent, content)
  if content.accessible_to_guests? @public_sections, parent
    ''
  else
    '<span aria-hidden="true" class="permission-icon icon-locked"></span>'.html_safe
  end
end

#hidden_icon_tag(content) ⇒ String

Generate HTML for ‘hidden’ icon for hidden content.

Parameters:

  • content (Object)

Returns:

  • (String)

    HTML (HTML safe)



41
42
43
44
45
46
47
# File 'app/helpers/cms/section_nodes_helper.rb', line 41

def hidden_icon_tag(content)
  if content.respond_to?(:hidden?) && content.hidden?
    '<span aria-hidden="true" class="permission-icon icon-eye-blocked"></span>'.html_safe
  else
    ''
  end
end

#icon_tag(section_node, children) ⇒ Object

Generate the HTML for a given section node.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/cms/section_nodes_helper.rb', line 58

def icon_tag(section_node, children)
  name = if section_node.ancestors.size == 0
           'earth'
         elsif section_node.home?
           'house'
         elsif section_node.link?
           'link'
         elsif section_node.page?
           'file'
         elsif section_node.section? && children.empty?
           'folder-open'
         elsif section_node.section?
           'folder'
         else
           'list' # All other content types.
         end
  ("span", "", {'aria-hidden' => true, class: "type-icon icon-#{name}"})
end

#initial_visibility_class(section_node) ⇒ Object

When sitemap initially renders, we only want to show first level.



28
29
30
# File 'app/helpers/cms/section_nodes_helper.rb', line 28

def initial_visibility_class(section_node)
  section_node.depth >= 1 ? 'hide' : ''
end

#row_type_tag(section_node) ⇒ Object

Determines if a row is leaf or folder based on whether there are any subchildren.



97
98
99
# File 'app/helpers/cms/section_nodes_helper.rb', line 97

def row_type_tag(section_node)
  section_node.section? ? 'folder' : 'leaf'
end

#sitemap_depth_class(section_node) ⇒ Object

Returns a css class for determine sitemap depth.



33
34
35
36
# File 'app/helpers/cms/section_nodes_helper.rb', line 33

def sitemap_depth_class(section_node)
  one_based_depth = section_node.depth + 1
  "level-#{one_based_depth}"
end