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 !
allow next/previous paging with articles within a given section.  [Pascal 
Belloncle]

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2746 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Mon Feb 19 00:25:15 -0800 2007
commit  e133010ec94bff28db35e30825b536dd060e368b
tree    887ca7b23ae9c545c656ca8ca4344bf179e899ca
parent  bc1fa233102e6266f43768667d26a37f5f4f631b
...
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
...
58
59
60
 
 
 
 
 
 
 
 
 
 
 
 
61
62
63
0
@@ -58,18 +58,6 @@ class ArticleDrop < BaseDrop
0
     @assets ||= liquify(*@source.assets)
0
   end
0
 
0
- def next(section=nil)
0
- if nxt = @source.next(section ? section.source : nil)
0
- nxt.to_liquid.tap { |n| n.context = @context if n }
0
- end
0
- end
0
-
0
- def previous(section=nil)
0
- if prev = @source.previous(section ? section.source : nil)
0
- prev.to_liquid.tap { |p| p.context = @context if p }
0
- end
0
- end
0
-
0
   protected
0
     def body_for_mode(mode)
0
       contents = [before_method(:excerpt), before_method(:body)]
...
36
37
38
 
 
 
 
 
 
 
 
 
 
 
 
39
40
41
...
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
0
@@ -36,6 +36,18 @@ module DropFilters
0
   def find_asset(article, label)
0
     article.assets.detect { |a| a.source.label == label }
0
   end
0
+
0
+ def next_article(article, section=nil)
0
+ if nxt = article.source.next(section ? section.source : nil)
0
+ nxt.to_liquid.tap { |n| n.context = @context if n }
0
+ end
0
+ end
0
+
0
+ def previous_article(article, section=nil)
0
+ if prev = article.source.previous(section ? section.source : nil)
0
+ prev.to_liquid.tap { |p| p.context = @context if p }
0
+ end
0
+ end
0
 
0
   def monthly_articles(section, date = nil)
0
     date = parse_date(date)
...
159
160
161
 
 
162
163
164
165
166
 
 
 
 
 
 
 
 
 
167
168
169
...
171
172
173
 
 
174
175
176
177
178
 
 
 
 
 
 
 
 
 
179
180
181
...
159
160
161
162
163
164
165
 
 
 
166
167
168
169
170
171
172
173
174
175
176
177
...
179
180
181
182
183
184
185
 
 
 
186
187
188
189
190
191
192
193
194
195
196
197
0
@@ -159,11 +159,19 @@ class Article < Content
0
   end
0
 
0
   def next(section=nil)
0
+ return nil if section && !sections.include?(section)
0
+ section = sections[0] if (section.nil?)
0
     self.class.with_published do
0
       if section
0
- site.articles.find :first, :conditions => ['published_at > ? and assigned_sections.section_id = ?', published_at, section.id],
0
- :joins => 'inner join assigned_sections on contents.id = assigned_sections.article_id',
0
- :order => 'published_at'
0
+ if section.paged?
0
+ index = section.articles.index(self)
0
+ (index <= section.articles.length-1) ? section.articles[index+1] : nil
0
+ # article = section.articles.detect {|article| article.id == id }
0
+ else
0
+ site.articles.find :first, :conditions => ['published_at > ? and assigned_sections.section_id = ?', published_at, section.id],
0
+ :joins => 'inner join assigned_sections on contents.id = assigned_sections.article_id',
0
+ :order => 'published_at'
0
+ end
0
       else
0
         site.articles.find :first, :conditions => ['published_at > ?', published_at], :order => 'published_at'
0
       end
0
@@ -171,11 +179,19 @@ class Article < Content
0
   end
0
 
0
   def previous(section=nil)
0
+ return nil if section && !sections.include?(section)
0
+ section = sections[0] if (section.nil?)
0
     self.class.with_published do
0
       if section
0
- site.articles.find :first, :conditions => ['published_at < ? and assigned_sections.section_id = ?', published_at, section.id],
0
- :joins => 'inner join assigned_sections on contents.id = assigned_sections.article_id',
0
- :order => 'published_at desc'
0
+ if section.paged?
0
+ index = section.articles.index(self)
0
+ (index > 0) ? section.articles[index-1] : nil
0
+ # article = section.articles.detect {|article| article.id == id }
0
+ else
0
+ site.articles.find :first, :conditions => ['published_at < ? and assigned_sections.section_id = ?', published_at, section.id],
0
+ :joins => 'inner join assigned_sections on contents.id = assigned_sections.article_id',
0
+ :order => 'published_at desc'
0
+ end
0
       else
