Class: Section
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Section
- Defined in:
- app/models/section.rb
Instance Attribute Summary collapse
-
#full_path ⇒ Object
Returns the value of attribute full_path.
Class Method Summary collapse
Instance Method Summary collapse
- #actual_path ⇒ Object
- #all_children_with_name ⇒ Object
- #ancestors ⇒ Object
- #deletable? ⇒ Boolean
- #editable_by_group?(group) ⇒ Boolean
- #empty? ⇒ Boolean
-
#first_page_or_link ⇒ Object
The first page that is a decendent of this section.
- #move_to(section) ⇒ Object
- #parent ⇒ Object
- #parent=(sec) ⇒ Object
- #parent_id ⇒ Object
- #parent_id=(sec_id) ⇒ Object
- #path_not_reserved ⇒ Object
- #public? ⇒ Boolean
- #status ⇒ Object
- #visible_child_nodes ⇒ Object
Instance Attribute Details
#full_path ⇒ Object
Returns the value of attribute full_path.
37 38 39 |
# File 'app/models/section.rb', line 37 def full_path @full_path end |
Class Method Details
.find_by_name_path(name_path) ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'app/models/section.rb', line 105 def self.find_by_name_path(name_path) section = Section.root.first children = name_path.split("/")[1..-1] || [] children.each do |name| section = section.sections.first(:conditions => {:name => name}) end section end |
Instance Method Details
#actual_path ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'app/models/section.rb', line 125 def actual_path if root? "/" else p = first_page_or_link p ? p.path : "#" end end |
#all_children_with_name ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'app/models/section.rb', line 44 def all_children_with_name child_sections.map do |s| if s.node s.node.full_path = root? ? s.node.name : "#{name} / #{s.node.name}" [s.node] << s.node.all_children_with_name end end.flatten.compact end |
#ancestors ⇒ Object
73 74 75 |
# File 'app/models/section.rb', line 73 def ancestors node ? node.ancestors : [] end |
#deletable? ⇒ Boolean
93 94 95 |
# File 'app/models/section.rb', line 93 def deletable? !root? && empty? end |
#editable_by_group?(group) ⇒ Boolean
97 98 99 |
# File 'app/models/section.rb', line 97 def editable_by_group?(group) group.editable_by_section(self) end |
#empty? ⇒ Boolean
89 90 91 |
# File 'app/models/section.rb', line 89 def empty? child_nodes.reject{|n| n.orphaned?}.empty? end |
#first_page_or_link ⇒ Object
The first page that is a decendent of this section
115 116 117 118 119 120 121 122 123 |
# File 'app/models/section.rb', line 115 def first_page_or_link section_node = child_nodes.of_type(['Link','Page']).first return section_node.node if section_node sections.each do |s| node = s.first_page_or_link return node if node end nil end |
#move_to(section) ⇒ Object
77 78 79 80 81 82 83 |
# File 'app/models/section.rb', line 77 def move_to(section) if root? false else node.move_to_end(section) end end |
#parent ⇒ Object
57 58 59 |
# File 'app/models/section.rb', line 57 def parent node ? node.section : nil end |
#parent=(sec) ⇒ Object
65 66 67 68 69 70 71 |
# File 'app/models/section.rb', line 65 def parent=(sec) if node node.move_to_end(sec) else build_node(:node => self, :section => sec) end end |
#parent_id ⇒ Object
53 54 55 |
# File 'app/models/section.rb', line 53 def parent_id parent ? parent.id : nil end |
#parent_id=(sec_id) ⇒ Object
61 62 63 |
# File 'app/models/section.rb', line 61 def parent_id=(sec_id) self.parent = Section.find(sec_id) end |
#path_not_reserved ⇒ Object
134 135 136 137 138 |
# File 'app/models/section.rb', line 134 def path_not_reserved if Cms.reserved_paths.include?(path) errors.add(:path, "is invalid, '#{path}' a reserved path") end end |
#public? ⇒ Boolean
85 86 87 |
# File 'app/models/section.rb', line 85 def public? !!(groups.find_by_code('guest')) end |
#status ⇒ Object
101 102 103 |
# File 'app/models/section.rb', line 101 def status public? ? :unlocked : :locked end |
#visible_child_nodes ⇒ Object
39 40 41 42 |
# File 'app/models/section.rb', line 39 def visible_child_nodes children = child_nodes.of_type(["Section", "Page", "Link"]).all(:order => 'section_nodes.position') children.select{|sn| sn.visible?} end |