Class Section
In: app/models/section.rb
Parent: ActiveRecord::Base

Methods

Attributes

full_path  [RW] 

Public Class methods

[Source]

     # 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

Public Instance methods

[Source]

     # 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

[Source]

    # 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

[Source]

     # 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

[Source]

    # 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

[Source]

     # File app/models/section.rb, line 100
100:   def deletable?
101:     !root? && empty?
102:   end

[Source]

     # File app/models/section.rb, line 104
104:   def editable_by_group?(group)
105:     group.editable_by_section(self)
106:   end

[Source]

    # 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

[Source]

     # 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

[Source]

    # 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

[Source]

    # File app/models/section.rb, line 58
58:   def parent
59:     node ? node.section : nil
60:   end

[Source]

    # 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

[Source]

    # File app/models/section.rb, line 54
54:   def parent_id
55:     parent ? parent.id : nil
56:   end

[Source]

    # File app/models/section.rb, line 62
62:   def parent_id=(sec_id)
63:     self.parent = Section.find(sec_id)
64:   end

[Source]

     # 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

[Source]

    # File app/models/section.rb, line 92
92:   def public?
93:     !!(groups.find_by_code('guest'))
94:   end

[Source]

     # File app/models/section.rb, line 108
108:   def status
109:     public? ? :unlocked : :locked
110:   end

[Source]

    # 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

[Source]

    # File app/models/section.rb, line 79
79:   def with_ancestors(options = {})
80:     options.merge! :include_self => true
81:     self.ancestors(options)
82:   end

[Validate]