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
- #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
33 34 35 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 33 def children @children end |
#controller ⇒ Object
Returns the value of attribute controller
33 34 35 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 33 def controller @controller end |
#page ⇒ Object
Returns the value of attribute page
33 34 35 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 33 def page @page end |
Instance Method Details
#children? ⇒ Boolean
51 52 53 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 51 def children? !children.blank? end |
#class_names ⇒ Object
55 56 57 58 59 60 61 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 55 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
99 100 101 102 103 104 105 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 99 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
71 72 73 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 71 def deeper_text_inline_style text_inline_style(1) end |
#draggable ⇒ Object
75 76 77 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 75 def draggable draggable? ? 'draggable' : '' end |
#draggable? ⇒ Boolean
79 80 81 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 79 def draggable? !index_or_not_found? && (templatized? || !templatized_parent?) end |
#fold_state ⇒ Object
41 42 43 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 41 def fold_state controller.send(:cookies)["node-#{_id}"] != 'unfolded' ? 'folded' : 'unfolded' end |
#max_width(inc = 0) ⇒ Object
107 108 109 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 107 def max_width(inc = 0) depth >= 2 ? MAX_WIDTH[depth - 2 + inc] : nil end |
#nodes ⇒ Object
45 46 47 48 49 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 45 def nodes children.map do |(child, children)| self.class.new(child, children, controller) end end |
#templatized_children? ⇒ Boolean
87 88 89 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 87 def templatized_children? !templatized_page.nil? end |
#templatized_page ⇒ Object
91 92 93 94 95 96 97 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 91 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
83 84 85 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 83 def templatized_parent? parent.templatized? end |
#text_inline_style(inc = 0) ⇒ Object
63 64 65 66 67 68 69 |
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 63 def text_inline_style(inc = 0) if width = max_width(inc) "max-width: #{width}px;" else '' end end |