public
Description: This contains various plugins for Feather
Clone URL: git://github.com/eldiablo/feather-plugins.git
Click here to lend your support to: feather-plugins and make a donation at www.pledgie.com !
updated pages to DM 0.9
eldiablo (author)
Mon Jun 23 15:22:59 -0700 2008
commit  383c784567fd08ab126bc4c5f0e35534c89bde76
tree    adb585b2d8307c5215d935e6cebf4c99356a7d3c
parent  079437d6f55cad61c4a033a37a9e9cd05e44165d
...
4
5
6
7
 
8
9
10
...
19
20
21
 
 
22
23
24
...
39
40
41
 
 
42
43
44
...
63
64
65
66
 
67
68
69
70
...
4
5
6
 
7
8
9
10
...
19
20
21
22
23
24
25
26
...
41
42
43
44
45
46
47
48
...
67
68
69
 
70
71
72
73
74
0
@@ -4,7 +4,7 @@ module Admin
0
     before :find_page, :only => %w(edit update delete show)
0
 
0
     def index
0
- @pages = Page.all(:order => "created_at DESC")
0
+ @pages = Page.all(:order => [:created_at.desc])
0
       display @pages
0
     end
0
 
0
@@ -19,6 +19,8 @@ module Admin
0
     end
0
 
0
     def create(page)
0
+ page["published"] = (page["published"] == "1")
0
+ page["display_in_nav"] = (page["display_in_nav"] == "1")
0
       @page = Page.new(page)
0
       get_pages
0
       @parent_selected = params[:page][:parent_id].to_i
0
@@ -39,6 +41,8 @@ module Admin
0
     end
0
 
0
     def update(page)
0
+ page["published"] = (page["published"] == "1")
0
+ page["display_in_nav"] = (page["display_in_nav"] == "1")
0
       if @page.update_attributes(page)
0
         # Expire all pages to reflect the updated page
0
         expire_all_pages
0
@@ -63,7 +67,7 @@ module Admin
0
       end
0
       
0
       def get_pages
0
- @pages = Page.all(:order => "title")
0
+ @pages = Page.all(:order => [:title.asc])
0
       end
0
   end
0
 end
0
\ No newline at end of file
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
16
17
18
19
 
 
 
 
20
21
22
23
24
 
 
 
25
26
 
27
28
29
30
31
 
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
49
50
51
52
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
 
 
 
19
20
21
22
23
24
 
 
 
25
26
27
28
 
29
30
31
32
33
 
34
35
36
37
38
39
 
 
 
 
 
40
41
42
43
44
45
 
46
47
 
48
49
0
@@ -1,51 +1,48 @@
0
-class Page < DataMapper::Base
0
- property :parent_id, :integer
0
- property :user_id, :integer, :nullable => false
0
- property :title, :string, :nullable => false, :length => 255
0
- property :permalink, :string, :length => 255
0
- property :content, :text, :nullable => false
0
- property :display_in_nav, :boolean, :default => true
0
- property :position, :integer
0
- property :meta_description, :text
0
- property :meta_keywords, :text
0
- property :created_at, :datetime
0
- property :published_at, :datetime
0
- property :published, :boolean, :default => true
0
- property :formatter, :string, :default => "default"
0
+class Page
0
+ include DataMapper::Resource
0
+
0
+ property :id, Integer, :key => true, :serial => true
0
+ property :parent_id, Integer
0
+ property :user_id, Integer, :nullable => false
0
+ property :title, String, :nullable => false, :length => 255
0
+ property :permalink, String, :length => 255
0
+ property :content, Text, :nullable => false
0
+ property :display_in_nav, Boolean, :default => true
0
+ property :position, Integer
0
+ property :meta_description, Text
0
+ property :meta_keywords, Text
0
+ property :created_at, DateTime
0
+ property :published_at, DateTime
0
+ property :published, Boolean, :default => true
0
+ property :formatter, String, :default => "default"
0
 
0
- validates_presence_of :user_id, :key => "uniq_user_id"
0
- validates_presence_of :title, :key => "uniq_title"
0
- validates_presence_of :permalink, :key => "uniq_permalink"
0
- validates_uniqueness_of :title
0
+ validates_present :user_id, :key => "uniq_user_id"
0
+ validates_present :title, :key => "uniq_title"
0
+ validates_present :permalink, :key => "uniq_permalink"
0
+ validates_is_unique :title
0
 
0
   belongs_to :user
0
- belongs_to :parent, :class => "Page"
0
- has_many :children, :class => "Page", :foreign_key => "parent_id", :order => "position"
0
- has_many :children_nav, :class => "Page", :foreign_key => "parent_id", :order => "position", :conditions => {:display_in_nav => true}
0
+ belongs_to :parent, :class_name => "Page"
0
+ has n, :children, :class_name => "Page", :child_key => [:parent_id], :order => [:position.desc]
0
+ has n, :children_nav, :class_name => "Page", :child_key => [:parent_id], :order => [:position.desc], :display_in_nav => true
0
   
0
- before_validation :set_published_permalink
0
+ before :save, :set_published_permalink
0
   
0
   def set_published_permalink
0
     # Set the permalink, only if we haven't already
0
     self.permalink = title.downcase.gsub(/[^a-z0-9]+/i, '-') if permalink.blank?
0
- if self.is_published?
0
+ if self.published
0
       # Set the date, only if we haven't already
0
       self.published_at = Time.now if self.published_at.nil?
0
     end
0
   end
0
   
0
- def is_published?
0
- # We need this because the values get populated from the params
0
- self.published == "1"
0
- end
0
-
0
   def link
0
     "/page/#{permalink}"
0
   end
0
   
0
   protected
0
   def self.published_pages_and_in_nav
0
- all(:conditions => ['published = 1 AND published_at <= ? AND parent_id = 0 AND display_in_nav = 1', Time.now.utc], :order => "position")
0
+ self.all(:published => true, :published_at.lte => Time.now.utc, :parent_id => 0, :display_in_nav => true, :order => [:position.asc])
0
   end
0
-
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.