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 !
update dispatcher to recognize comment urls

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2132 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sat Sep 09 22:58:59 -0700 2006
commit  d4a1e3cddbe810effd5eef464b61103e5d49b32e
tree    bcd646a7c1b2519a58f9012ad744291e489f06cc
parent  9e3550180b97bb37327354abd5e9fd83d35c24cc
...
73
74
75
76
 
77
78
79
...
73
74
75
 
76
77
78
79
0
@@ -73,7 +73,7 @@ class Site < ActiveRecord::Base
0
           s << piece
0
         end
0
       end
0
- @permalink_regex = Regexp.new("^#{r.join('\/')}$")
0
+ @permalink_regex = Regexp.new("^#{r.join('\/')}(\/comments(\/(\\d+))?)?$")
0
     end
0
     
0
     @permalink_regex
...
5
6
7
8
 
 
 
 
 
 
 
9
10
11
...
50
51
52
53
 
54
55
 
56
 
 
57
58
59
...
5
6
7
 
8
9
10
11
12
13
14
15
16
17
...
56
57
58
 
59
60
 
61
62
63
64
65
66
67
0
@@ -5,7 +5,13 @@ module Mephisto
0
 
0
     def self.run(site, path)
0
       if options = recognize_permalink(site, path)
0
- return [:single, nil, options]
0
+ if options[1] && options[2]
0
+ return [:comment, nil, options.first, options.last]
0
+ elsif options[1]
0
+ return [:comments, nil, options.first]
0
+ else
0
+ return [:single, nil, options.first]
0
+ end
0
       end
0
       
0
       dispatch_type = :list
0
@@ -50,10 +56,12 @@ module Mephisto
0
     def self.recognize_permalink(site, path)
0
       full_path = path.join('/')
0
       if match = site.permalink_regex.match(full_path)
0
- returning({}) do |options|
0
+ returning([{}]) do |result|
0
           site.permalink_variables.each_with_index do |var, i|
0
- options[var] = match[i+1]
0
+ result.first[var] = match[i+1]
0
           end
0
+ result << !match[site.permalink_variables.size + 1].nil?
0
+ result << match[site.permalink_variables.size + 3]
0
         end
0
       end
0
     end
...
49
50
51
 
 
 
 
 
 
 
 
 
 
52
53
54
55
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
58
59
60
61
 
 
62
63
64
...
67
68
69
 
 
70
71
72
...
49
50
51
52
53
54
55
56
57
58
59
60
61
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
...
91
92
93
94
95
96
97
98
0
@@ -49,16 +49,40 @@ context "Dispatcher" do
0
     assert_dispatch :single, nil, options, %w(2006 9 1 foo)
0
   end
0
 
0
+ specify "should dispatch to comments" do
0
+ options = {:year => '2006', :month => '9', :day => '1', :permalink => 'foo'}
0
+ assert_dispatch :comments, nil, options, %w(2006 9 1 foo comments)
0
+ end
0
+
0
+ specify "should dispatch to single comment" do
0
+ options = {:year => '2006', :month => '9', :day => '1', :permalink => 'foo'}
0
+ assert_dispatch :comment, nil, options, '5', %w(2006 9 1 foo comments 5)
0
+ end
0
+
0
   specify "should recognize permalinks" do
0
     @site = sites(:first)
0
     
0
     options = {:year => '2006', :month => '9', :day => '1', :permalink => 'foo'}
0
- assert_equal options, Mephisto::Dispatcher.recognize_permalink(@site, %w(2006 9 1 foo))
0
+ assert_equal [options, false, nil], Mephisto::Dispatcher.recognize_permalink(@site, %w(2006 9 1 foo))
0
+
0
+ @site.permalink_slug = 'entries/:id/:permalink'
0
+ @site.permalink_regex(true)
0
+ options = {:id => '5', :permalink => 'foo-bar-baz'}
0
+ assert_equal [options, false, nil], Mephisto::Dispatcher.recognize_permalink(@site, %w(entries 5 foo-bar-baz))
0
+ end
0
+
0
+ specify "should recognize permalinks with comment" do
0
+ @site = sites(:first)
0
+
0
+ options = {:year => '2006', :month => '9', :day => '1', :permalink => 'foo'}
0
+ assert_equal [options, true, nil], Mephisto::Dispatcher.recognize_permalink(@site, %w(2006 9 1 foo comments))
0
+ assert_equal [options, true, '5'], Mephisto::Dispatcher.recognize_permalink(@site, %w(2006 9 1 foo comments 5))
0
     
0
     @site.permalink_slug = 'entries/:id/:permalink'
0
     @site.permalink_regex(true)
0
     options = {:id => '5', :permalink => 'foo-bar-baz'}
0
- assert_equal options, Mephisto::Dispatcher.recognize_permalink(@site, %w(entries 5 foo-bar-baz))
0
+ assert_equal [options, true, nil], Mephisto::Dispatcher.recognize_permalink(@site, %w(entries 5 foo-bar-baz comments))
0
+ assert_equal [options, true, '5'], Mephisto::Dispatcher.recognize_permalink(@site, %w(entries 5 foo-bar-baz comments 5))
0
   end
0
 
0
   specify "should ignore unrecognized permalinks" do
0
@@ -67,6 +91,8 @@ context "Dispatcher" do
0
     assert_nil Mephisto::Dispatcher.recognize_permalink(sites(:first), %w(2006 239 1 foo))
0
     assert_nil Mephisto::Dispatcher.recognize_permalink(sites(:first), %w(2006 9 123 foo))
0
     assert_nil Mephisto::Dispatcher.recognize_permalink(sites(:first), %w(2006 9 1 a_b))
0
+ assert_nil Mephisto::Dispatcher.recognize_permalink(sites(:first), %w(2006 9 1 foo boo))
0
+ assert_nil Mephisto::Dispatcher.recognize_permalink(sites(:first), %w(2006 9 1 foo comment))
0
   end
0
 
0
   protected
...
38
39
40
41
 
42
43
44
 
45
46
47
...
38
39
40
 
41
42
43
 
44
45
46
47
0
@@ -38,9 +38,9 @@ context "Site Permalink Regular Expression" do
0
   end
0
 
0
   specify "should create permalink regex" do
0
- assert_equal Regexp.new(%(^(\\d{4})\\/(\\d{1,2})\\/(\\d{1,2})\\/([a-z0-9-]+)$)), @site.permalink_regex
0
+ assert_equal Regexp.new(%(^(\\d{4})\\/(\\d{1,2})\\/(\\d{1,2})\\/([a-z0-9-]+)(\/comments(\/(\\d+))?)?$)), @site.permalink_regex
0
     
0
     @site.permalink_slug = "articles/:id/:permalink"
0
- assert_equal Regexp.new(%(^articles\\/(\\d+)\\/([a-z0-9-]+)$)), @site.permalink_regex(true)
0
+ assert_equal Regexp.new(%(^articles\\/(\\d+)\\/([a-z0-9-]+)(\/comments(\/(\\d+))?)?$)), @site.permalink_regex(true)
0
   end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.