jabe 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,9 @@
1
1
  h1. Just Another Blog Engine
2
2
 
3
+ h2. Status
4
+
5
+ "!https://codeclimate.com/badge.png!":https://codeclimate.com/github/pixels-and-bits/jabe
6
+
3
7
  h3. What is this?
4
8
 
5
9
  JABE is a bare bones blogging engine that is installed as a gem. It will grow as its needs do.
@@ -13,6 +17,7 @@ Edit your Gemfile and add the required gems
13
17
  <pre><code>gem 'devise', '>= 2.0.0'
14
18
  gem 'friendly_id', '>= 4.0.0'
15
19
  gem 'kaminari', '>= 0.13.0'
20
+ gem 'sanitize', '>= 2.0.0'
16
21
  </code></pre>
17
22
 
18
23
  From your rails root
@@ -62,4 +67,6 @@ Create a new migration to handle the database changes.
62
67
  h2. TODO
63
68
 
64
69
  * Migrate generators
65
- * Switch from boilerplate to Twitter Bootstrap?
70
+ * Integrate Akismet
71
+ * Add a comment moderation queue?
72
+
data/Rakefile CHANGED
@@ -27,5 +27,9 @@ Bundler::GemHelper.install_tasks
27
27
 
28
28
  task :default do
29
29
  # NOTE: There has to be a better way to do this
30
- exit system("bundle exec cucumber features")
30
+ Dir.chdir('test/dummy') do
31
+ FileUtils.rm(%w(db/dev.sqlite3)) rescue Errno::ENOENT
32
+ FileUtils.rm(%w(db/test.sqlite3)) rescue Errno::ENOENT
33
+ exit system("bundle exec rake db:migrate db:test:prepare && bundle exec cucumber features")
34
+ end
31
35
  end
@@ -9,6 +9,19 @@ $(function() {
9
9
  }
10
10
 
11
11
  $('.dropdown-toggle').dropdown()
12
+
13
+ $('.comment_delete').click(function() {
14
+ var elem = $(this)
15
+ if (confirm(elem.data('confirm'))) {
16
+ $.ajax({
17
+ url: elem.attr('href'),
18
+ type: 'DELETE'
19
+ }).success(function() {
20
+ elem.closest('.comment').fadeOut()
21
+ })
22
+ }
23
+ return false
24
+ })
12
25
  });
13
26
 
