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 !
leave the permalink generation to the dispatcher

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2223 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Tue Sep 19 09:14:11 -0700 2006
commit  e525dff691c364199af3c814623e3f1557cfd73e
tree    fbc652aca519a9648a413826b8dc0bab209d8855
parent  1601e47585fcb3f84b0f3184ecc23e19cd2cff0b
...
53
54
55
56
57
58
59
...
127
128
129
130
131
132
133
134
135
136
137
...
53
54
55
 
56
57
58
...
126
127
128
 
 
 
 
 
129
130
131
0
@@ -53,7 +53,6 @@ class Site < ActiveRecord::Base
0
   validates_uniqueness_of :host
0
   validate :check_permalink_style
0
   after_create { |s| s.sections.create(:name => 'Home', :path => '') }
0
- attr_reader :permalink_variables
0
 
0
   with_options :order => 'contents.created_at', :class_name => 'Comment' do |comment|
0
     comment.has_many :comments, :conditions => ['contents.approved = ?', true]
0
@@ -127,11 +126,6 @@ class Site < ActiveRecord::Base
0
   
0
   [:attachments, :templates, :resources].each { |m| delegate m, :to => :theme }
0
 
0
- def permalink_regex(refresh = false)
0
- @permalink_regex, @permalink_variables = Mephisto::Dispatcher.build_permalink_regex_with(permalink_style) if refresh || @permalink_regex.nil?
0
- @permalink_regex
0
- end
0
-
0
   def permalink_for(article)
0
     Mephisto::Dispatcher.build_permalink_with(permalink_style, article)
0
   end
...
60
61
62
63
 
 
64
65
 
66
67
68
69
 
 
70
71
72
...
60
61
62
 
63
64
65
 
66
67
68
 
 
69
70
71
72
73
0
@@ -60,13 +60,14 @@ module Mephisto
0
     
0
     def self.recognize_permalink(site, path)
0
       full_path = path.join('/')
0
- if match = site.permalink_regex.match(full_path)
0
+ regex, variables = build_permalink_regex_with(site.permalink_style)
0
+ if match = regex.match(full_path)
0
         returning([{}]) do |result|
0
- site.permalink_variables.each_with_index do |var, i|
0
+ variables.each_with_index do |var, i|
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
+ result << !match[variables.size + 1].nil?
0
+ result << match[variables.size + 3]
0
         end
0
       end
0
     end
...
76
77
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
80
81
...
90
91
92
93
94
95
96
...
103
104
105
106
107
108
109
...
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
...
120
121
122
 
123
124
125
...
132
133
134
 
135
136
137
0
@@ -76,6 +76,36 @@ context "Dispatcher" do
0
     end
0
 end
0
 
0
+context "Dispatcher Permalink Regular Expression" do
0
+ fixtures :sites
0
+
0
+ def setup
0
+ @site = sites(:first)
0
+ end
0
+
0
+ specify "should create permalink regex with default permalink style" do
0
+ assert_equal Regexp.new(%(^(\\d{4})\\/(\\d{1,2})\\/(\\d{1,2})\\/([\\w\\-]+)(\/comments(\/(\\d+))?)?$)),
0
+ Mephisto::Dispatcher.build_permalink_regex_with(@site.permalink_style).first
0
+ end
0
+
0
+ specify "should create permalink regex with custom style" do
0
+ @site.permalink_style = "articles/:id/:permalink"
0
+ assert_equal Regexp.new(%(^articles\\/(\\d+)\\/([\\w\\-]+)(\/comments(\/(\\d+))?)?$)),
0
+ Mephisto::Dispatcher.build_permalink_regex_with(@site.permalink_style).first
0
+ end
0
+
0
+ specify "should pull out permalink variables from default permalink style" do
0
+ assert_equal [:year, :month, :day, :permalink],
0
+ Mephisto::Dispatcher.build_permalink_regex_with(@site.permalink_style).last
0
+ end
0
+
0
+ specify "should pull out permalink variables from custom style" do
0
+ @site.permalink_style = "articles/:id/:permalink"
0
+ assert_equal [:id, :permalink],
0
+ Mephisto::Dispatcher.build_permalink_regex_with(@site.permalink_style).last
0
+ end
0
+end
0
+
0
 context "Dispatcher Permalink Recognition" do
0
   fixtures :sites
0
 
0
@@ -90,7 +120,6 @@ context "Dispatcher Permalink Recognition" do
0
   
0
   specify "should recognize permalinks with custom style" do
0
     @site.permalink_style = '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
@@ -103,7 +132,6 @@ context "Dispatcher Permalink Recognition" do
0
   
0
   specify "should recognize permalinks with comment and custom style" do
0
     @site.permalink_style = 'entries/:id/:permalink'
0
- @site.permalink_regex(true)
0
     options = {:id => '5', :permalink => '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))
...
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
...
44
45
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
48
49
0
@@ -44,21 +44,6 @@ context "Site Permalink Validations" do
0
   end
0
 end
0
 
0
-context "Site Permalink Regular Expression" do
0
- fixtures :sites
0
-
0
- def setup
0
- @site = sites(:first)
0
- end
0
-
0
- specify "should create permalink regex" do
0
- assert_equal Regexp.new(%(^(\\d{4})\\/(\\d{1,2})\\/(\\d{1,2})\\/([\\w\\-]+)(\/comments(\/(\\d+))?)?$)), @site.permalink_regex
0
-
0
- @site.permalink_style = "articles/:id/:permalink"
0
- assert_equal Regexp.new(%(^articles\\/(\\d+)\\/([\\w\\-]+)(\/comments(\/(\\d+))?)?$)), @site.permalink_regex(true)
0
- end
0
-end
0
-
0
 context "Site Permalink Generation" do
0
   fixtures :sites, :contents
0
   

Comments

    No one has commented yet.