0
         site.articles.find :first, :conditions => ['published_at < ?', published_at], :order => 'published_at desc'
0
       end
...
55
56
57
58
59
 
 
 
 
 
 
 
 
 
 
 
...
55
56
57
 
58
59
60
61
62
63
64
65
66
67
68
69
0
@@ -55,4 +55,14 @@ future_about:
0
   id: 11
0
   article_id: 5
0
   section_id: 2
0
- position: 5
0
\ No newline at end of file
0
+ position: 5
0
+paged_section_article_1:
0
+ id: 12
0
+ article_id: 16
0
+ section_id: 10
0
+ position: 1
0
+paged_section_article_2:
0
+ id: 13
0
+ article_id: 17
0
+ section_id: 10
0
+ position: 2
...
204
205
206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
208
...
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
0
@@ -204,4 +204,30 @@ at_beginning_of_next_month:
0
   published_at: <%= date %>
0
   comment_age: 30
0
   user_id: 1
0
+ type: Article
0
+article_1_only_in_page_section:
0
+ id: 16
0
+ site_id: 1
0
+ title: Article 1
0
+ permalink: article-1
0
+ body: Lalala
0
+ body_html: Lalala
0
+ created_at: <%= date = Time.now.utc.beginning_of_month.advance(:months => -1).to_s(:db) %>
0
+ updated_at: <%= date %>
0
+ published_at: <%= date %>
0
+ comment_age: 30
0
+ user_id: 1
0
+ type: Article
0
+article_2_only_in_page_section:
0
+ id: 17
0
+ site_id: 1
0
+ title: Article 2
0
+ permalink: article-2
0
+ body: Lalala
0
+ body_html: Lalala
0
+ created_at: <%= date = Time.now.utc.beginning_of_month.advance(:months => -1).to_s(:db) %>
0
+ updated_at: <%= date %>
0
+ published_at: <%= date %>
0
+ comment_age: 30
0
+ user_id: 1
0
   type: Article
0
\ No newline at end of file
...
84
85
86
 
 
 
 
 
 
 
 
 
 
87
...
84
85
86
87
88
89
90
91
92
93
94
95
96
97
0
@@ -84,3 +84,13 @@ links:
0
   articles_count: 0
0
   archive_path: archives
0
   position: 7
0
+paged_section:
0
+ id: 10
0
+ site_id: 1
0
+ name: Paged Section
0
+ path: paged-section
0
+ show_paged_articles: true
0
+ template: page.liquid
0
+ articles_count: 2
0
+ archive_path: archives
0
+ position: 8
0
\ No newline at end of file
...
16
17
18
19
 
20
21
22
...
16
17
18
 
19
20
21
22
0
@@ -16,7 +16,7 @@ class Admin::ArticlesControllerPermissionsTest < Test::Unit::TestCase
0
 
0
   def test_should_show_articles
0
     get :index
0
- assert_equal 10, assigns(:articles).length
0
+ assert_equal 12, assigns(:articles).length
0
   end
0
 
0
   def test_should_show_new_article_form
...
28
29
30
31
 
32
33
34
35
36
 
37
38
39
...
28
29
30
 
31
32
33
34
35
 
36
37
38
39
0
@@ -28,12 +28,12 @@ class Admin::ArticlesControllerTest < Test::Unit::TestCase
0
   
0
   def test_should_show_articles
0
     get :index
0
- assert_equal 10, assigns(:articles).length
0
+ assert_equal 12, assigns(:articles).length
0
   end
0
   
0
   def test_should_show_articles_with_empty_seartest_should_show_checked_sectionsch
0
     get :index, :q => '', :filter => 'title', :section => '0'
0
- assert_equal 10, assigns(:articles).length
0
+ assert_equal 12, assigns(:articles).length
0
   end
0
 
0
   def test_should_search_article_titles
...
18
19
20
21
 
22
23
24
...
77
78
79
80
81
 
 
82
83
84
...
18
19
20
 
21
22
23
24
...
77
78
79
 
 
80
81
82
83
84
0
@@ -18,7 +18,7 @@ class Admin::SectionsControllerTest < Test::Unit::TestCase
0
     get :index
