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 !
extract article permalink generation into class method [Martins]

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2231 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Wed Sep 20 19:57:58 -0700 2006
commit  d8f44f16692fc1894115ce768e30723c4e73c4b4
tree    c8b6d74169f40c74cf5d4696f11a2e2c516cb103
parent  574adb337ce96367445a58cc53e4b9d1a060c8fd
...
66
67
68
 
 
 
 
69
70
71
...
123
124
125
126
 
127
128
129
...
66
67
68
69
70
71
72
73
74
75
...
127
128
129
 
130
131
132
133
0
@@ -66,6 +66,10 @@ class Article < Content
0
       find(:all, :order => 'contents.published_at DESC', :include => [:tags, :user], :limit => limit,
0
         :conditions => ['(contents.published_at <= ? AND contents.published_at IS NOT NULL) AND tags.name IN (?)', Time.now.utc, tag_names])
0
     end
0
+
0
+ def permalink_for(str)
0
+ str.gsub(/\W+/, ' ').strip.downcase.gsub(/\ +/, '-')
0
+ end
0
   end
0
 
0
   [:year, :month, :day].each { |m| delegate m, :to => :published_at }
0
@@ -123,7 +127,7 @@ class Article < Content
0
 
0
   protected
0
     def create_permalink
0
- self.permalink = title.to_s.gsub(/\W+/, ' ').strip.downcase.gsub(/\ +/, '-') if permalink.blank?
0
+ self.permalink = self.class.permalink_for(title.to_s) if permalink.blank?
0
     end
0
 
0
     def convert_to_utc
...
12
13
14
 
 
 
 
 
15
16
17
...
12
13
14
15
16
17
18
19
20
21
22
0
@@ -12,6 +12,11 @@ class ArticleTest < Test::Unit::TestCase
0
     a = create_article :title => 'This IS a Tripped out title!!.!1 (well/ not really)', :body => 'foo', :permalink => 'trippy'
0
     assert_equal 'trippy', a.permalink
0
   end
0
+
0
+ def test_permalink_for_strange_article_title
0
+ title = '////// meph1sto r0x ! \\\\\\'
0
+ assert_equal 'meph1sto-r0x', Article.permalink_for(title)
0
+ end
0
 
0
   def test_full_permalink
0
     date = 3.days.ago

Comments

    No one has commented yet.