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 !
fix issues with sections named 'Home'

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@1432 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Wed Jul 26 21:57:39 -0700 2006
commit  4e6ba8e9c444e52237365c1a5dd1d5a2d70f7e17
tree    5a57a3af958e3e5ab61584e820eb18eb83495677
parent  3921aeff6d5c87df6c3cbc7c09f930066dc76881
...
103
104
105
106
 
107
108
109
...
103
104
105
 
106
107
108
109
0
@@ -103,7 +103,7 @@ class Admin::ArticlesController < Admin::BaseController
0
   protected
0
     def load_sections
0
       @sections = site.sections.find :all, :order => 'name'
0
- home = @sections.find { |s| s.name == 'home' }
0
+ home = @sections.find &:home?
0
       @sections.delete home
0
       @sections.unshift home
0
     end
...
38
39
40
41
 
42
43
44
...
38
39
40
 
41
42
43
44
0
@@ -38,7 +38,7 @@ class Admin::SectionsController < Admin::BaseController
0
       @article_count = site.sections.articles_count
0
       @sections = site.sections.find :all
0
       @sections.each do |s|
0
- @home = s if s.name.downcase == 'home'
0
+ @home = s if s.home?
0
         @section = s if params[:id].to_s == s.id.to_s
0
       end
0
       @sections.delete @home
...
1
2
3
4
 
 
 
5
6
7
...
18
19
20
21
 
22
23
24
...
45
46
47
 
 
 
 
48
49
50
...
69
70
71
72
 
73
74
75
76
 
77
78
79
...
83
84
85
86
 
87
88
...
1
2
 
 
3
4
5
6
7
8
...
19
20
21
 
22
23
24
25
...
46
47
48
49
50
51
52
53
54
55
...
74
75
76
 
77
78
79
80
 
81
82
83
84
...
88
89
90
 
91
92
93
0
@@ -1,7 +1,8 @@
0
 class Section < ActiveRecord::Base
0
   ARTICLES_COUNT_SQL = 'INNER JOIN assigned_sections ON contents.id = assigned_sections.article_id INNER JOIN sections ON sections.id = assigned_sections.section_id' unless defined?(ARTICLES_COUNT)
0
- validates_presence_of :name
0
- before_create :create_path
0
+ before_validation_on_create :create_path
0
+ validates_presence_of :name, :path, :site_id
0
+ validates_uniqueness_of :path, :case_sensitive => false, :scope => :site_id
0
   belongs_to :site
0
   has_many :assigned_sections, :dependent => :delete_all
0
   has_many :articles, :order => 'position', :through => :assigned_sections do
0
@@ -18,7 +19,7 @@ class Section < ActiveRecord::Base
0
 
0
     def find_by_permalink(permalink, options = {})
0
       find(:first, { :conditions => ['contents.permalink = ? AND published_at <= ? AND contents.published_at IS NOT NULL',
0
- permalink, Time.now.utc] }.merge(options))
0
+ permalink, Time.now.utc] }.merge(options))
0
     end
0
   end
0
 
0
@@ -45,6 +46,10 @@ class Section < ActiveRecord::Base
0
     def articles_count
0
       Article.count :all, :group => :section_id, :joins => ARTICLES_COUNT_SQL
0
     end
0
+
0
+ def permalink_for(str)
0
+ str.gsub(/[^\w\/]|[!\(\)\.]+/, ' ').strip.downcase.gsub(/\ +/, '-')
0
+ end
0
   end
0
 
0
   def to_liquid
0
@@ -69,11 +74,11 @@ class Section < ActiveRecord::Base
0
   end
0
 
0
   def home?
0
- name == 'home'
0
+ path.to_s.downcase == 'home'
0
   end
0
 
0
   def to_url
0
- ((name.nil? || home?) ? '' : name).split('/')
0
+ ((path.blank? || home?) ? '' : path).split('/')
0
   end
0
 
0
   def to_feed_url
0
@@ -83,6 +88,6 @@ class Section < ActiveRecord::Base
0
   protected
0
     def create_path
0
       # nasty regex because i want to keep alpha numerics AND /'s
0
- self.path = name.to_s.gsub(/[^\w\/]|[!\(\)\.]+/, ' ').strip.downcase.gsub(/\ +/, '-') if path.blank?
0
+ self.path = self.class.permalink_for(name.to_s) if path.blank?
0
     end
0
 end
...
33
34
35
36
37
 
 
 
 
 
38
39
40
...
33
34
35
 
 
36
37
38
39
40
41
42
43
0
@@ -33,8 +33,11 @@ module Typo
0
     end
0
 
0
     def find_or_create_sections(typo_article)
0
- home_section = Section.find_by_path 'home'
0
- section_ids = typo_article.categories.inject([home_section.id]) { |a, c| a << ::Section.find_or_create_by_name(c.name, :site_id => 1).id }
0
+ site = ::Site.find(1)
0
+ home_section = site.sections.home
0
+ section_ids = typo_article.categories.inject([home_section.id]) do |a, c|
0
+ a << (site.sections.find_by_path(::Section.permalink_for(c.name)) || site.sections.create(:name => c.name)).id
0
+ end
0
     end
0
 
0
     def create_article(site, typo_article)
...
2
3
4
5
 
6
7
8
9
10
 
11
12
13
14
15
16
 
17
18
19
20
21
22
 
23
24
...
2
3
4
 
5
6
7
8
9
 
10
11
12
13
14
15
 
16
17
18
19
20
21
 
22
23
24
0
@@ -2,23 +2,23 @@
0
 home:
0
   id: 1
0
   site_id: 1
0
- name: home
0
+ name: Home
0
   path: home
0
 about:
0
   id: 2
0
   site_id: 1
0
- name: about
0
+ name: About
0
   path: about
0
   show_paged_articles: true
0
 cupcake_home:
0
   id: 3
0
   site_id: 2
0
- name: home
0
+ name: Home
0
   path: home
0
   show_paged_articles: true
0
 cupcake_about:
0
   id: 4
0
   site_id: 2
0
- name: about
0
+ name: About
0
   path: about
0
   show_paged_articles: true
...
106
107
108
109
 
110
111
112
...
106
107
108
 
109
110
111
112
0
@@ -106,7 +106,7 @@ class Admin::ArticlesControllerTest < Test::Unit::TestCase
0
       [ :year, :month, :day, :hour, :min ].each_with_index do |attr, i|
0
         value = local_time.send(attr)
0
         assert_tag 'option', :attributes => { :selected => 'selected', :value =>
0
- (i > 3 ? ('%02d' % local_time.send(attr)) : value.to_s) },
0
+ (i > 2 ? local_time.send(attr).to_s.rjust(2, '0') : value.to_s) },
0
           :ancestor => { :tag => 'select', :attributes => { :name => "article[#{date_attr}(#{i+1}i)]" } }
0
       end
0
     end
...
5
6
7
8
 
9
10
11
12
 
13
14
15
...
5
6
7
 
8
9
10
11
 
12
13
14
15
0
@@ -5,11 +5,11 @@ class SectionTest < Test::Unit::TestCase
0
 
0
   def test_find_or_create_sanity_check
0
     assert_no_difference Section, :count do
0
- assert_equal sections(:home), sites(:first).sections.find_or_create_by_name('home')
0
+ assert_equal sections(:home), sites(:first).sections.find_or_create_by_path('home')
0
     end
0
     
0
     assert_difference Section, :count do
0
- section = sites(:first).sections.find_or_create_by_name('foo')
0
+ section = sites(:first).sections.create(:name => 'Foo')
0
       assert_equal sites(:first), section.site
0
     end
0
   end

Comments

    No one has commented yet.