0
     assert_equal sites(:first), assigns(:site)
0
     assert_equal sections(:home), assigns(:home)
0
- assert_equal 7, assigns(:sections).length, "Sections: #{assigns(:sections).collect(&:id).to_sentence}"
0
+ assert_equal 8, assigns(:sections).length, "Sections: #{assigns(:sections).collect(&:id).to_sentence}"
0
     assert_equal 4, assigns(:article_count)['1']
0
     assert_equal 5, assigns(:article_count)['2']
0
   end
0
@@ -77,8 +77,8 @@ class Admin::SectionsControllerTest < Test::Unit::TestCase
0
   end
0
 
0
   def test_should_reorder_sections
0
- assert_reorder_sections [sections(:home), sections(:about), sections(:earth), sections(:europe), sections(:africa), sections(:bucharest), sections(:links)],
0
- [sections(:home), sections(:earth), sections(:europe), sections(:africa), sections(:bucharest), sections(:links), sections(:about)]
0
+ assert_reorder_sections [sections(:home), sections(:about), sections(:earth), sections(:europe), sections(:africa), sections(:bucharest), sections(:links), sections(:paged_section)],
0
+ [sections(:home), sections(:earth), sections(:europe), sections(:africa), sections(:bucharest), sections(:links), sections(:about), sections(:paged_section)]
0
   end
0
 
0
   protected
...
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
...
71
72
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
75
76
0
@@ -71,26 +71,6 @@ class ArticleDropTest < Test::Unit::TestCase
0
     assert_equal '<p>body</p>', a.send(:body_for_mode, :list)
0
   end
0
 
0
- def test_find_next
0
- another = contents(:another).to_liquid
0
- another.context = @context
0
- cupcake_welcome = contents(:cupcake_welcome).to_liquid
0
- cupcake_welcome.context = @context
0
-
0
- assert_equal another.next, contents(:site_map).to_liquid
0
- assert_equal another.next(sections(:home).to_liquid), contents(:welcome).to_liquid
0
- assert_equal cupcake_welcome.next(sections(:cupcake_home).to_liquid), nil
0
- end
0
-
0
- def test_should_find_previous
0
- another = contents(:another).to_liquid
0
- another.context = @context
0
-
0
- assert_equal another.previous, contents(:at_beginning_of_next_month).to_liquid
0
- assert_equal another.previous(sections(:home).to_liquid), nil
0
- assert_not_equal another.previous(sections(:cupcake_home).to_liquid), contents(:at_beginning_of_next_month).to_liquid
0
- end
0
-
0
   specify "should show article url" do
0
     t = Time.now.utc - 3.days
0
     assert_equal "/#{t.year}/#{t.month}/#{t.day}/welcome-to-mephisto", @article.url
...
4
5
6
7
 
8
9
 
 
 
 
 
 
10
11
12
13
 
14
 
 
15
 
 
 
 
16
17
18
...
4
5
6
 
7
8
 
9
10
11
12
13
14
15
16
17
 
18
19
20
21
22
23
24
25
26
27
28
29
0
@@ -4,15 +4,26 @@ class ArticleTest < Test::Unit::TestCase
0
   fixtures :contents, :users, :sections, :sites, :assigned_sections
0
 
0
   def test_find_next
0
- assert_equal contents(:another).next, contents(:site_map)
0
+ assert_equal contents(:another).next, contents(:welcome)
0
     assert_equal contents(:another).next(sections(:home)), contents(:welcome)
0
- assert_equal contents(:cupcake_welcome).next(sections(:cupcake_home)), nil
0
+ assert_equal contents(:another).next(sections(:about)), nil
0
+ assert_equal contents(:welcome).next(sections(:about)), contents(:about)
0
+ assert_equal contents(:article_1_only_in_page_section).next, contents(:article_2_only_in_page_section)
0
+ assert_equal contents(:article_1_only_in_page_section).next(sections(:paged_section)), contents(:article_2_only_in_page_section)
0
+ assert_equal contents(:article_2_only_in_page_section).next, nil
0
+ assert_equal contents(:article_2_only_in_page_section).next(sections(:paged_section)), nil
0
   end
0
 
0
   def test_should_find_previous
0
- assert_equal contents(:another).previous, contents(:at_beginning_of_next_month)
0
+ assert_equal contents(:another).previous, nil
0
     assert_equal contents(:another).previous(sections(:home)), nil
