Class | Section |
In: |
app/models/section.rb
|
Parent: | ActiveRecord::Base |
full_path | [RW] |
# File app/models/section.rb, line 112 112: def self.find_by_name_path(name_path) 113: section = Section.root.first 114: children = name_path.split("/")[1..-1] || [] 115: children.each do |name| 116: section = section.sections.first(:conditions => {:name => name}) 117: end 118: section 119: end
# File app/models/section.rb, line 132 132: def actual_path 133: if root? 134: "/" 135: else 136: p = first_page_or_link 137: p ? p.path : "#" 138: end 139: end
# File app/models/section.rb, line 45 45: def all_children_with_name 46: child_sections.map do |s| 47: if s.node 48: s.node.full_path = root? ? s.node.name : "#{name} / #{s.node.name}" 49: [s.node] << s.node.all_children_with_name 50: end 51: end.flatten.compact 52: end
Set which groups are allowed to access this section. @params [Symbol] code Set of groups to allow (Options :all, :none) Defaults to :none
# File app/models/section.rb, line 150 150: def allow_groups=(code=:none) 151: if code == :all 152: self.groups = Group.all 153: end 154: end
# File app/models/section.rb, line 74 74: def ancestors(options={}) 75: ancs = node ? node.ancestors : [] 76: options[:include_self] ? ancs + [self] : ancs 77: end
# File app/models/section.rb, line 104 104: def editable_by_group?(group) 105: group.editable_by_section(self) 106: end
# File app/models/section.rb, line 96 96: def empty? 97: child_nodes.reject{|n| n.orphaned?}.empty? 98: end
The first page that is a decendent of this section
# File app/models/section.rb, line 122 122: def first_page_or_link 123: section_node = child_nodes.of_type(['Link', 'Page']).first(:order => "section_nodes.position") 124: return section_node.node if section_node 125: sections.each do |s| 126: node = s.first_page_or_link 127: return node if node 128: end 129: nil 130: end
# File app/models/section.rb, line 84 84: def move_to(section) 85: if root? 86: false 87: else 88: node.move_to_end(section) 89: end 90: end
# File app/models/section.rb, line 66 66: def parent=(sec) 67: if node 68: node.move_to_end(sec) 69: else 70: build_node(:node => self, :section => sec) 71: end 72: end
# File app/models/section.rb, line 62 62: def parent_id=(sec_id) 63: self.parent = Section.find(sec_id) 64: end
# File app/models/section.rb, line 141 141: def path_not_reserved 142: if Cms.reserved_paths.include?(path) 143: errors.add(:path, "is invalid, '#{path}' a reserved path") 144: end 145: end
# File app/models/section.rb, line 39 39: def visible_child_nodes(options={}) 40: children = child_nodes.of_type(["Section", "Page", "Link"]).all(:order => 'section_nodes.position') 41: visible_children = children.select{|sn| sn.visible?} 42: options[:limit] ? visible_children[0...options[:limit]] : visible_children 43: end