blogit 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/README.md +5 -20
  2. data/app/controllers/blogit/posts_controller.rb +22 -0
  3. data/app/models/blogit/post.rb +1 -1
  4. data/app/views/blogit/posts/_form.html.erb +1 -1
  5. data/app/views/blogit/posts/index.rss.builder +10 -10
  6. data/config/routes.rb +4 -4
  7. data/lib/blogit.rb +1 -0
  8. data/lib/blogit/configuration.rb +10 -5
  9. data/lib/blogit/version.rb +1 -1
  10. data/lib/generators/templates/blogit.rb +9 -3
  11. data/spec/controllers/blogit/posts_controller_spec.rb +72 -0
  12. data/spec/dummy/app/views/layouts/application.html.erb +1 -1
  13. data/spec/dummy/config/initializers/blogit.rb +49 -20
  14. data/spec/dummy/db/development.sqlite3 +0 -0
  15. data/spec/dummy/db/schema.rb +9 -9
  16. data/spec/dummy/db/test.sqlite3 +0 -0
  17. data/spec/dummy/log/development.log +1094 -804
  18. data/spec/dummy/log/test.log +24187 -2415
  19. data/spec/dummy/tmp/cache/assets/CB5/DD0/sprockets%2F346324d2a51df58457807bee661c449c +0 -0
  20. data/spec/dummy/tmp/cache/assets/CB6/ED0/sprockets%2F4390d06699f3ad4262e342be530f9f91 +0 -0
  21. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  22. data/spec/dummy/tmp/cache/assets/CE7/230/sprockets%2F6f493a817d97133a8dbf674bcd322670 +0 -0
  23. data/spec/dummy/tmp/cache/assets/CEE/310/sprockets%2F89642af8492e579dcd7162a0e2b7f155 +0 -0
  24. data/spec/dummy/tmp/cache/assets/D01/8C0/sprockets%2F332d5a9ce3e800c6c4a7a99058023ba2 +0 -0
  25. data/spec/dummy/tmp/cache/assets/{D5B/660/sprockets%2F4bb4e11ca3769b37bdac230e17180f2f → D09/740/sprockets%2F7a82d51e72434ef73fabb4a26131d945} +0 -0
  26. data/spec/dummy/tmp/cache/assets/D11/CC0/sprockets%2F3a12dfa6665b5318fa99d097203ac7e7 +0 -0
  27. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  28. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  29. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  30. data/spec/dummy/tmp/cache/assets/D61/6F0/sprockets%2F02da53eeca228bcef0c49278517111fe +0 -0
  31. data/spec/dummy/tmp/cache/assets/{D12/8E0/sprockets%2F589dd1f5f312060f7ea7179ed0d1b690 → D66/900/sprockets%2F52de1b25e110e8a937b9e30b0a9e8da7} +0 -0
  32. data/spec/dummy/tmp/cache/assets/{D60/F70/sprockets%2F336e00e00f731efa2546eeae7691ba1e → DA7/D70/sprockets%2Fc627f052aaee94e9b24815d5aee4ff38} +0 -0
  33. data/spec/dummy/tmp/cache/assets/DCA/9B0/sprockets%2Fdf0e8f8a85e5d4056b3fe1cec3b7131a +0 -0
  34. data/spec/dummy/tmp/cache/assets/{C5B/630/sprockets%2F8a34981857e0826772a246e2d7215ce5 → DD2/6F0/sprockets%2Ffbe80717facec3dd9ea7ac008719c843} +0 -0
  35. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  36. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  37. data/spec/lib/configuration_spec.rb +5 -5
  38. metadata +28 -20
  39. data/spec/dummy/db/migrate/20111118222920_create_blog_posts.rb +0 -12
  40. data/spec/dummy/db/migrate/20111118222921_create_blog_comments.rb +0 -15
  41. data/spec/dummy/db/migrate/20111118222922_acts_as_taggable_on_migration.rb +0 -28
  42. data/spec/dummy/tmp/pids/server.pid +0 -1
data/README.md CHANGED
@@ -54,8 +54,9 @@ we'll also throw in:
54
54
 
55
55
  * An XML Sitemap located at `/blog/posts.xml`
56
56
  * An RSS feed located at `/blog/posts.rss`