0
+ assert_equal contents(:another).previous(sections(:about)), nil
0
+ assert_equal contents(:welcome).previous(sections(:home)), contents(:another)
0
     assert_not_equal contents(:another).previous(sections(:cupcake_home)), contents(:at_beginning_of_next_month)
0
+ assert_equal contents(:article_2_only_in_page_section).previous, contents(:article_1_only_in_page_section)
0
+ assert_equal contents(:article_2_only_in_page_section).previous(sections(:paged_section)), contents(:article_1_only_in_page_section)
0
+ assert_equal contents(:article_1_only_in_page_section).previous, nil
0
+ assert_equal contents(:article_1_only_in_page_section).previous(sections(:paged_section)), nil
0
   end
0
   
0
   def test_should_create_permalink
...
32
33
34
35
 
36
37
38
...
43
44
45
46
 
47
48
49
...
62
63
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
66
67
...
32
33
34
 
35
36
37
38
...
43
44
45
 
46
47
48
49
...
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
0
@@ -32,7 +32,7 @@ context "Drop Filters" do
0
   end
0
 
0
   specify "should find latest articles by site" do
0
- assert_models_equal [contents(:welcome), contents(:about), contents(:site_map), contents(:another), contents(:at_beginning_of_next_month), contents(:at_end_of_month), contents(:at_middle_of_month), contents(:at_beginning_of_month)],
0
+ assert_models_equal [contents(:welcome), contents(:about), contents(:site_map), contents(:another), contents(:at_beginning_of_next_month), contents(:article_1_only_in_page_section), contents(:article_2_only_in_page_section), contents(:at_end_of_month), contents(:at_middle_of_month), contents(:at_beginning_of_month)],
0
       latest_articles(@site).collect(&:source)
0
     assert_models_equal [contents(:welcome), contents(:about)], latest_articles(@site, 2).collect(&:source)
0
   end
0
@@ -43,7 +43,7 @@ context "Drop Filters" do
0
   end
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(:about), sections(:earth), sections(:links), sections(:paged_section)], child_sections('').collect(&:source)
0
     assert_models_equal [sections(:europe), sections(:africa)], child_sections('earth').collect(&:source)
0
   end
0
 
0
@@ -62,6 +62,29 @@ context "Drop Filters" do
0
     assert_equal assets(:mp3), find_asset(article, 'podcast').source
0
   end
0
 
0
+ def test_find_next
0
+ another = contents(:another).to_liquid
0
+ another.context = @context
0
+ cupcake_welcome = contents(:cupcake_welcome).to_liquid
0
+ cupcake_welcome.context = @context
0
+
0
+ assert_equal next_article(another), contents(:welcome).to_liquid
0
+ assert_equal next_article(another, sections(:home).to_liquid), contents(:welcome).to_liquid
0
+ assert_equal next_article(cupcake_welcome, sections(:cupcake_home).to_liquid), nil
0
+ end
0
+
0
+ def test_should_find_previous
0
+ another = contents(:another).to_liquid
0
+ another.context = @context
0
+ welcome = contents(:welcome).to_liquid
0
+ welcome.context = @context
0
+
0
+ assert_equal previous_article(another), nil
0
+ assert_equal previous_article(another, sections(:home).to_liquid), nil
0
+ assert_equal previous_article(welcome, sections(:home).to_liquid), another
0
+ assert_not_equal previous_article(another, sections(:cupcake_home).to_liquid), contents(:at_beginning_of_next_month).to_liquid
0
+ end
0
+
0
   specify "should find movies" do
0
     assert_models_equal [assets(:swf), assets(:mov)], assets_by_type('movie').collect(&:source)
0
   end
...
103
104
105
106
107
 
 
108
109
110
...
103
104
105
 
 
106
107
108
109
110
0
@@ -103,8 +103,8 @@ class SectionTest < Test::Unit::TestCase
0
   end
0
 
0
   specify "should return correct sections" do
0
- assert_models_equal [sections(:about), sections(:africa), sections(:bucharest), sections(:earth), sections(:europe), sections(:home), sections(:links)], sites(:first).sections.find(:all, :order => 'name')
0
- assert_models_equal [sections(:about), sections(:links)], sites(:first).sections.find_paged
0
+ assert_models_equal [sections(:about), sections(:africa), sections(:bucharest), sections(:earth), sections(:europe), sections(:home), sections(:links), sections(:paged_section)], sites(:first).sections.find(:all, :order => 'name')
0
+ assert_models_equal [sections(:about), sections(:links), sections(:paged_section)], sites(:first).sections.find_paged
0
   end
