Class: Locomotive::Shared::PagesHelper::Node
- Inherits:
-
Struct
- Object
- Struct
- Locomotive::Shared::PagesHelper::Node
- Extended by:
- Forwardable
- Defined in:
- app/helpers/locomotive/shared/pages_helper.rb
Constant Summary collapse
- MAX_WIDTH =
starts at depth 2
[180, 157, 134].freeze
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#page ⇒ Object
Returns the value of attribute page.
Instance Method Summary collapse
- #children? ⇒ Boolean
- #class_names ⇒ Object
- #content_type ⇒ Object
- #deeper_text_inline_style ⇒ Object
- #draggable ⇒ Object
- #draggable? ⇒ Boolean
- #fold_state ⇒ Object
- #max_width(inc = 0) ⇒ Object
- #nodes ⇒ Object
- #show? ⇒ Boolean
- #templatized_children? ⇒ Boolean
- #templatized_page ⇒ Object
- #templatized_parent? ⇒ Boolean
- #text_inline_style(inc = 0) ⇒ Object
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children
56 57 58 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 56 def children @children end |
#controller ⇒ Object
Returns the value of attribute controller
56 57 58 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 56 def controller @controller end |
#page ⇒ Object
Returns the value of attribute page
56 57 58 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 56 def page @page end |
Instance Method Details
#children? ⇒ Boolean
74 75 76 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 74 def children? !children.blank? end |
#class_names ⇒ Object
78 79 80 81 82 83 84 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 78 def class_names base = ['page'] base << (children? ? 'node' : 'leaf') base << (published? ? 'published' : 'unpublished') base << (index_or_not_found? ? 'fixed' : '') if children? base.join(' ') end |
#content_type ⇒ Object
122 123 124 125 126 127 128 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 122 def content_type return @content_type unless @content_type.nil? @content_type = (if templatized_page templatized_page.try(:content_type_with_main_attributes) end) end |
#deeper_text_inline_style ⇒ Object
94 95 96 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 94 def deeper_text_inline_style text_inline_style(1) end |
#draggable ⇒ Object
98 99 100 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 98 def draggable draggable? ? 'draggable' : '' end |
#draggable? ⇒ Boolean
102 103 104 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 102 def draggable? !index_or_not_found? && (templatized? || !templatized_parent?) end |
#fold_state ⇒ Object
64 65 66 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 64 def fold_state controller.send(:cookies)["node-#{_id}"] != 'unfolded' ? 'folded' : 'unfolded' end |
#max_width(inc = 0) ⇒ Object
130 131 132 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 130 def max_width(inc = 0) depth >= 2 ? MAX_WIDTH[depth - 2 + inc] : nil end |
#nodes ⇒ Object
68 69 70 71 72 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 68 def nodes children.map do |(child, children)| self.class.new(child, children, controller) end end |
#show? ⇒ Boolean
134 135 136 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 134 def show? controller.send(:policy, page).show? end |
#templatized_children? ⇒ Boolean
110 111 112 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 110 def templatized_children? !templatized_page.nil? end |
#templatized_page ⇒ Object
114 115 116 117 118 119 120 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 114 def templatized_page return @templatized_page unless @templatized_page.nil? @templatized_page = (if children? children.find { |(child, _)| child.templatized? }.try(:first) end) end |
#templatized_parent? ⇒ Boolean
106 107 108 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 106 def templatized_parent? parent&.templatized? end |
#text_inline_style(inc = 0) ⇒ Object
86 87 88 89 90 91 92 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 86 def text_inline_style(inc = 0) if width = max_width(inc) "max-width: #{width}px;" else '' end end |