public
Description: Simple blog system for my personal blog, to be used in combination with Cubicphuse's other 'to' applications.
Clone URL: git://github.com/ludo/to-publish.git
Add MerbAuth slice
ludo (author)
Sun Jul 20 13:48:40 -0700 2008
commit  755eb3511c143fd634f71947a176a523f0a19c81
tree    5e05c23e621cb8e518abaf106afc65b23a7a1ee0
parent  88439b9925bee5fe4c0141e7bc103438880c81ac
...
3
4
5
6
7
 
 
8
9
10
...
16
17
18
19
 
20
21
22
23
24
25
 
26
27
28
...
31
32
33
34
 
35
36
37
...
41
42
43
44
 
45
46
47
...
51
52
53
54
 
...
3
4
5
 
 
6
7
8
9
10
...
16
17
18
 
19
20
21
22
23
24
 
25
26
27
28
...
31
32
33
 
34
35
36
37
...
41
42
43
 
44
45
46
47
...
51
52
53
 
54
0
@@ -3,8 +3,8 @@ module Admin
0
     # provides :xml, :yaml, :js
0
 
0
     def index
0
- @published_articles = Article.all(:published_at.not => nil, :order => [:published_at.desc])
0
- @unpublished_articles = Article.all(:published_at => nil, :order => [:created_at.desc])
0
+ @published_articles = current_user.articles.all(:published_at.not => nil, :order => [:published_at.desc])
0
+ @unpublished_articles = current_user.articles.all(:published_at => nil, :order => [:created_at.desc])
0
       render
0
     end
0
 
0
@@ -16,13 +16,13 @@ module Admin
0
 
0
     def edit
0
       only_provides :html
0
- @article = Article.get(params[:id])
0
+ @article = current_user.articles.get(params[:id])
0
       raise NotFound unless @article
0
       render
0
     end
0
 
0
     def create
0
- @article = Article.new(params[:article])
0
+ @article = Article.new(params[:article].merge(:user_id => current_user.id))
0
       if @article.save
0
         redirect url(:admin_articles)
0
       else
0
@@ -31,7 +31,7 @@ module Admin
0
     end
0
 
0
     def update
0
- @article = Article.get(params[:id])
0
+ @article = current_user.articles.get(params[:id])
0
       raise NotFound unless @article
0
       if @article.update_attributes(params[:article]) || !@article.dirty?
0
         redirect url(:admin_articles)
0
@@ -41,7 +41,7 @@ module Admin
0
     end
0
 
0
     def destroy
0
- @article = Article.get(params[:id])
0
+ @article = current_user.articles.get(params[:id])
0
       raise NotFound unless @article
0
       if @article.destroy
0
         redirect url(:admin_article)
0
@@ -51,4 +51,4 @@ module Admin
0
     end
0
 
0
   end
0
-end # Admin
0
+end
...
1
2
3
4
 
5
6
7
...
1
2
3
 
4
5
6
7
0
@@ -1,6 +1,6 @@
0
 module Admin
0
   class Base < Application
0
     layout :admin
0
-# before :login_required
0
+ before :login_required
0
   end
0
 end
0
\ No newline at end of file
...
16
17
18
19
20
 
 
21
22
23
...
16
17
18
 
 
19
20
21
22
23
0
@@ -16,8 +16,8 @@ module Merb
0
     # @api public
0
     def prepare(article)
0
       body = article.body
