Class: Locomotive::Shared::PagesHelper::Node

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#childrenObject

Returns the value of attribute children

Returns:

  • (Object)

    the current value of children



33
34
35
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 33

def children
  @children
end

#controllerObject

Returns the value of attribute controller

Returns:

  • (Object)

    the current value of controller



33
34
35
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 33

def controller
  @controller
end

#pageObject

Returns the value of attribute page

Returns:

  • (Object)

    the current value of page



33
34
35
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 33

def page
  @page
end

Instance Method Details

#children?Boolean

Returns:



51
52
53
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 51

def children?
  !children.blank?
end

#class_namesObject



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_typeObject



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_styleObject



71
72
73
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 71

def deeper_text_inline_style
  text_inline_style(1)
end

#draggableObject



75
76
77
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 75

def draggable
  draggable? ? 'draggable' : ''
end

#draggable?Boolean

Returns:



79
80
81
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 79

def draggable?
  !index_or_not_found? && (templatized? || !templatized_parent?)
end

#fold_stateObject



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

#nodesObject



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

Returns:



87
88
89
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 87

def templatized_children?
  !templatized_page.nil?
end

#templatized_pageObject



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

Returns:



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