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 !
use the section path

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@1424 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Tue Jul 25 20:13:05 -0700 2006
commit  b4e83b91a5a44c0727c9b9f6f882b151d4b925cc
tree    ea5309a7710428c9f2a7c3d61bb39f1d1294777e
parent  a33089a36797f1b9cec7c58107d0b9e3bd5a6168
...
8
9
10
11
 
12
13
14
...
8
9
10
 
11
12
13
14
0
@@ -8,7 +8,7 @@ class FeedController < ApplicationController
0
     last = sections.last
0
     sections.delete(last) if last =~ /\.xml$/
0
     
0
- @section = site.sections.find_by_name(sections.blank? ? 'home' : sections.join('/'))
0
+ @section = site.sections.find_by_path(sections.blank? ? 'home' : sections.join('/'))
0
     @articles = @section.articles.find_by_date(:limit => 15)
0
     self.cached_references += @articles
0
   end
...
4
5
6
7
 
8
9
10
11
 
12
13
14
...
4
5
6
 
7
8
9
10
 
11
12
13
14
0
@@ -4,11 +4,11 @@ class MephistoController < ApplicationController
0
 
0
   def list
0
     if params[:sections].blank?
0
- @section = site.sections.find_by_name('home')
0
+ @section = site.sections.find_by_path('home')
0
       @section.show_paged_articles? ? show_section_page_with(nil, :main) : list_section_articles_with(:main)
0
     else
0
       @section, page_name = site.sections.find_section_and_page_name(params[:sections].dup)
0
- @section ||= site.sections.find_by_name('home')
0
+ @section ||= site.sections.find_by_path('home')
0
       if @section.show_paged_articles?
0
         show_section_page_with(page_name, :page)
0
       else
...
1
2
3
4
 
5
6
7
...
36
37
38
39
 
40
41
42
...
81
82
83
84
 
85
86
 
87
88
...
1
2
3
 
4
5
6
7
...
36
37
38
 
39
40
41
42
...
81
82
83
 
84
85
 
86
87
88
0
@@ -1,7 +1,7 @@
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_permalink
0
+ before_create :create_path
0
   belongs_to :site
0
   has_many :assigned_sections, :dependent => :delete_all
0
   has_many :articles, :order => 'position', :through => :assigned_sections do
0
@@ -36,7 +36,7 @@ class Section < ActiveRecord::Base
0
       page_name = []
0
       section = nil
0
       while section.nil? && section_path.any?
0
- section = find_by_name(section_path.join('/'))
0
+ section = find_by_path(section_path.join('/'))
0
         page_name << section_path.pop if section.nil?
0
       end
0
       [section, page_name.any? ? page_name.join('/') : nil]
0
@@ -81,8 +81,8 @@ class Section < ActiveRecord::Base
0
   end
0
   
0
   protected
0
- def create_permalink
0
+ def create_path
0
       # nasty regex because i want to keep alpha numerics AND /'s
0
- self.permalink = name.to_s.gsub(/[^\w\/]|[!\(\)\.]+/, ' ').strip.downcase.gsub(/\ +/, '-')
0
+ self.path = name.to_s.gsub(/[^\w\/]|[!\(\)\.]+/, ' ').strip.downcase.gsub(/\ +/, '-') if path.blank?
0
     end
0
 end
...
1
2
3
4
 
5
6
7
...
1
2
3
 
4
5
6
7
0
@@ -1,7 +1,7 @@
0
 class Site < ActiveRecord::Base
0
   has_many :sections do
0
     def home
0
- Section.find_by_name 'home'
0
+ Section.find_by_path 'home'
0
     end
0
   end
0
 
...
4
5
6
 
 
7
8
9
...
4
5
6
7
8
9
10
11
0
@@ -4,6 +4,8 @@
0
   <dl>
0
     <dt><label for="section_name">Section name</label></dt>
0
     <dd><%= f.text_field :name, :class => 'big' %></dd>
0
+ <dt><label for="section_path">Section path</label></dt>
0
+ <dd><%= f.text_field :path, :class => 'big' %></dd>
0
     <dt><label for="section_show_paged_articles">Type of section</label></dt>
0
     <dd>
0
       <select id="section_show_paged_articles" name="section[show_paged_articles]" onchange="SectionForm.toggle_settings();">
