public
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/halorgium/mephisto.git
Search Repo:
host of fixes and added support for comment preview
technoweenie (author)
Mon Feb 04 09:21:51 -0800 2008
commit  b0fadcd7955634ef0fc82c18a8b769c7d9cb89d4
tree    12a89c5278097f788f6b742fb22a91e21f3bb9cc
parent  963b29301a8e3c6b62557848575422dbad4a9245
...
62
63
64
 
65
66
67
...
62
63
64
65
66
67
68
0
@@ -62,6 +62,7 @@
0
 
0
   def destroy
0
     @article.destroy
0
+ flash[:notice] = "The article: #{@article.title.inspect} was deleted."
0
     render :update do |page|
0
       page.redirect_to :action => 'index'
0
     end
...
55
56
57
 
 
58
59
60
...
55
56
57
58
59
60
61
62
0
@@ -55,6 +55,8 @@
0
       show_article_with 'errors' => @comment.errors.full_messages, 'submitted' => params[:comment]
0
     rescue Article::CommentNotAllowed
0
       show_article_with 'errors' => ["Commenting has been disabled on this article"]
0
+ rescue Comment::Previewing
0
+ show_article_with 'errors' => ["Previewing your comment"], 'submitted' => params[:comment]
0
     end
0
     
0
     def dispatch_comment
...
19
20
21
22
 
23
24
25
...
19
20
21
 
22
23
24
25
0
@@ -19,7 +19,7 @@
0
   end
0
 
0
   def comments
0
- @comments ||= liquify(*@source.comments.reject(&:new_record?))
0
+ @comments ||= liquify(*@source.comments) # .reject(&:new_record?) <-- show new comments as they're built as a preview
0
   end
0
   
0
   def sections
...
19
20
21
 
 
 
 
22
23
24
...
19
20
21
22
23
24
25
26
27
28
0
@@ -19,6 +19,10 @@
0
     @url ||= absolute_url(@source.site.permalink_for(@source))
0
   end
0
 
0
+ def new_record
0
+ @source.new_record?
0
+ end
0
+
0
   def author_link