0
 
0
   specify "should order articles in sections" do
...
18
19
20
21
22
 
 
23
24
25
...
30
31
32
33
 
34
35
36
...
38
39
40
41
 
42
43
44
...
54
55
56
57
 
58
59
60
...
18
19
20
 
 
21
22
23
24
25
...
30
31
32
 
33
34
35
36
...
38
39
40
 
41
42
43
44
...
54
55
56
 
57
58
59
60
0
@@ -18,8 +18,8 @@ class SiteDropTest < Test::Unit::TestCase
0
   end
0
 
0
   def test_should_list_all_sections
0
- assert_models_equal [sections(:home), sections(:about), sections(:earth), sections(:europe), sections(:africa), sections(:bucharest), sections(:links)], @site.sections.collect(&:source)
0
- assert_equal [false, false, false, false, false, false, false], @site.sections.collect(&:current)
0
+ assert_models_equal [sections(:home), sections(:about), sections(:earth), sections(:europe), sections(:africa), sections(:bucharest), sections(:links), sections(:paged_section)], @site.sections.collect(&:source)
0
+ assert_equal [false, false, false, false, false, false, false, false], @site.sections.collect(&:current)
0
   end
0
   
0
   def test_should_default_to_no_current_section
0
@@ -30,7 +30,7 @@ class SiteDropTest < Test::Unit::TestCase
0
     @site = SiteDrop.new(sites(:first), sections(:about))
0
     @site.context = mock_context
0
     assert_equal sections(:about), @site.current_section.source
0
- assert_equal [false, true, false, false, false, false, false], @site.sections.collect(&:current)
0
+ assert_equal [false, true, false, false, false, false, false, false], @site.sections.collect(&:current)
0
   end
0
   
0
   def test_should_list_only_blog_sections
0
@@ -38,7 +38,7 @@ class SiteDropTest < Test::Unit::TestCase
0
   end
0
   
0
   def test_should_list_only_paged_sections
0
- assert_models_equal [sections(:about), sections(:links)], @site.page_sections.collect(&:source)
0
+ assert_models_equal [sections(:about), sections(:links), sections(:paged_section)], @site.page_sections.collect(&:source)
0
   end
0
 
0
   def test_should_list_tags
0
@@ -54,7 +54,7 @@ class SiteDropTest < Test::Unit::TestCase
0
   end
0
 
0
   def test_should_find_latest_articles
0
- assert_models_equal [contents(:welcome), contents(:about), contents(:site_map), contents(:another), contents(:at_beginning_of_next_month), contents(:at_end_of_month), contents(:at_middle_of_month), contents(:at_beginning_of_month)],
0
+ assert_models_equal [contents(:welcome), contents(:about), contents(:site_map), contents(:another), contents(:at_beginning_of_next_month), contents(:article_1_only_in_page_section), contents(:article_2_only_in_page_section), contents(:at_end_of_month), contents(:at_middle_of_month), contents(:at_beginning_of_month)],
0
       @site.latest_articles.collect(&:source)
0
     assert_models_equal [contents(:welcome), contents(:about)], @site.latest_articles(2).collect(&:source)
0
   end
...
56
57
58
59
60
 
 
61
62
63
...
56
57
58
 
 
59
60
61
62
63
0
@@ -56,8 +56,8 @@ context "Site" do
0
   end
0
 
0
   specify "should order sections in site" do
0
- assert_reorder_sections [sections(:home), sections(:about), sections(:earth), sections(:europe), sections(:africa), sections(:bucharest), sections(:links)],
0
- [sections(:home), sections(:earth), sections(:europe), sections(:africa), sections(:bucharest), sections(:links), sections(:about)]
0
+ assert_reorder_sections [sections(:home), sections(:about), sections(:earth), sections(:europe), sections(:africa), sections(:bucharest), sections(:links), sections(:paged_section)],
0
+ [sections(:home), sections(:earth), sections(:europe), sections(:africa), sections(:bucharest), sections(:links), sections(:about), sections(:paged_section)]
0
   end
0
 
0
   specify "should find at least one extension (.liquid)" do

Comments

    No one has commented yet.