57
+ * Sitemap submission to the major search engines (via [Pingr](http://github.com/katanacode/pingr "Pingr") - off by default)
57
58
  * Page Caching and Sweeping
58
- * Internationalization (see the [locales file](https://github.com/KatanaCode/blogit/blob/master/config/locales/en.yml) for configurable options)
59
+ * Internationalization (see the [locales file](config/locales/en.yml) for configurable options)
59
60
  * Share links (Google+, Twitter & Facebook)
60
61
  * [Disquss Comments](http://disqus.com)
61
62
 
@@ -78,24 +79,7 @@ You're welcome to contribute to Blogit. Please consult the [contribution guideli
78
79
 
79
80
  Copyright 2011 [Katana Code Ltd.](http://katanacode.com)
80
81
 
81
- Permission is hereby granted, free of charge, to any person obtaining
82
- a copy of this software and associated documentation files (the
83
- "Software"), to deal in the Software without restriction, including
84
- without limitation the rights to use, copy, modify, merge, publish,
85
- distribute, sublicense, and/or sell copies of the Software, and to
86
- permit persons to whom the Software is furnished to do so, subject to
87
- the following conditions:
88
-
89
- The above copyright notice and this permission notice shall be
90
- included in all copies or substantial portions of the Software.
91
-
92
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
93
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
94
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
95
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
96
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
97
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
98
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
82
+ See (LEGAL)[LEGAL] for full details.
99
83
 
100
84
  ## Credits
101
85
 
@@ -105,7 +89,8 @@ with generous contributions from:
105
89
 
106
90
  * [Philou](https://github.com/philou)
107
91
  * [Stewart McKee](https://github.com/stewartmckee)
92
+ * [Karsten Silkenbäumer](https://github.com/kassi)
108
93
 
109
94
  ## About Katana Code
110
95
 
111
- Katana Code are [Ruby on Rails Developers Based in Edinburgh, Scotland](http://katanacode.com/ "Katana Code").
96
+ Katana Code are [Ruby on Rails Developers Based in Edinburgh, Scotland](http://katanacode.com/ "Katana Code").
@@ -4,6 +4,14 @@ module Blogit
4
4
  # the main_app
5
5
  class PostsController < ::Blogit::ApplicationController
6
6
 
7
+
8
+ # If using Blogit's Create, Update and Destroy actions AND ping_search_engines is
9
+ # set, call ping_search_engines after these requests
10
+ if Blogit.configuration.include_admin_actions
11
+ after_filter :ping_search_engines, only: [:create, :update, :destroy], :if => lambda { Blogit.configuration.ping_search_engines }
12
+ end
13
+
14
+ # Raise a 404 error if the admin actions aren't to be included
7
15
  # We can't use blogit_conf here because it sometimes raises NoMethodError in main app's routes
8
16
  unless Blogit.configuration.include_admin_actions
9
17
  before_filter :raise_404, except: [:index, :show, :tagged]
@@ -75,6 +83,20 @@ module Blogit
75
83
  # Don't include admin actions if include_admin_actions is false
76
84
  render file: "#{Rails.root}/public/404.html", status: :not_found, layout: false
77
85
  end
86
+
87
+
88
+ # @See the Pingr gem for more info https://github.com/KatanaCode/pingr
89
+ def ping_search_engines
90
+ case blogit_conf.ping_search_engines
91
+ when Array
92
+ search_engines = blogit_conf.ping_search_engines
93
+ when true
94
+ search_engines = Pingr::SUPPORTED_SEARCH_ENGINES
95
+ end
96
+ for search_engine in search_engines
97
+ Pingr::Request.new(search_engine, posts_url(format: :xml)).ping
98
+ end
99
+ end
78
100
 
79
101
  end
80
102
 
@@ -13,7 +13,7 @@ module Blogit
13
13
  # ==============
14
14
  # = Attributes =
15
15
  # ==============
16
- attr_accessible :title, :body, :tag_list
16
+ attr_accessible :title, :body, :tag_list, :blogger_type, :blogger_id
17
17
 
18
18
  # ===============
19
19
  # = Validations =
@@ -37,7 +37,7 @@
37
37
 
38
38
  <%= actions do %>
39
39
  <%= f.submit %> <%=t :or, scope: 'blogit.posts'%>
40
- <%= link_to(t(:cancel, scope: 'blogit.posts'), @post.new_record? ? root_path : post_path(@post)) %>
40
+ <%= link_to(t(:cancel, scope: 'blogit.posts'), @post.new_record? ? blog_root_path : post_path(@post)) %>
41
41
  <% end %>
42
42
 
43
43
  <% end %>
@@ -1,21 +1,21 @@
1
1
  xml.instruct!
2
2
  xml.rss "version" => "2.0", "xmlns:dc" => "htt://purl.org/dc/elements/1.1/" do
3
3
  xml.channel do
4
-
4
+
5
5
  xml.title blogit_conf.rss_feed_title
6
-
6
+
7
7
  xml.description blogit_conf.rss_feed_description
8
-
8
+
9
9
  xml.pubDate CGI.rfc1123_date @posts.first.try(:updated_at)
10
-
11
- xml.link root_url
12
-
10
+
11
+ xml.link blog_root_url
12
+
13
13
  xml.lastBuildDate CGI.rfc1123_date @posts.first.try(:updated_at)
14
-
15
- xml.language blogit_conf.rss_feed_language
14
+
15
+ xml.language I18n.locale
16
16
 
17
17
  @posts.each do |post|
18
-
18
+
19
19
  xml.item do
20
20
  xml.title post.title
21
21
  xml.description format_content(truncate(post.body, length: 400)).html_safe
@@ -24,7 +24,7 @@ xml.rss "version" => "2.0", "xmlns:dc" => "htt://purl.org/dc/elements/1.1/" do
24
24
  xml.guid post_url(post)
25
25
  xml.author post.blogger_display_name
26
26
  end
27
-
27
+
28
28
  end
29
29
  end
30
30
  end
@@ -1,12 +1,12 @@
1
1
  Blogit::Engine.routes.draw do
2
-
2
+
3
3
  # Keep these above the posts resources block
4
4
  match "posts/page/:page" => "posts#index"
5
5
  match "posts/tagged/:tag" => 'posts#tagged', as: :tagged_blog_posts
6
-
6
+
7
7
  resources :posts do
8
8
  resources :comments, only: [:create, :destroy]
9
9
  end
10
10
 
11
- root to: "posts#index"
12
- end
11
+ match "/" => "posts#index", as: :blog_root
12
+ end
@@ -2,6 +2,7 @@
2
2
  require "acts-as-taggable-on"
3
3
  require "kaminari"
4
4
  require "redcarpet"
5
+ require "pingr"
5
6
 
6
7
  require "blogit/configuration"
7
8
  require "blogit/blogs"
@@ -79,14 +79,15 @@ module Blogit
79
79
  # Defaults to "[Application Name] Blog Posts"
80
80
  attr_accessor :rss_feed_description
81
81
 
82
- # The default language of the RSS feed
83
- # Defaults to 'en'
84
- attr_accessor :rss_feed_language
85
-
86
82
  # Should the routes of the main app be accessible without
87
83
  # the "main_app." prefix ?
88
84
  attr_accessor :inline_main_app_named_routes
89
85
 
86
+ # Should blogit ping search engines with your sitemap
87
+ # when posts are created, updated or destroyed?
88
+ # Defaults to false
89
+ attr_accessor :ping_search_engines
90
+
90
91
  # When using redcarpet as content parser, pass these options as defaults.
91
92
  REDCARPET_OPTIONS = {
92
93
  hard_wrap: true,
@@ -116,7 +117,7 @@ module Blogit
116
117
  @highlight_code_syntax = true
117
118
  @rss_feed_title = "#{Rails.application.engine_name.titleize} Blog Posts"
118
119
  @rss_feed_description = "#{Rails.application.engine_name.titleize} Blog Posts"
119
- @rss_feed_language = "en"
120
+ @ping_search_engines = false
120
121
  @redcarpet_options = REDCARPET_OPTIONS
121
122
  end
122
123
 
@@ -142,6 +143,10 @@ module Blogit
142
143
  @twitter_username = username
143
144
  end
144
145
 
146
+ def rss_feed_language=(locale)
147
+ blogit_warn "#{self.class}#rss_feed_language has been deprecated. You can remove this from your blogit.rb configuration file"
148
+ end
149
+
145
150
  private
146
151
 
147
152
  def blogit_warn(message)
@@ -1,3 +1,3 @@
1
1
  module Blogit
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -60,9 +60,15 @@ Blogit.configure do |config|
60
60
  # RSS Feed description content
61
61
  # config.rss_feed_description = "Get your daily pony news here!"
62
62
 
63
- # RSS Feed language
64
- # config.rss_feed_language = "en"
65
-
63
+ # Should blogit ping search engines with your sitemap
64
+ # when posts are created, updated or destroyed?
65
+ #
66
+ # Can pass true to ping all supported search engines, or an array of search
67
+ # engine names. e.g. [:google, :bing]
68
+ #
69
+ # Defaults to false
70
+ # config.ping_search_engines = false
71
+
66
72
  # When using redcarpet as content parser, pass these options as defaults.
67
73
  # @see here for more options: https://github.com/tanoku/redcarpet
68
74
  # config.redcarpet_options = {
@@ -116,7 +116,30 @@ describe PostsController do
116
116
  do_post
117
117
  response.should redirect_to(controller.posts_url)
118
118
  end
119
+
120
+ it "should ping all search engines in ping_search_engines config if array" do
121
+ Blogit.configuration.ping_search_engines = search_engines = [:google]
122
+ search_engines.each do |search_engine|
123
+ Pingr::Request.expects(:new).with(search_engine, controller.posts_url(format: :xml))
124
+ end
125
+ do_post
126
+ end
127
+
128
+ it "should ping all search engines in Pingr::SUPPORTED_SEARCH_ENGINES if config is true" do
129
+ Blogit.configuration.ping_search_engines = true
130
+ Pingr::SUPPORTED_SEARCH_ENGINES.each do |search_engine|
131
+ Pingr::Request.expects(:new).with(search_engine, controller.posts_url(format: :xml))
132
+ end
133
+ do_post
134
+ end
119
135
 
136
+ it "should not ping any search engines if ping_search_engines is false" do
137
+ Blogit.configuration.ping_search_engines = false
138
+ Pingr::SUPPORTED_SEARCH_ENGINES.each do |search_engine|
139
+ Pingr::Request.expects(:new).with(search_engine, controller.posts_url(format: :xml)).never
140
+ end
141
+ do_post
142
+ end
120
143
  end
121
144
 
122
145
  end
@@ -192,6 +215,31 @@ describe PostsController do
192
215
  do_put
193
216
  flash[:notice].should be_present
194
217
  end
218
+
219
+ it "should ping all search engines in ping_search_engines config if array" do
220
+ Blogit.configuration.ping_search_engines = search_engines = [:google, :bing]
221
+ search_engines.each do |search_engine|
222
+ Pingr::Request.expects(:new).with(search_engine, controller.posts_url(format: :xml))
223
+ end
224
+ do_put
225
+ end
226
+
227
+ it "should ping all search engines in Pingr::SUPPORTED_SEARCH_ENGINES if config is true" do
228
+ Blogit.configuration.ping_search_engines = true
229
+ Pingr::SUPPORTED_SEARCH_ENGINES.each do |search_engine|
230
+ Pingr::Request.expects(:new).with(search_engine, controller.posts_url(format: :xml))
231
+ end
232
+ do_put
233
+ end
234
+
235
+ it "should not ping any search engines if ping_search_engines is false" do
236
+ Blogit.configuration.ping_search_engines = false
237
+ Pingr::SUPPORTED_SEARCH_ENGINES.each do |search_engine|
238
+ Pingr::Request.expects(:new).with(search_engine, controller.posts_url(format: :xml)).never
239
+ end
240
+ do_put
241
+ end
242
+
195
243
  end
196
244
 
197
245
  context "when not logged in" do
@@ -261,6 +309,30 @@ describe PostsController do
261
309
  do_delete
262
310
  flash[:notice].should be_present
263
311
  end
312
+
313
+ it "should ping all search engines in ping_search_engines config if array" do
314
+ Blogit.configuration.ping_search_engines = search_engines = [:google, :bing]
315
+ search_engines.each do |search_engine|
316
+ Pingr::Request.expects(:new).with(search_engine, controller.posts_url(format: :xml))
317
+ end
318
+ do_delete
319
+ end
320
+
321
+ it "should ping all search engines in Pingr::SUPPORTED_SEARCH_ENGINES if config is true" do
322
+ Blogit.configuration.ping_search_engines = true
323
+ Pingr::SUPPORTED_SEARCH_ENGINES.each do |search_engine|
324
+ Pingr::Request.expects(:new).with(search_engine, controller.posts_url(format: :xml))
325
+ end
326
+ do_delete
327
+ end
328
+
329
+ it "should not ping any search engines if ping_search_engines is false" do
330
+ Blogit.configuration.ping_search_engines = false
331
+ Pingr::SUPPORTED_SEARCH_ENGINES.each do |search_engine|
332
+ Pingr::Request.expects(:new).with(search_engine, controller.posts_url(format: :xml)).never
333
+ end
334
+ do_delete
335
+ end
264
336
 
265
337
  end
266
338
 
@@ -15,7 +15,7 @@
15
15
  <%= link_to("log in", main_app.new_session_path) %>
16
16
  <% end %>
17
17
 
18
- <h1><%= link_to("My Awesome Blog", root_path) %></h1>
18
+ <h1><%= link_to("My Awesome Blog", blog_root_path) %></h1>
19
19
 
20
20
  <%= yield %>
21
21
  </div>
@@ -1,62 +1,91 @@
1
1
  # These configuration options can be used to customise the behaviour of Blogit
2
+ # these are all commented out in testing to use the defaults
2
3
  Blogit.configure do |config|
3
4
 
4
5
  # What kind of comments do you want to add to your blog ? (:active_record, :disqus or :no)
5
- config.include_comments = :active_record
6
+ # config.include_comments = :active_record
6
7
 
7
8
  # When using disqus comments, what is the shortname of your forum ?
8
- config.disqus_shortname = ""
9
+ # config.disqus_shortname = ""
9
10
 
10
11
  # Should there be a share bar on every post ?
11
- config.include_share_bar = true
12
+ # config.include_share_bar = false
12
13
 
13
14
  # Twitter username used in the share bar
14
- config.twitter_username = "blogit"
15
+ # config.twitter_username = ""
15
16
 
16
17
  # The name of the controller method we'll call to return the current blogger.
17
18
  # Change this if you use something other than current_user.
18
19
  # Eg. current_admin_user (if using ActiveAdmin)
19
- config.current_blogger_method = :current_user
20
+ # config.current_blogger_method = :current_user
20
21
 
21
22
  # What method do we call on blogger to show who they are?
22
- config.blogger_display_name_method = :username
23
+ # config.blogger_display_name_method = :username
23
24
 
24
25
  # Which DateTime::FORMATS format do we use to display blog and comment publish time
25
- config.datetime_format = :short
26
+ # config.datetime_format = :short
26
27
 
27
28
  # Should the controllers cache the blog pages as HTML?
28
- config.cache_pages = true
29
+ # config.cache_pages = false
29
30
 
30
31
  # No. of posts to show per page
31
- config.posts_per_page = 5
32
+ # config.posts_per_page = 5
32
33
 
33
34
  # The name of the before filter we'll call to authenticate the current user.
34
- config.authentication_method = :login_required
35
+ # config.authentication_method = :login_required
35
36
 
36
37
  # If set to true, the comments form will POST and DELETE to the comments
37
38
  # controller using AJAX calls.
38
- config.ajax_comments = true
39
+ # config.ajax_comments = true
39
40
 
40
41
  # If set to true, the create, edit, update and destroy actions
41
42
  # will be included. If set to false, you'll have to set these
42
43
  # yourself elsewhere in the app.
43
- config.include_admin_actions = true
44
+ # config.include_admin_actions = true
44
45
 
45
46
  # If set to true, links for new posts, editing posts and deleting comments
46
47
  # will be available. If set to false, you'll have to set these
47
48
  # yourself in the templates.
48
- config.include_admin_links = true
49
+ # config.include_admin_links = true
49
50
 
50
51
  # The default format for parsing the blog content.
51
- config.default_parser = :textile
52
+ # config.default_parser = :markdown
52
53
 
53
54
  # If blog content contains code, this should be highlighted using
54
55
  # albino.
55
- config.highlight_code_syntax = true
56
-
56
+ # config.highlight_code_syntax = true
57
+
58
+ # RSS Feed title content
59
+ # config.rss_feed_title = "A blog about ponies!"
60
+
61
+ # RSS Feed description content
62
+ # config.rss_feed_description = "Get your daily pony news here!"
63
+
64
+ # Should blogit ping search engines with your sitemap
65
+ # when posts are created, updated or destroyed?
66
+ #
67
+ # Can pass true to ping all supported search engines, or an array of search
68
+ # engine names. e.g. [:google, :bing]
69
+ #
70
+ # Defaults to false
71
+ config.ping_search_engines = true
72
+
57
73
  # When using redcarpet as content parser, pass these options as defaults.
58
74
  # @see here for more options: https://github.com/tanoku/redcarpet
59
- # config.redcarpet_options = [:hard_wrap, :filter_html, :autolink,
60
- # :no_intraemphasis, :fenced_code, :gh_blockcode]
61
-
62
- end
75
+ # config.redcarpet_options = {
76
+ # hard_wrap: true,
77
+ # filter_html: true,
78
+ # autolink: true,
79
+ # no_intraemphasis: true,
80
+ # fenced_code_blocks: true,
81
+ # gh_blockcode: true
82
+ # }
83
+
84
+ # If set to true, it will be possible to call named routes of the main app
85
+ # directly, without the "main_app." prefix.
86
+ # Useful in the case where you don't want to change the main app's layout,
87
+ # but it does not expand correctly from inside blogit because some main
88
+ # app's named routes are missing.
89
+ # config.inline_main_app_named_routes = true
90
+
91
+ end