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


56
57
58
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 56

def children
  @children
end

#controllerObject

Returns the value of attribute controller

Returns:

  • (Object)

    the current value of controller


56
57
58
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 56

def controller
  @controller
end

#pageObject

Returns the value of attribute page

Returns:

  • (Object)

    the current value of page


56
57
58
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 56

def page
  @page
end

Instance Method Details

#children?Boolean

Returns:


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

def children?
  !children.blank?
end

#class_namesObject


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_typeObject


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_styleObject


94
95
96
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 94

def deeper_text_inline_style
  text_inline_style(1)
end

#draggableObject


98
99
100
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 98

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

#draggable?Boolean

Returns:


102
103
104
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 102

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

#fold_stateObject


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

#nodesObject


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

Returns:


134
135
136
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 134

def show?
  controller.send(:policy, page).show?
end

#templatized_children?Boolean

Returns:


110
111
112
# File 'app/helpers/locomotive/shared/pages_helper.rb', line 110

def templatized_children?
  !templatized_page.nil?
end

#templatized_pageObject


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

Returns:


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