...
1
2
3
4
 
 
5
6
...
1
2
3
 
4
5
6
7
0
@@ -1,5 +1,6 @@
0
 home:
0
   id: 1
0
   site_id: 1
0
- name: home
0
+ name: Home
0
+ path: home
0
   articles_per_page: 15
0
\ No newline at end of file
...
2
3
4
5
 
6
7
8
...
102
103
104
105
 
106
107
108
...
2
3
4
 
5
6
7
8
...
102
103
104
 
105
106
107
108
0
@@ -2,7 +2,7 @@
0
 # migrations feature of ActiveRecord to incrementally modify your database, and
0
 # then regenerate this schema definition.
0
 
0
-ActiveRecord::Schema.define(:version => 35) do
0
+ActiveRecord::Schema.define(:version => 36) do
0
 
0
   create_table "assigned_sections", :force => true do |t|
0
     t.column "article_id", :integer
0
@@ -102,7 +102,7 @@ ActiveRecord::Schema.define(:version => 35) do
0
     t.column "layout", :string
0
     t.column "template", :string
0
     t.column "site_id", :integer
0
- t.column "permalink", :string
0
+ t.column "path", :string
0
   end
0
 
0
   create_table "sessions", :force => true do |t|
...
2
3
4
5
 
6
7
8
...
2
3
4
 
5
6
7
8
0
@@ -2,7 +2,7 @@ require 'convert/textpattern/article'
0
 require 'convert/textpattern/comment'
0
 module TextPattern
0
   def self.convert
0
- section = Section.find_by_name('home')
0
+ section = Section.find_by_path('home')
0
     TextPattern::Article.find(:all, :include => :comments).each do |article|
0
       a = ::Article.create \
0
         :title => article.Title,
...
33
34
35
36
 
37
38
39
...
33
34
35
 
36
37
38
39
0
@@ -33,7 +33,7 @@ module Typo
0
     end
0
 
0
     def find_or_create_sections(typo_article)
0
- home_section = Section.find_by_name 'home'
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
     end
0
 
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@ module Mephisto
0
 
0
       def initialize(section)
0
         @section = section
0
- @section_liquid = [:id, :name, :permalink].inject({}) { |h, k| h.merge k.to_s => section.send(k) }
0
+ @section_liquid = [:id, :name, :path].inject({}) { |h, k| h.merge k.to_s => section.send(k) }
0
       end
0
 
0
       def before_method(method)
...
3
4
5
6
 
7
8
9
10
11
 
12
13
14
15
16
17
 
18
19
20
21
22
23
 
24
...
3
4
5
 
6
7
8
9
10
 
11
12
13
14
15
16
 
17
18
19
20
21
22
 
23
24
0
@@ -3,22 +3,22 @@ home:
0
   id: 1
0
   site_id: 1
0
   name: home
0
- permalink: home
0
+ path: home
0
 about:
0
   id: 2
0
   site_id: 1
0
   name: about
0
- permalink: about
0
+ path: about
0
   show_paged_articles: true
0
 cupcake_home:
0
   id: 3
0
   site_id: 2
0
   name: home
0
- permalink: home
0
+ path: home
0
   show_paged_articles: true
0
 cupcake_about:
0
   id: 4
0
   site_id: 2
0
   name: about
0
- permalink: about
0
+ path: about
0
   show_paged_articles: true
...
14
15
16
17
 
18
19
 
 
 
 
 
 
20
21
22
...
14
15
16
 
17
18
 
19
20
21
22
23
24
25
26
27
0
@@ -14,9 +14,14 @@ class SectionTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
- def test_should_create_permalink
0
+ def test_should_create_path
0
     s = sites(:first).sections.find_or_create_by_name('This IS a Tripped out title!!!1 (well/ not. really)')
0
- assert_equal 'this-is-a-tripped-out-title-1-well/-not-really', s.permalink
0
+ assert_equal 'this-is-a-tripped-out-title-1-well/-not-really', s.path
0
+ end
0
+
0
+ def test_should_use_path
0
+ s = sites(:first).sections.create(:name => 'This IS a Tripped out title!!!1 (well/ not. really)', :path => 'trippy')
0
+ assert_equal 'trippy', s.path
0
   end
0
 
0
   def test_should_return_correct_url_paths

Comments

    No one has commented yet.