0
- body.gsub!('<post.timestamp>', "<div class='date'>#{article.published_at.strftime("%B #{article.published_at.day.ordinalize}, %Y")}</div>")
0
- body.gsub!('<post.title>', "<h1>#{link_to_article(article)}</h1>")
0
+ body.gsub!('<article.timestamp>', "<div class='date'>#{article.published_at.strftime("%B #{article.published_at.day.ordinalize}, %Y")}</div>")
0
+ body.gsub!('<article.title>', "<h1>#{link_to_article(article)}</h1>")
0
       body
0
     end
0
     
...
10
11
12
 
13
14
 
15
16
17
...
19
20
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
23
24
...
10
11
12
13
14
15
16
17
18
19
...
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
0
@@ -10,8 +10,10 @@ class Article
0
   property :published_at, DateTime
0
   property :created_at, DateTime
0
   property :updated_at, DateTime
0
+ property :user_id, Integer, :nullable => false
0
   
0
   # === Associations
0
+ belongs_to :user
0
   has n, :comments
0
   
0
   # === Callbacks
0
@@ -19,6 +21,21 @@ class Article
0
   
0
   # === Instance Methods
0
   
0
+ # Set +published_at+
0
+ #
0
+ # Verify whether <tt>value</tt> is a <tt>Date</tt>. If this is not the case then
0
+ # <tt>value</tt> will be set to <tt>nil</tt>.
0
+ #
0
+ # ==== Paramaters
0
+ # value<String>:: Date on which this article should be published
0
+ #
0
+ # --
0
+ # @api public
0
+ def published_at=(value)
0
+ value = nil if value.instance_of?(String) && value.length == 0
0
+ attribute_set(:published_at, value)
0
+ end
0
+
0
   # Set a slug to use in URIs
0
   #
0
   # If no user-defined slug is given, then the slug will be generated based on
...
1
2
3
 
4
5
6
7
...
1
2
 
3
4
5
6
7
0
@@ -1,6 +1,6 @@
0
 %li{:id => "article-#{article.id}"}
0
   = article
0
- %small.due= article.published_at.strftime("%B %e, %Y") if article.published_at
0
+ %small.due= article.published_at.strftime("%B #{article.published_at.day.ordinalize}, %Y") if article.published_at
0
   %small{:id => "edit-article-#{article.id}", :class => "hidden"}
0
     = link_to "edit", url(:edit_admin_article, article)
0
     = delete_button :admin_article, article, "delete", :class => "delete_button"
0
\ No newline at end of file
...
11
12
13
14
15
16
17
 
18
19
20
21
22
 
 
 
23
24
25
26
27
 
28
29
30
...
11
12
13
 
 
 
 
14
15
16
17
 
 
18
19
20
21
22
23
24
 
25
26
27
28
0
@@ -11,20 +11,18 @@
0
   %body
0
     #auth
0
       .container
0
- %ul
0
- %li= link_to "log out", url(:admin_root)
0
- /%li= link_to "settings", url(:sizes)
0
- %li= link_to "website", url(:root)
0
+ %ul= partial "layout/auth"
0
         %br{:style => "clear: both;"}
0
     .container
0
       #header
0
- /#user.right= current_user.login
0
- /%img.right.avatar{:src => "https://secure.gravatar.com/avatar/64082d83db14dd06252607325df8679c?s=40"}
0
+ - if logged_in?
0
+ #user.right= current_user.login
0
+ /%img.right.avatar{:src => "https://secure.gravatar.com/avatar/64082d83db14dd06252607325df8679c?s=40"}
0
         %h1
0
           to
0
           = link_to "publish", url(:admin_root)
0
       #nav
0
- = render_menu
0
+ = render_menu if logged_in?
0
         %br{:style => "clear: both;"}
0
       #main= catch_content :for_layout
0
       #footer
...
55
56
57
58
 
59
60
61
 
 
 
 
62
63
64
65
66
67
68
69
 
 
 
70
71
72
...
55
56
57
 
58
59
 
60
61
62
63
64
65
66
67
68
69
 
 
 
70
71
72
73
74
75
0
@@ -55,18 +55,21 @@ Merb.push_path(:lib, Merb.root / "lib") # uses **/*.rb as path glob.
0
 # OR
0
 # dependencies "RedCloth" => "> 3.0", "ruby-aes-cext" => "= 1.0"
0
 dependency "merb-assets"
0
-#dependency "merb-auth"
0
+dependency "merb-cache"
0
 dependency "merb-haml"
0
-dependency "merb_helpers"
0
 dependency "merb-jquery"
0
+dependency "merb-slices"
0
+
0
+dependency "merb-auth"
0
+dependency "merb_helpers"
0
 
0
 dependency "dm-aggregates"
0
 dependency "dm-timestamps"
0
 dependency "dm-validations"
0
 
0
-#Merb::BootLoader.before_app_loads do
0
-# Merb::Slices::config[:merb_auth][:layout] = :application
0
-#end
0
+Merb::BootLoader.before_app_loads do
0
+ Merb::Slices::config[:merb_auth][:layout] = :admin
0
+end
0
 
0
 Merb::BootLoader.after_app_loads do
0
   # Add dependencies here that must load after the application loads:
...
21
22
23
24
 
25
26
27
28
29
30
 
 
31
32
33
34
35
36
 
 
37
38
39
40
 
41
42
43
...
62
63
64
65
66
 
 
67
68
69
...
21
22
23
 
24
25
26
27
28
 
 
29
30
31
32
33
34
 
 
35
36
37
38
39
 
40
41
42
43
...
62
63
64
 
 
65
66
67
68
69
0
@@ -21,23 +21,23 @@
0
 
0
 Merb.logger.info("Compiling routes...")
0
 Merb::Router.prepare do |r|
0
- # r.add_slice :MerbAuth, :path => '', :default_routes => false
0
+ r.add_slice :MerbAuth, :path => "", :default_routes => false
0
 
0
   # Admin interface
0
   r.namespace :admin do |admin|
0
     admin.resources :articles
0
- admin.match('').
0
- to(:controller => 'articles', :action => 'index').
0
+ admin.match("").
0
+ to(:controller => "articles", :action => "index").
0
       name(:admin_root)
0
   end
0
 
0
   # Create a comment
0
- r.match('/comments').
0
- to(:controller => 'comments', :action => 'create').
0
+ r.match("/comments").
0
+ to(:controller => "comments", :action => "create").
0
     name(:comment)
0
       
0
   # Articles Archive
0
- r.match('/archive').
0
+ r.match("/archive").
0
     to(:controller => "articles", :action => "archive").
0
     name(:articles_archive)
0
       
0
@@ -62,7 +62,7 @@ Merb::Router.prepare do |r|
0
     name(:article)
0
       
0
   # Homepage
0
- r.match('/').
0
- to(:controller => 'articles', :action =>'index').
0
+ r.match("/").
0
+ to(:controller => "articles", :action => "index").
0
     name(:root)
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.