14
27
  var JABE = function() {
@@ -2,7 +2,7 @@ module Jabe
2
2
  class Admin::SettingsController < Admin::BaseController
3
3
 
4
4
  def update
5
- if Jabe::SETTINGS.update_attributes(params[:settings])
5
+ if Jabe::SETTINGS.update_attributes(params[:settings])
6
6
  Jabe::SETTINGS.do_updates
7
7
  redirect_to admin_root_path, :notice => 'Settings updated.'
8
8
  else
@@ -1,13 +1,17 @@
1
1
  module Jabe
2
2
  class CommentsController < Admin::BaseController
3
+ include PublicEntryUrl
4
+
3
5
  layout 'application'
4
6
  skip_before_filter :authenticate_admin!, :only => [ :create, :new ]
5
7
  helper_method :entry, :comment
6
8
 
7
9
  def create
10
+ comment.request = request
11
+ comment.permalink = public_entry_url(entry)
12
+
8
13
  if comment.save
9
- comment.send_notification(request)
10
- redirect_to entry_path(entry), :notice => 'Your comment was submitted.'
14
+ redirect_to public_entry_url(entry), :notice => 'Your comment was submitted.'
11
15
  else
12
16
  flash[:error] = 'Unable to submit your comment.'
13
17
  render 'entries/show'
@@ -16,7 +20,12 @@ module Jabe
16
20
 
17
21
  def destroy
18
22
  comment.destroy
19
- redirect_to entry_path(entry), :notice => 'Comment was deleted.'
23
+
24
+ if request.xhr?
25
+ render :nothing => true
26
+ else
27
+ redirect_to entry_path(entry), :notice => 'Comment was deleted.'
28
+ end
20
29
  end
21
30
 
22
31
  private
@@ -1,13 +1,13 @@
1
1
  module Jabe
2
2
  class CommentMailer < ActionMailer::Base
3
- def notification(comment, request)
4
- @comment = comment
5
- @request = request
3
+ include PublicEntryUrl
6
4
 
7
- from Jabe::SETTINGS.mail_from || 'edit-me-in-settings@example.com'
5
+ def notification(comment)
6
+ @comment = comment
8
7
 
9
8
  mail(:to => Admin.all.map(&:email),
10
- :subject => "Comment on: #{comment.entry.title}"
9
+ :subject => "Comment on: #{comment.entry.title}",
10
+ :from => Jabe::SETTINGS.mail_from || 'edit-me-in-settings@example.com'
11
11
  )
12
12
  end
13
13
  end
@@ -1,23 +1,29 @@
1
1
  module Jabe
2
2
  class Comment < ActiveRecord::Base
3
+ include Rakismet::Model
4
+ include PublicEntryUrl
5
+
3
6
  if defined?(Gravtastic)
4
7
  include Gravtastic
5
- is_gravtastic :size => 64
8
+ gravtastic :author_email, :size => 64
6
9
  end
7
10
 
8
- attr_accessor :nickname
11
+ attr_accessor :nickname, :request
9
12
 
10
13
  belongs_to :entry
11
- default_scope :order => 'created_at ASC'
14
+ default_scope :conditions => { :spam => false }, :order => 'created_at ASC'
15
+ scope :spam, :conditions => { :spam => true }
16
+
17
+ before_validation :bot_check, :check_akismet, :sanitize
18
+ validates_presence_of :author, :author_email, :content, :message => 'Required'
12
19
 
13
- before_validation :bot_check
14
- validates_presence_of :name, :email, :body, :message => 'Required'
20
+ after_create :send_notification
15
21
 
16
- acts_as_textiled :body
22
+ acts_as_textiled :content
17
23
 
18
- def send_notification(request)
24
+ def send_notification
19
25
  begin
20
- CommentMailer.notification(self, request).deliver
26
+ CommentMailer.notification(self).deliver
21
27
  rescue => e
22
28
  logger.error "#{e}\n#{e.backtrace.join("\n")}"
23
29
  end
@@ -28,8 +34,23 @@ module Jabe
28
34
  def bot_check
29
35
  unless self.nickname.blank?
30
36
  errors.add(:nickname, 'You shouldn\'t have seen this...')
31
- false
37
+ return false
32
38
  end
33
39
  end
40
+
41
+ def check_akismet
42
+ self.user_ip = request.remote_ip
43
+ self.user_agent = request.env['HTTP_USER_AGENT']
44
+ self.referrer = request.env['HTTP_REFERER']
45
+ self.spam = spam?
46
+ true
47
+ end
48
+
49
+ def sanitize
50
+ self.author_email = Sanitize.clean(author_email)
51
+ self.author_url = Sanitize.clean(author_url)
52
+ self.content = Sanitize.clean(content)
53
+ true
54
+ end
34
55
  end
35
- end
56
+ end
@@ -3,12 +3,14 @@ module Jabe
3
3
  def do_updates
4
4
  Time.zone = self.time_zone
5
5
  ActionMailer::Base.default_url_options[:host] = self.host_name
6
+ Rakismet.key = self.akismet_key rescue nil
7
+ Rakismet.url = self.akismet_url rescue nil
6
8
  end
7
9
  end
8
10
 
9
- # begin
11
+ begin
10
12
  SETTINGS = Settings.first || Settings.create
11
13
  SETTINGS.do_updates
12
- # rescue ActiveRecord::StatementInvalid
13
- # end
14
+ rescue ActiveRecord::StatementInvalid
15
+ end
14
16
  end
@@ -43,6 +43,14 @@
43
43
  <%= form.label :google_tracker_id %>
44
44
  <%= form.text_field :google_tracker_id, :input_html => { :class => "span7" } %>
45
45
 
46
+ <%= form.label :akismet_key, 'Akismet Key (leave blank to skip Akismet)' %>
47
+ <%= form.text_field :akismet_key, :input_html => { :class => "span7" } %>
48
+
49
+ <% Jabe::SETTINGS.akismet_url ||= root_url %>
50
+
51
+ <%= form.label :akismet_url, 'Akismet URL' %>
52
+ <%= form.text_field :akismet_url, :input_html => { :class => "span7" } %>
53
+
46
54
  <br><br>
47
55
 
48
56
  <%= form.submit 'Save', :class => 'btn btn-success' %>
@@ -1,19 +1,25 @@
1
1
  <p>
2
- From: <%= @comment.name %>
2
+ On: <%= public_entry_url(@comment.entry) %>
3
3
  </p>
4
4
  <p>
5
- Email: <%= @comment.email %>
5
+ SPAM: <%= @comment.spam? %>
6
6
  </p>
7
7
  <p>
8
- URL: <%= @comment.url %>
8
+ From: <%= @comment.author %>
9
9
  </p>
10
10
  <p>
11
- <%= @comment.body.html_safe %>
11
+ Email: <%= @comment.author_email %>
12
+ </p>
13
+ <p>
14
+ URL: <%= @comment.author_url %>
15
+ </p>
16
+ <p>
17
+ <%= @comment.content.html_safe %>
12
18
  </p>
13
19
  <hr>
14
20
  <p>
15
- Remote IP: <%= @request.remote_ip %>
21
+ Remote IP: <%= @comment.user_ip %>
16
22
  </p>
17
23
  <p>
18
- User agent: <%= @request.user_agent %>
24
+ User agent: <%= @comment.user_agent %>
19
25
  </p>
@@ -24,7 +24,12 @@
24
24
  <div class="comment">
25
25
  <% if admin_signed_in? %>
26
26
  <div class="delete">
27
- <%= link_to image_tag('jabe/delete.png'), entry_comment_path(entry, comment), :confirm => 'Are you sure?', :method => :delete %>
27
+ <%= link_to image_tag('jabe/delete.png'),
28
+ entry_comment_path(entry, comment),
29
+ :confirm => 'Are you sure?',
30
+ :method => :delete,
31
+ :class => 'comment_delete'
32
+ %>
28
33
  </div>
29
34
  <% end %>
30
35
 
@@ -35,13 +40,13 @@
35
40
  <% end %>
36
41
 
37
42
  <div class="author">
38
- <%= comment.name %>
43
+ <%= comment.author %>
39
44
  <span class="when">
40
45
  <%= comment.created_at.to_s(:long) %>
41
46
  </span>
42
47
  </div>
43
48
  <div class="body">
44
- <%= comment.body.html_safe %>
49
+ <%= comment.content.html_safe %>
45
50
  </div>
46
51
  </div>
47
52
  <% end %>
@@ -60,20 +65,20 @@
60
65
  <div id="new_comment">
61
66
  <h4>Add a comment</h4>
62
67
  <%= form_for [entry, comment] do |form| %>
63
- <%= form.label :name %>
64
- <%= form.text_field :name %>
68
+ <%= form.label :author, 'Name' %>
69
+ <%= form.text_field :author %>
65
70
 
66
71
  <%= form.label :nickname %>
67
72
  <%= form.text_field :nickname %>
68
73
 
69
- <%= form.label :email %>
70
- <%= form.text_field :email, :label => 'Email (not shown to the public)' %>
74
+ <%= form.label :author_email, 'Email (not shown to the public)' %>
75
+ <%= form.text_field :author_email %>
71
76
 
72
- <%= form.label :url, 'Website' %>
73
- <%= form.text_field :url %>
77
+ <%= form.label :author_url, 'Website' %>
78
+ <%= form.text_field :author_url %>
74
79
 
75
- <%= form.label :body, "Comment - Textile enabled (#{link_to 'Reference', 'http://redcloth.org/try-redcloth/', :target => '_blank'})".html_safe %>
76
- <%= form.text_area :body %>
80
+ <%= form.label :content, "Comment - Textile enabled (#{link_to 'Reference', 'http://redcloth.org/try-redcloth/', :target => '_blank'})".html_safe %>
81
+ <%= form.text_area :content %>
77
82
 
78
83
  <br>
79
84
 
@@ -2,9 +2,7 @@
2
2
  <% if flash[message_type] %>
3
3
  <div class="<%= "alert alert-#{message_type} fade in" %>">
4
4
  <%= link_to '&times;'.html_safe, '#', :class => 'close' %>
5
- <p>
6
- <%= flash[message_type] %>
7
- </p>
5
+ <%= flash[message_type] %>
8
6
  </div>
9
7
  <% end %>
10
8
  <% end %>
@@ -54,7 +54,7 @@
54
54
 
55
55
  <% unless Jabe::SETTINGS.twitter_username.blank? %>
56
56
  <li>
57
- <%= link_to 'Twitter', "https://twitter.com/#!/#{Jabe::SETTINGS.twitter_username}" %>
57
+ <%= link_to 'Twitter', "https://twitter.com/#{Jabe::SETTINGS.twitter_username}" %>
58
58
  </li>
59
59
  <% end %>
60
60
 
@@ -1,23 +1,21 @@
1
1
  class DeviseCreateAdmins < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table(:jabe_admins) do |t|
4
- t.database_authenticatable :null => false
5
- t.recoverable
6
- t.rememberable
7
- t.trackable
8
-
9
- # t.confirmable
10
- # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
11
- # t.token_authenticatable
12
-
13
-
4
+ t.string :email, :null => false, :default => ""
5
+ t.string :encrypted_password, :null => false, :default => ""
6
+ t.string :reset_password_token
7
+ t.datetime :reset_password_sent_at
8
+ t.datetime :remember_created_at
9
+ t.integer :sign_in_count, :default => 0
10
+ t.datetime :current_sign_in_at
11
+ t.datetime :last_sign_in_at
12
+ t.string :current_sign_in_ip
13
+ t.string :last_sign_in_ip
14
14
  t.timestamps
15
15
  end
16
16
 
17
17
  add_index :jabe_admins, :email, :unique => true
18
18
  add_index :jabe_admins, :reset_password_token, :unique => true
19
- # add_index :jabe_admins, :confirmation_token, :unique => true
20
- # add_index :jabe_admins, :unlock_token, :unique => true
21
19
  end
22
20
 
23
21
  def self.down
@@ -0,0 +1,32 @@
1
+ class AkismetifyComments < ActiveRecord::Migration
2
+ def up
3
+ rename_column :jabe_comments, :name, :author
4
+ rename_column :jabe_comments, :email, :author_email
5
+ rename_column :jabe_comments, :url, :author_url
6
+ rename_column :jabe_comments, :body, :content
7
+ add_column :jabe_comments, :permalink, :string
8
+ add_column :jabe_comments, :user_ip, :string
9
+ add_column :jabe_comments, :user_agent, :string
10
+ add_column :jabe_comments, :referrer, :string
11
+ add_column :jabe_comments, :spam, :boolean
12
+
13
+ add_column :jabe_settings, :akismet_key, :string
14
+ add_column :jabe_settings, :akismet_url, :string
15
+ end
16
+
17
+ def down
18
+ remove_column :jabe_settings, :akismet_key
19
+ remove_column :jabe_settings, :akismet_url
20
+
21
+ remove_column :jabe_comments, :permalink
22
+ remove_column :jabe_comments, :user_ip
23
+ remove_column :jabe_comments, :user_agent
24
+ remove_column :jabe_comments, :referrer
25
+ remove_column :jabe_comments, :spam
26
+
27
+ rename_column :jabe_comments, :author, :name
28
+ rename_column :jabe_comments, :author_email, :email
29
+ rename_column :jabe_comments, :author_url, :url
30
+ rename_column :jabe_comments, :content, :body
31
+ end
32
+ end
@@ -8,7 +8,7 @@ module Jabe
8
8
  end
9
9
 
10
10
  def public_entry_url(entry)
11
- "//#{SETTINGS.host_name}#{root_path}#{entry.published_at.in_time_zone.to_s(:url_part)}/#{entry.to_param}"
11
+ "http://#{SETTINGS.host_name}#{root_path}#{entry.published_at.in_time_zone.to_s(:url_part)}/#{entry.to_param}"
12
12
  end
13
13
  end
14
14
 
@@ -1,3 +1,3 @@
1
1
  module Jabe
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jabe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-05 00:00:00.000000000 Z
13
+ date: 2013-01-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -108,6 +108,38 @@ dependencies:
108
108
  - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: 4.2.9
111
+ - !ruby/object:Gem::Dependency
112
+ name: sanitize
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: 2.0.0
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: 2.0.0
127
+ - !ruby/object:Gem::Dependency
128
+ name: rakismet
129
+ requirement: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - '='
133
+ - !ruby/object:Gem::Version
134
+ version: 1.3.0
135
+ type: :runtime
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - '='
141
+ - !ruby/object:Gem::Version
142
+ version: 1.3.0
111
143
  - !ruby/object:Gem::Dependency
112
144
  name: sqlite3
113
145
  requirement: !ruby/object:Gem::Requirement
@@ -190,6 +222,7 @@ files:
190
222
  - db/migrate/20101230010436_devise_create_admins.rb
191
223
  - db/migrate/20101230010437_create_entries.rb
192
224
  - db/migrate/20101230010438_create_comments.rb
225
+ - db/migrate/20121017015058_akismetify_comments.rb
193
226
  - lib/acts_as_textiled/base.rb
194
227
  - lib/jabe/engine.rb
195
228
  - lib/jabe/version.rb
@@ -213,7 +246,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
246
  version: '0'
214
247
  segments:
215
248
  - 0
216
- hash: -520388874793192525
249
+ hash: -2851312894657140189
217
250
  required_rubygems_version: !ruby/object:Gem::Requirement
218
251
  none: false
219
252
  requirements:
@@ -222,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
255
  version: '0'
223
256
  segments:
224
257
  - 0
225
- hash: -520388874793192525
258
+ hash: -2851312894657140189
226
259
  requirements: []
227
260
  rubyforge_project:
228
261
  rubygems_version: 1.8.23