public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
Change child_section and descendent_section methods in the SiteDrop to 
search the preloaded sections array.

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2381 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Fri Oct 20 07:03:49 -0700 2006
commit  7c5b84ff081f4dbd3ed2e863bdd14014e2fb03fe
tree    6eb49fcee2d3d229c5c68edaa80b42e16d51bcc6
parent  6cd908d31b0f5661cf7f23913272e50d689c3598
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 * SVN *
0
 
0
+* Change child_section and descendent_section methods in the SiteDrop to search the preloaded sections array.
0
+
0
 * Added global mode var to all templates to check what mode you're in: section, single, page, archive, search, tag
0
 
0
 * Remove any notion of a template hierarchy, and the page template itself. Paged sections now default to the 'single' template.
...
33
34
35
36
37
38
39
40
 
 
41
42
 
43
44
45
 
 
46
47
48
49
50
 
 
51
52
53
...
33
34
35
 
 
 
 
 
36
37
38
 
39
40
 
 
41
42
43
44
45
 
 
46
47
48
49
50
0
@@ -33,21 +33,18 @@ class SiteDrop < BaseDrop
0
   end
0
 
0
   def find_section(path)
0
- @section_index ||= {}
0
- return @section_index[path] if @section_index[path]
0
- @section_index[path] ||= @current_section_liquid if @current_section && @current_section.path == path
0
- @section_index[path] ||= @sections.detect { |s| s['path'] == path } if @sections
0
- @section_index[path] ||= liquify(@source.sections.find_by_path(path)).first
0
+ @section_index ||= sections.inject({}) { |memo, section| memo.update section['path'] => section }
0
+ @section_index[path]
0
   end
0
-
0
+
0
   def find_child_sections(path)
0
- path_search = path + (path == '' ? '%' : '/%')
0
- liquify(*@source.sections.find(:all, :conditions => ['path != ? AND path LIKE ? AND path NOT LIKE ?', path, path_search, "#{path_search}/%"], :order => 'path'))
0
+ path << '/' unless path.empty?
0
+ sections.select { |s| s['path'] != path && s['path'] =~ %r(^#{Regexp.escape path}[^/]+$) }
0
   end
0
   
0
   def find_descendant_sections(path)
0
- path_search = path + (path == '' ? '%' : '/%')
0
- liquify(*@source.sections.find(:all, :conditions => ['path != ? AND path LIKE ?', path, path_search], :order => 'path'))
0
+ path << '/' unless path.empty?
0
+ sections.select { |s| s['path'] != path && s['path'] =~ %r(^#{Regexp.escape path}) }
0
   end
0
   
0
   def blog_sections
...
44
45
46
47
 
48
49
50
51
52
 
 
53
54
55
...
44
45
46
 
47
48
49
50
 
 
51
52
53
54
55
0
@@ -44,12 +44,12 @@ context "Drop Filters" do
0
 
0
   specify "should find child sections" do
0
     assert_models_equal [sections(:about), sections(:earth), sections(:links)], child_sections('').collect(&:source)
0
- assert_models_equal [sections(:africa), sections(:europe)], child_sections('earth').collect(&:source)
0
+ assert_models_equal [sections(:europe), sections(:africa)], child_sections('earth').collect(&:source)
0
   end
0
 
0
   specify "should find descendant sections" do
0
- assert_models_equal sites(:first).sections.reject(&:home?).sort_by(&:path), descendant_sections('').collect(&:source)
0
- assert_models_equal [sections(:africa), sections(:europe), sections(:bucharest)], descendant_sections('earth').collect(&:source)
0
+ assert_models_equal sites(:first).sections.reject(&:home?), descendant_sections('').collect(&:source)
0
+ assert_models_equal [sections(:europe), sections(:africa), sections(:bucharest)], descendant_sections('earth').collect(&:source)
0
   end
0
 
0
   specify "should find articles by month" do

Comments

    No one has commented yet.