Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Change child_section and descendent_section methods in the SiteDrop t…
…o search the preloaded sections array.

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2381 567b1171-46fb-0310-a4c9-b4bef9110e78
  • Loading branch information
technoweenie committed Oct 20, 2006
1 parent 6cd908d commit 7c5b84f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,5 +1,7 @@
* SVN *

* Change child_section and descendent_section methods in the SiteDrop to search the preloaded sections array.

* Added global mode var to all templates to check what mode you're in: section, single, page, archive, search, tag

* Remove any notion of a template hierarchy, and the page template itself. Paged sections now default to the 'single' template.
Expand Down
17 changes: 7 additions & 10 deletions app/drops/site_drop.rb
Expand Up @@ -33,21 +33,18 @@ def latest_comments(limit = nil)
end

def find_section(path)
@section_index ||= {}
return @section_index[path] if @section_index[path]
@section_index[path] ||= @current_section_liquid if @current_section && @current_section.path == path
@section_index[path] ||= @sections.detect { |s| s['path'] == path } if @sections
@section_index[path] ||= liquify(@source.sections.find_by_path(path)).first
@section_index ||= sections.inject({}) { |memo, section| memo.update section['path'] => section }
@section_index[path]
end

def find_child_sections(path)
path_search = path + (path == '' ? '%' : '/%')
liquify(*@source.sections.find(:all, :conditions => ['path != ? AND path LIKE ? AND path NOT LIKE ?', path, path_search, "#{path_search}/%"], :order => 'path'))
path << '/' unless path.empty?
sections.select { |s| s['path'] != path && s['path'] =~ %r(^#{Regexp.escape path}[^/]+$) }
end

def find_descendant_sections(path)
path_search = path + (path == '' ? '%' : '/%')
liquify(*@source.sections.find(:all, :conditions => ['path != ? AND path LIKE ?', path, path_search], :order => 'path'))
path << '/' unless path.empty?
sections.select { |s| s['path'] != path && s['path'] =~ %r(^#{Regexp.escape path}) }
end

def blog_sections
Expand Down
6 changes: 3 additions & 3 deletions test/unit/drop_filters_test.rb
Expand Up @@ -44,12 +44,12 @@ def setup

specify "should find child sections" do
assert_models_equal [sections(:about), sections(:earth), sections(:links)], child_sections('').collect(&:source)
assert_models_equal [sections(:africa), sections(:europe)], child_sections('earth').collect(&:source)
assert_models_equal [sections(:europe), sections(:africa)], child_sections('earth').collect(&:source)
end

specify "should find descendant sections" do
assert_models_equal sites(:first).sections.reject(&:home?).sort_by(&:path), descendant_sections('').collect(&:source)
assert_models_equal [sections(:africa), sections(:europe), sections(:bucharest)], descendant_sections('earth').collect(&:source)
assert_models_equal sites(:first).sections.reject(&:home?), descendant_sections('').collect(&:source)
assert_models_equal [sections(:europe), sections(:africa), sections(:bucharest)], descendant_sections('earth').collect(&:source)
end

specify "should find articles by month" do
Expand Down

0 comments on commit 7c5b84f

Please sign in to comment.