0
     @source.author_url.blank? ? "<span>#{@source.author}</span>" : %Q{<a href="#{author_url}">#{@source.author}</a>}
0
   end
...
12
13
14
15
 
16
 
 
 
 
 
 
 
 
 
 
17
18
19
...
80
81
82
83
 
84
85
86
...
12
13
14
 
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
...
90
91
92
 
93
94
95
96
0
@@ -12,8 +12,18 @@
0
   before_destroy :decrement_counter_cache
0
   belongs_to :article
0
   has_one :event, :dependent => :destroy
0
- attr_accessible :article, :article_id, :user_id, :user, :excerpt, :body, :author, :author_url, :author_email, :author_ip, :updater_id, :updater, :comment_age, :user_agent, :referrer
0
+ before_create :check_if_previewing
0
 
0
+ attr_accessible :article, :article_id, :user_id, :user, :excerpt, :body, :author, :author_url, :author_email, :author_ip, :updater_id, :updater, :comment_age, :user_agent, :referrer, :preview
0
+ attr_accessor :preview
0
+ class Previewing < StandardError; end
0
+
0
+ # If the view sends the "preview" accessor, we raise this
0
+ # error so the controller can simply rescue
0
+ def check_if_previewing
0
+ raise Comment::Previewing if preview
0
+ end
0
+
0
   def self.find_all_by_section(section, options = {})
0
     find :all, options.update(:conditions => ['contents.approved = ? and assigned_sections.section_id = ?', true, section.id],
0
       :select => 'contents.*', :joins => 'INNER JOIN assigned_sections ON assigned_sections.article_id = contents.article_id',
0
@@ -80,7 +90,7 @@
0
     end
0
 
0
     def check_comment_expiration
0
- raise Article::CommentNotAllowed unless article.accept_comments?
0
+ raise Article::CommentNotAllowed, "#{article.status} does not allow comments" unless article.accept_comments?
0
     end
0
 
0
     def update_counter_cache
...
44
45
46
 
 
47
 
48
49
50
...
44
45
46
47
48
49
50
51
52
53
0
@@ -44,7 +44,10 @@
0
             <li><%= link_to 'Sections', :controller => '/admin/sections' %></li>
0
             <li><%= link_to 'Design', :controller => '/admin/design' %></li>
0
             <li><%= link_to "Users", :controller => "users" %></li>
0
+ <% if false -%>
0
+ hidden because plugins are in for a change
0
             <li><%= link_to 'Plugins', :controller => '/admin/plugins' %></li>
0
+ <% end -%>
0
           <% Mephisto::Plugin.admin_tabs.each do |tab| -%>
0
             <li><%= link_to tab.first.to_s.tableize.humanize, tab.last %></li>
0
           <% end -%>
...
9
10
11
 
 
12
13
14
...
9
10
11
12
13
14
15
16
0
@@ -9,6 +9,8 @@
0
         Thread.current[:comment_form_article] = value
0
       end
0
     
0
+ # Provides the required input, error, and form fields
0
+ # TODO: make this more accessible to users (let them mess it up, rather than forcing a structure on them)
0
       def render(context)
0
         return '' unless self.class.article.accept_comments?
0
         result = []
...
19
20
21
22
 
23
24
25
...
19
20
21
 
22
23
24
25
0
@@ -19,7 +19,7 @@
0
       map.purge 'admin/articles/comments/purge', :controller => 'admin/comments', :action => 'destroy'
0
 
0
       map.resources :articles, :path_prefix => 'admin', :controller => 'admin/articles' do |r|
0
- r.resources :comments, :controller => 'admin/comments', :member => { :unapprove => :post, :approve => :post, :edit => :gett }
0
+ r.resources :comments, :controller => 'admin/comments', :member => { :unapprove => :post, :approve => :post, :edit => :get, :preview => :post }
0
       end
0
 
0
       map.overview 'admin/overview.xml', :controller => 'admin/overview', :action => 'feed'
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
53
0
@@ -1 +1,54 @@
0
+require File.dirname(__FILE__) + '/../spec_helper'
0
+
0
+
0
+describe Comment, "previewing" do
0
+ define_models do
0
+ time 2007, 6, 15
0
+
0
+ model Site do
0
+ stub :cupcake, :title => "Cupcake", :host => 'cupcake.com'
0
+ end
0
+ model Article do
0
+ stub :welcome, :title => "Welcome!", :body => "Hi there", :filter => "textile_filter", :site => all_stubs(:site), :created_at => current_time - 3.days, :published_at => current_time - 2.days, :comment_age => 0
0
+ end
0
+ end
0
+
0
+ before do
0
+ @comment = Comment.new :author => "1", :author_ip => "127.0.0.1", :body => "No answer"
0
+ @comment.article = contents(:welcome)
0
+ end
0
+
0
+ it "should be valid" do
0
+ @comment.should be_valid
0
+ end
0
+
0
+ it "raises Previewing error when preview accessor is set" do
0
+ @comment.preview = true
0
+ lambda{
0
+ @comment.save!
0
+ }.should raise_error(Comment::Previewing)
0
+ end
0
+
0
+end
0
+
0
+describe Comment, "textilizing" do
0
+ define_models do
0
+ model Site do
0
+ stub :cupcake, :title => "Cupcake", :host => 'cupcake.com'
0
+ end
0
+ model Article do
0
+ stub :welcome, :title => "Welcome!", :body => "Hi there", :filter => "textile_filter", :site => all_stubs(:site), :created_at => current_time - 3.days, :published_at => current_time - 2.days, :comment_age => 0
0
+ end
0
+ end
0
+
0
+ # Copied from tests, in the hope that more people will PDI and convert the test::unit
0
+ # tests to RSpec.
0
+ it "processes comments with textile, if the article is textile-formatted" do
0
+ @comment = Comment.new :author => "1", :author_ip => "127.0.0.1", :body => "*test* comment"
0
+ @comment.article = contents(:welcome)
0
+ @comment.save
0
+ @comment.body_html.should == "<p><strong>test</strong> comment</p>"
0
+ end
0
+
0
+end

Comments

    No one has commented yet.