blogit 0.8.0 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +3 -1
  3. data/Rakefile +8 -24
  4. data/app/controllers/blogit/application_controller.rb +5 -16
  5. data/app/controllers/blogit/comments_controller.rb +7 -5
  6. data/app/controllers/blogit/posts_controller.rb +30 -17
  7. data/app/helpers/blogit/posts_helper.rb +1 -1
  8. data/app/models/blogit/comment.rb +23 -27
  9. data/app/models/blogit/post.rb +24 -23
  10. data/app/views/blogit/comments/_admin_links.html.erb +2 -2
  11. data/app/views/blogit/comments/create.js.erb +2 -2
  12. data/app/views/blogit/posts/_empty.html.erb +0 -3
  13. data/app/views/blogit/posts/_form.html.erb +9 -3
  14. data/app/views/blogit/posts/_post_links.html.erb +3 -2
  15. data/app/views/blogit/posts/_related.html.erb +1 -1
  16. data/config/locales/de.yml +50 -0
  17. data/config/locales/en.yml +2 -5
  18. data/config/locales/fr.yml +0 -4
  19. data/config/routes.rb +3 -3
  20. data/db/migrate/20110814091434_create_blogit_posts.rb +15 -0
  21. data/db/migrate/{20110814093229_create_blog_comments.rb → 20110814093229_create_blogit_comments.rb} +3 -3
  22. data/lib/blogit/configuration.rb +26 -1
  23. data/lib/blogit/version.rb +1 -1
  24. data/lib/blogit.rb +1 -2
  25. data/lib/generators/blogit/table_name_migration_generator.rb +15 -0
  26. data/lib/generators/templates/blogit.rb +12 -6
  27. data/lib/generators/templates/rename_blogit_tables.rb +21 -0
  28. data/spec/controllers/blogit/comments_controller_spec.rb +1 -1
  29. data/spec/controllers/blogit/posts_controller_spec.rb +57 -13
  30. data/spec/dummy/app/views/layouts/custom.html.erb +34 -0
  31. data/spec/dummy/config/application.rb +12 -7
  32. data/spec/dummy/config/database.yml +28 -24
  33. data/spec/dummy/config/environments/development.rb +23 -14
  34. data/spec/dummy/config/environments/production.rb +55 -22
  35. data/spec/dummy/config/environments/test.rb +17 -16
  36. data/spec/dummy/config/initializers/blogit.rb +5 -8
  37. data/spec/dummy/config/initializers/secret_token.rb +11 -2
  38. data/spec/dummy/db/development.sqlite3 +0 -0
  39. data/{db/migrate/20110814103306_acts_as_taggable_on_migration.rb → spec/dummy/db/migrate/20140511174024_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb} +6 -3
  40. data/spec/dummy/db/migrate/20140511174025_add_missing_unique_indices.acts_as_taggable_on_engine.rb +20 -0
  41. data/spec/dummy/db/migrate/20140511174026_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +15 -0
  42. data/spec/dummy/db/migrate/20140511174028_create_blogit_posts.blogit.rb +16 -0
  43. data/spec/dummy/db/migrate/20140511174029_create_blogit_comments.blogit.rb +16 -0
  44. data/spec/dummy/db/schema.rb +32 -29
  45. data/spec/dummy/db/test.sqlite3 +0 -0
  46. data/spec/dummy/log/development.log +1444 -2970
  47. data/spec/dummy/log/test.log +9631 -29732
  48. data/spec/dummy/tmp/cache/assets/CB5/DD0/sprockets%2F346324d2a51df58457807bee661c449c +0 -0
  49. data/spec/dummy/tmp/cache/assets/CB6/ED0/sprockets%2F4390d06699f3ad4262e342be530f9f91 +0 -0
  50. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  51. data/spec/dummy/tmp/cache/assets/CE7/230/sprockets%2F6f493a817d97133a8dbf674bcd322670 +0 -0
  52. data/spec/dummy/tmp/cache/assets/{D35/E90/sprockets%2F9542f66fea1d10b7924f3b6b31e1e2e0 → CEA/490/sprockets%2F9697d4fb1ed26d80f3c715611c8d4373} +0 -0
  53. data/spec/dummy/tmp/cache/assets/CEE/310/sprockets%2F89642af8492e579dcd7162a0e2b7f155 +0 -0
  54. data/spec/dummy/tmp/cache/assets/D01/8C0/sprockets%2F332d5a9ce3e800c6c4a7a99058023ba2 +0 -0
  55. data/spec/dummy/tmp/cache/assets/D11/CC0/sprockets%2F3a12dfa6665b5318fa99d097203ac7e7 +0 -0
  56. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  57. data/spec/dummy/tmp/cache/assets/{D67/C10/sprockets%2Fa58c567f1eae28b401a6e9a0b3b71d93 → D3D/1E0/sprockets%2Ffbaabd57fa2c9d426f0c318156705667} +0 -0
  58. data/spec/dummy/tmp/cache/assets/D3E/920/sprockets%2F3efa8d0fc958c223647cb704183b65ca +0 -0
  59. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  60. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  61. data/spec/dummy/tmp/cache/assets/D61/6F0/sprockets%2F02da53eeca228bcef0c49278517111fe +0 -0
  62. data/spec/dummy/tmp/cache/assets/DCA/9B0/sprockets%2Fdf0e8f8a85e5d4056b3fe1cec3b7131a +0 -0
  63. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  64. data/spec/dummy/tmp/cache/assets/E02/A60/sprockets%2Fb32faeede196f7a933c3a2794e7ed0bd +0 -0
  65. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  66. data/spec/dummy/tmp/cache/assets/development/sprockets/02da53eeca228bcef0c49278517111fe +0 -0
  67. data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  68. data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  69. data/spec/dummy/tmp/cache/assets/development/sprockets/2ff93f9f5ed9970021c7704ff93237c8 +0 -0
  70. data/spec/dummy/tmp/cache/assets/development/sprockets/332d5a9ce3e800c6c4a7a99058023ba2 +0 -0
  71. data/spec/dummy/tmp/cache/assets/development/sprockets/346324d2a51df58457807bee661c449c +0 -0
  72. data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  73. data/spec/dummy/tmp/cache/assets/development/sprockets/3a12dfa6665b5318fa99d097203ac7e7 +0 -0
  74. data/spec/dummy/tmp/cache/assets/{D74/A60/sprockets%2F2add607cdb6c0b17fd866aac28895485 → development/sprockets/3ed52366904e135bd833590814b6ac6d} +0 -0
  75. data/spec/dummy/tmp/cache/assets/development/sprockets/4390d06699f3ad4262e342be530f9f91 +0 -0
  76. data/spec/dummy/tmp/cache/assets/development/sprockets/6f493a817d97133a8dbf674bcd322670 +0 -0
  77. data/spec/dummy/tmp/cache/assets/development/sprockets/89642af8492e579dcd7162a0e2b7f155 +0 -0
  78. data/spec/dummy/tmp/cache/assets/{D09/740/sprockets%2F7a82d51e72434ef73fabb4a26131d945 → development/sprockets/89dc196c51ae83634b664c0c33052008} +0 -0
  79. data/spec/dummy/tmp/cache/assets/{DD2/6F0/sprockets%2Ffbe80717facec3dd9ea7ac008719c843 → development/sprockets/8dd8236b00c868ba248fe30cd9c14c2a} +0 -0
  80. data/spec/dummy/tmp/cache/assets/development/sprockets/9239a04d094a872c1cf77ac391072ea8 +0 -0
  81. data/spec/dummy/tmp/cache/assets/development/sprockets/b3ffb6bd243399012806331ce393ae4f +0 -0
  82. data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  83. data/spec/dummy/tmp/cache/assets/{D78/4E0/sprockets%2F3d4e761a135f6b6e50b24defce90f798 → development/sprockets/d53accc3e58037ee4005e41221b8846b} +0 -0
  84. data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  85. data/spec/dummy/tmp/cache/assets/development/sprockets/df0e8f8a85e5d4056b3fe1cec3b7131a +0 -0
  86. data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  87. data/spec/factories.rb +5 -1
  88. data/spec/helpers/blogit/posts_helper_spec.rb +5 -5
  89. data/spec/lib/blogs_spec.rb +0 -6
  90. data/spec/lib/configuration_spec.rb +17 -1
  91. data/spec/models/blogit/post_spec.rb +29 -9
  92. data/spec/spec_helper.rb +6 -5
  93. metadata +177 -174
  94. data/app/sweepers/blogit/blogit_sweeper.rb +0 -33
  95. data/db/migrate/20110814091434_create_blog_posts.rb +0 -12
  96. data/spec/dummy/test/fixtures/people.yml +0 -7
  97. data/spec/dummy/test/fixtures/users.yml +0 -9
  98. data/spec/dummy/test/functional/people_controller_test.rb +0 -49
  99. data/spec/dummy/test/functional/sessions_controller_test.rb +0 -9
  100. data/spec/dummy/test/functional/users_controller_test.rb +0 -49
  101. data/spec/dummy/test/unit/helpers/people_helper_test.rb +0 -4
  102. data/spec/dummy/test/unit/helpers/sessions_helper_test.rb +0 -4
  103. data/spec/dummy/test/unit/helpers/users_helper_test.rb +0 -4
  104. data/spec/dummy/test/unit/person_test.rb +0 -7
  105. data/spec/dummy/test/unit/user_test.rb +0 -7
  106. data/spec/dummy/tmp/cache/assets/CAA/340/sprockets%2Fa9991211287db8645603e5ba17008bbe +0 -0
  107. data/spec/dummy/tmp/cache/assets/D3D/D30/sprockets%2Ff1ebd04d570b12945debea975941815b +0 -0
  108. data/spec/dummy/tmp/cache/assets/D66/900/sprockets%2F52de1b25e110e8a937b9e30b0a9e8da7 +0 -0
  109. data/spec/dummy/tmp/cache/assets/DA7/D70/sprockets%2Fc627f052aaee94e9b24815d5aee4ff38 +0 -0
  110. data/spec/dummy/tmp/pids/server.pid +0 -1
  111. data/spec/lib/action_dispatch/http/url_spec.rb +0 -21
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 284698e6cf80971f9da206a03066356e5d290bae
4
+ data.tar.gz: 87263f108741571411bb221b9c670997ea1bbaa6
5
+ SHA512:
6
+ metadata.gz: 2367ee69877ce6372bbc302ba3a80f4cd7b42882a33007cb1e43b48628de4c0b63b77809dd4724128eca87a44162aa86e61f90aa7b3a5b2a02819e4ba707a48c
7
+ data.tar.gz: ced761eb3174ff8af85d7abcedfd12ae10ea661c315e11e5cca5fe96ffd90f5d58e27cb72e5d14b6c303e2d60201d0e8a709eefc91eb01c9d75b346032f00a99
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/blogit.png)](http://badge.fury.io/rb/blogit)
2
2
  [![Code Climate](https://codeclimate.com/github/KatanaCode/blogit.png)](http://codeclimate.com/github/KatanaCode/blogit/)
3
3
  [![Blogit](https://gemnasium.com/KatanaCode/blogit.png)](https://gemnasium.com/KatanaCode/blogit)
4
+ [![Travis CI](https://travis-ci.org/KatanaCode/blogit.png)](https://travis-ci.org/KatanaCode/blogit.png)
5
+
4
6
 
5
7
 
6
8
  # Blogit (beta)
@@ -105,4 +107,4 @@ with generous contributions from:
105
107
 
106
108
  ## About Katana Code
107
109
 
108
- Katana Code are [Ruby on Rails Developers Based in Edinburgh, Scotland](http://katanacode.com/ "Katana Code").
110
+ Katana Code are [iPhone app and Ruby on Rails Developers in Edinburgh, Scotland](http://katanacode.com/ "Katana Code").
data/Rakefile CHANGED
@@ -4,36 +4,20 @@ begin
4
4
  rescue LoadError
5
5
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
6
  end
7
- begin
8
- require 'rdoc/task'
9
- rescue LoadError
10
- require 'rdoc/rdoc'
11
- require 'rake/rdoctask'
12
- RDoc::Task = Rake::RDocTask
13
- end
14
-
15
- RDoc::Task.new(:rdoc) do |rdoc|
16
- rdoc.rdoc_dir = 'rdoc'
17
- rdoc.title = 'Blog'
18
- rdoc.options << '--line-numbers'
19
- rdoc.rdoc_files.include('README.rdoc')
20
- rdoc.rdoc_files.include('lib/**/*.rb')
21
- end
22
7
 
23
8
  APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
- load 'rails/tasks/engine.rake'
25
9
 
10
+ load 'rails/tasks/engine.rake'
26
11
 
27
12
  Bundler::GemHelper.install_tasks
28
13
 
29
- require 'rake/testtask'
14
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
30
15
 
31
- Rake::TestTask.new(:test) do |t|
32
- t.libs << 'lib'
33
- t.libs << 'test'
34
- t.pattern = 'test/**/*_test.rb'
35
- t.verbose = false
36
- end
16
+ require 'rspec/core'
17
+ require 'rspec/core/rake_task'
18
+
19
+ desc "Run all specs in spec directory (excluding plugin specs)"
37
20
 
21
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
38
22
 
39
- task :default => :test
23
+ task :default => :spec
@@ -19,22 +19,6 @@ module Blogit
19
19
  Blogit::configuration
20
20
  end
21
21
 
22
- # Turns on page caching for the given actions if
23
- # Blogit.configuration.cache_pages is true
24
- def self.blogit_cacher(*args)
25
- if blogit_conf.cache_pages
26
- caches_page *args
27
- end
28
- end
29
-
30
- # Sets a cache sweeper to observe changes if
31
- # Blogit.configuration.cache_pages is true
32
- def self.blogit_sweeper(*args)
33
- if blogit_conf.cache_pages
34
- cache_sweeper Blogit::BlogitSweeper, only: args
35
- end
36
- end
37
-
38
22
  # A helper method to access the Blogit::configuration
39
23
  # at the controller instance level
40
24
  def blogit_conf
@@ -47,6 +31,11 @@ module Blogit
47
31
  send blogit_conf.current_blogger_method
48
32
  end
49
33
 
34
+ # Returns true or false if current_blogger is present
35
+ def is_blogger_logged_in?
36
+ !!current_blogger
37
+ end
38
+
50
39
  # Returns true if the current_blogger is the owner of the post
51
40
  # @param post An instance of Blogit::Post
52
41
  def this_blogger?(post)
@@ -3,11 +3,9 @@ module Blogit
3
3
 
4
4
  blogit_authenticate except: [:create]
5
5
 
6
- blogit_sweeper(:create, :update, :destroy)
7
-
8
-
9
6
  def create
10
- @comment = post.comments.new(params[:comment])
7
+ @comment = post.comments.new(comment_params)
8
+
11
9
  respond_to do |format|
12
10
  format.js {
13
11
  # the rest is dealt with in the view
@@ -37,9 +35,13 @@ module Blogit
37
35
 
38
36
  private
39
37
 
38
+ def comment_params
39
+ params.require(:comment).permit(:name, :nickname, :email, :body, :website)
40
+ end
41
+
40
42
  def post
41
43
  @post ||= Blogit::Post.find(params[:post_id])
42
44
  end
43
-
45
+
44
46
  end
45
47
  end
@@ -4,34 +4,37 @@ module Blogit
4
4
  # the main_app
5
5
  class PostsController < ::Blogit::ApplicationController
6
6
 
7
-
7
+ # If a layout is specified, use that. Otherwise, fall back to the default
8
+ layout Blogit.configuration.layout if Blogit.configuration.layout
9
+
8
10
  # If using Blogit's Create, Update and Destroy actions AND ping_search_engines is
9
11
  # set, call ping_search_engines after these requests
10
12
  if Blogit.configuration.include_admin_actions
11
13
  after_filter :ping_search_engines, only: [:create, :update, :destroy], :if => lambda { Blogit.configuration.ping_search_engines }
12
14
  end
13
-
15
+
14
16
  # Raise a 404 error if the admin actions aren't to be included
15
17
  # We can't use blogit_conf here because it sometimes raises NoMethodError in main app's routes
16
18
  unless Blogit.configuration.include_admin_actions
17
- before_filter :raise_404, except: [:index, :show, :tagged]
19
+ before_filter :raise_404, except: [:index, :show]
18
20
  end
19
21
 
20
22
  blogit_authenticate(except: [:index, :show, :tagged])
21
23
 
22
- blogit_cacher(:index, :show, :tagged)
23
- blogit_sweeper(:create, :update, :destroy)
24
-
25
24
  def index
26
25
  respond_to do |format|
27
26
  format.xml {
28
- @posts = Post.order('created_at DESC')
27
+ @posts = Post.active.order('created_at DESC')
29
28
  }
30
29
  format.html {
31
- @posts = Post.for_index(params[:page])
30
+ @posts = if is_blogger_logged_in?
31
+ Post.for_index(params[Kaminari.config.param_name])
32
+ else
33
+ Post.active.for_index(params[Kaminari.config.param_name])
34
+ end
32
35
  }
33
36
  format.rss {
34
- @posts = Post.order('created_at DESC')
37
+ @posts = Post.active.order('created_at DESC')
35
38
  }
36
39
  end
37
40
  end
@@ -41,12 +44,13 @@ module Blogit
41
44
  end
42
45
 
43
46
  def tagged
44
- @posts = Post.for_index(params[:page]).tagged_with(params[:tag])
47
+ param_name = params[Kaminari.config.param_name]
48
+ @posts = Post.for_index(param_name).tagged_with(params[:tag])
45
49
  render :index
46
50
  end
47
51
 
48
52
  def new
49
- @post = current_blogger.blog_posts.new(params[:post])
53
+ @post = current_blogger.blog_posts.new(post_paramters)
50
54
  end
51
55
 
52
56
  def edit
@@ -54,7 +58,7 @@ module Blogit
54
58
  end
55
59
 
56
60
  def create
57
- @post = current_blogger.blog_posts.new(params[:post])
61
+ @post = current_blogger.blog_posts.new(post_paramters)
58
62
  if @post.save
59
63
  redirect_to @post, notice: t(:blog_post_was_successfully_created, scope: 'blogit.posts')
60
64
  else
@@ -64,8 +68,9 @@ module Blogit
64
68
 
65
69
  def update
66
70
  @post = current_blogger.blog_posts.find(params[:id])
67
- if @post.update_attributes(params[:post])
68
- redirect_to @post, notice: t(:blog_post_was_successfully_updated, scope: 'blogit.posts')
71
+ if @post.update_attributes(post_paramters)
72
+ redirect_to @post, notice: t(:blog_post_was_successfully_updated,
73
+ scope: 'blogit.posts')
69
74
  else
70
75
  render action: "edit"
71
76
  end
@@ -77,14 +82,22 @@ module Blogit
77
82
  redirect_to posts_url, notice: t(:blog_post_was_successfully_destroyed, scope: 'blogit.posts')
78
83
  end
79
84
 
85
+ def post_paramters
86
+ if params[:post]
87
+ params.require(:post).permit(:title, :body, :tag_list, :state)
88
+ else
89
+ {}
90
+ end
91
+ end
92
+
80
93
  private
81
94
 
82
95
  def raise_404
83
96
  # Don't include admin actions if include_admin_actions is false
84
97
  render file: "#{Rails.root}/public/404.html", status: :not_found, layout: false
85
98
  end
86
-
87
-
99
+
100
+
88
101
  # @See the Pingr gem for more info https://github.com/KatanaCode/pingr
89
102
  def ping_search_engines
90
103
  case blogit_conf.ping_search_engines
@@ -100,4 +113,4 @@ module Blogit
100
113
 
101
114
  end
102
115
 
103
- end
116
+ end
@@ -31,7 +31,7 @@ module Blogit
31
31
  posts_by_month.each do |month, posts|
32
32
  result << "<li><a data-blogit-click-to-toggle-children>#{CGI.escape_html(month)}</a><ul class=\"#{post_css}\">"
33
33
  posts.each do |post|
34
- result << "<li>#{yield post}</li>"
34
+ result << "<li>#{link_to(post.title, blogit.post_path(post))}</li>"
35
35
  end
36
36
  result << "</ul></li>"
37
37
  end
@@ -1,66 +1,62 @@
1
1
  module Blogit
2
2
  class Comment < ActiveRecord::Base
3
-
3
+
4
4
  # require custom validators
5
5
  require "validators"
6
6
  include Validators
7
-
8
- self.table_name = "blog_comments"
9
-
7
+
10
8
  # ================
11
9
  # = Associations =
12
10
  # ================
13
-
14
- belongs_to :post, class_name: "Blogit::Post",
11
+
12
+ belongs_to :post, class_name: "Blogit::Post",
15
13
  foreign_key: "post_id", counter_cache: true, touch: true
16
-
14
+
17
15
  # TODO: Check if this is optimal
18
- URL_REGEX = /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
16
+ URL_REGEX = /\A(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?\Z/ix
19
17
 
20
- # TODO: Check if this is optimal
21
- EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
22
-
23
- # ============
18
+ # TODO: Check if this is optimal
19
+ EMAIL_REGEX = /\A[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\Z/i
20
+
21
+ # =============
24
22
  # = Callbacks =
25
- # ============
26
-
23
+ # =============
24
+
27
25
  before_validation :format_website
28
-
26
+
29
27
  # ==============
30
28
  # = Attributes =
31
29
  # ==============
32
-
33
- attr_accessible :name, :nickname, :email, :body, :website
34
-
30
+
35
31
  # nickname acts as a "honeypot" to catch spam
36
- # the form field should be hidden using CSS and so
32
+ # the form field should be hidden using CSS and so
37
33
  # if present, must be spam.
38
- #
34
+ #
39
35
  # @attribute
40
36
  attr_accessor :nickname
41
-
42
-
37
+
38
+
43
39
  # ===============
44
40
  # = Validations =
45
41
  # ===============
46
42
 
47
43
  # nickname acts as a "honeypot" to catch spam
48
- # the form field should be hidden using CSS and so
44
+ # the form field should be hidden using CSS and so
49
45
  # if present, must be spam.
50
46
  validates :nickname, absence: true
51
47
  validates :name, presence: true
52
48
  validates :email, presence: true, format: {with: EMAIL_REGEX, allow_blank: true }
53
49
  validates :body, presence: true, length: { minimum: 4, allow_blank: true}
54
50
  validates :website, format: {with: URL_REGEX, allow_blank: true}
55
-
51
+
56
52
  private
57
-
53
+
58
54
  # Prepend http to the url before the validation check
59
55
  def format_website
60
56
  if self.website.present? and self.website !~ /^http/i
61
57
  self.website = "http://#{self.website}"
62
58
  end
63
59
  end
64
-
60
+
65
61
  end
66
- end
62
+ end
@@ -1,25 +1,17 @@
1
1
  module Blogit
2
2
  class Post < ActiveRecord::Base
3
3
 
4
- require "acts-as-taggable-on"
4
+ require 'acts-as-taggable-on'
5
5
  require "kaminari"
6
6
 
7
7
  include ::ActionView::Helpers::TextHelper
8
8
 
9
9
  acts_as_taggable
10
10
 
11
- self.table_name = "blog_posts"
12
-
13
11
  self.paginates_per Blogit.configuration.posts_per_page
14
12
 
15
- # ==============
16
- # = Attributes =
17
- # ==============
18
- attr_accessible :title, :body, :tag_list, :blogger_type, :blogger_id
13
+ AVAILABLE_STATUS = (Blogit.configuration.hidden_states + Blogit.configuration.active_states)
19
14
 
20
- def short_body
21
- truncate(body, length: 400, separator: "\n")
22
- end
23
15
 
24
16
  # ===============
25
17
  # = Validations =
@@ -28,24 +20,16 @@ module Blogit
28
20
  validates :title, presence: true, length: { minimum: 10, maximum: 66 }
29
21
  validates :body, presence: true, length: { minimum: 10 }
30
22
  validates :blogger_id, presence: true
23
+ validates :state, presence: true
31
24
 
32
- # =================
33
- # = Assosciations =
34
- # =================
25
+ # ================
26
+ # = Associations =
27
+ # ================
35
28
 
36
29
  belongs_to :blogger, :polymorphic => true
37
30
 
38
31
  has_many :comments, :class_name => "Blogit::Comment"
39
32
 
40
- def comments
41
- check_comments_config
42
- super()
43
- end
44
- def comments=(value)
45
- check_comments_config
46
- super(value)
47
- end
48
-
49
33
  # ==========
50
34
  # = Scopes =
51
35
  # ==========
@@ -53,6 +37,7 @@ module Blogit
53
37
  # Returns the blog posts paginated for the index page
54
38
  # @scope class
55
39
  scope :for_index, lambda { |page_no = 1| order("created_at DESC").page(page_no) }
40
+ scope :active, lambda { where(state: Blogit.configuration.active_states ) }
56
41
 
57
42
  # ====================
58
43
  # = Instance Methods =
@@ -61,6 +46,21 @@ module Blogit
61
46
  def to_param
62
47
  "#{id}-#{title.parameterize}"
63
48
  end
49
+
50
+ def short_body
51
+ truncate(body, length: 400, separator: "\n")
52
+ end
53
+
54
+ def comments
55
+ check_comments_config
56
+ super()
57
+ end
58
+
59
+ def comments=(value)
60
+ check_comments_config
61
+ super(value)
62
+ end
63
+
64
64
 
65
65
  # If there's a current blogger and the display name method is set, returns the blogger's display name
66
66
  # Otherwise, returns an empty string
@@ -80,5 +80,6 @@ module Blogit
80
80
  def check_comments_config
81
81
  raise RuntimeError.new("Posts only allow active record comments (check blogit configuration)") unless Blogit.configuration.include_comments == :active_record
82
82
  end
83
+
83
84
  end
84
- end
85
+ end
@@ -1,3 +1,3 @@
1
1
  <%= login_required(class: "actions") do %>
2
- <%= link_to(t(:delete, scope: 'blogit.comments'), [@post, comment], method: :delete, confirm: t(:are_you_sure_you_want_to_remove_this_comment, scope: 'blogit.comments')) %>
3
- <% end %>
2
+ <%= link_to(t(:delete, scope: 'blogit.comments'), [@post, comment], method: :delete, data: { confirm: t(:are_you_sure_you_want_to_remove_this_comment, scope: 'blogit.comments') }) %>
3
+ <% end %>
@@ -3,5 +3,5 @@ var $form = $("form#new_blog_comment");
3
3
  $("#comments").append("<%= escape_javascript(render(@comment)) %>");
4
4
  $form.get(0).reset();
5
5
  <% else %>
6
- $form.html("<%= escape_javascript(render('form')) %>");
7
- <% end %>
6
+ $form.html("<%= escape_javascript(render(partial:'form', locals: { post: @comment.post, comment: @comment })) %>");
7
+ <% end %>
@@ -1,3 +0,0 @@
1
- <div class="blogit_empty_message">
2
- <%=t :there_are_no_posts_about, scope: 'blogit.posts', tag: params[:tag] %>
3
- </div>
@@ -20,6 +20,11 @@
20
20
  <%= field do %>
21
21
  <%= f.text_area :body, placeholder: t(:write_something_here, scope: 'blogit.posts') %>
22
22
  <% end %>
23
+
24
+ <p class="blog_post_tip">
25
+ <%=t :tip_you_can_style_your_post_using, scope: 'blogit.posts', parser: blogit_conf.default_parser %>
26
+ </p>
27
+
23
28
  </fieldset>
24
29
 
25
30
  <fieldset>
@@ -29,9 +34,10 @@
29
34
  <%= f.text_field :tag_list, placeholder: t(:tag_placeholder, scope: 'blogit.posts') %>
30
35
  <% end %>
31
36
 
32
- <p class="blog_post_tip">
33
- <%=t :tip_you_can_style_your_post_using, scope: 'blogit.posts', parser: blogit_conf.default_parser %>
34
- </p>
37
+ <%= field id: "new_blog_post_state_field" do %>
38
+ <%= f.label :state, t(:state, scope: 'blogit.posts') %>
39
+ <%= f.collection_select(:state, Blogit::Post::AVAILABLE_STATUS, :to_s, :to_s) %>
40
+ <% end %>
35
41
 
36
42
  </fieldset>
37
43
 
@@ -1,5 +1,6 @@
1
1
  <%= login_required do %>
2
2
  <%= actions do %>
3
- <%= link_to(t(:edit, scope: 'blogit.posts'), edit_post_path(post)) %> | <%= link_to(t(:delete, scope: 'blogit.posts'), post, method: :delete, confirm: t(:are_you_sure_you_want_to_remove_this_post, scope: 'blogit.posts')) %>
3
+ <%= link_to(t(:edit, scope: 'blogit.posts'), edit_post_path(post)) %> | <%= link_to(t(:delete, scope: 'blogit.posts'), post,
4
+ method: :delete, data: { confirm: t(:are_you_sure_you_want_to_remove_this_post, scope: 'blogit.posts')}) %>
4
5
  <% end %>
5
- <% end unless blogit_conf.author_edits_only and not this_blogger?(post) %>
6
+ <% end unless blogit_conf.author_edits_only and not this_blogger?(post) %>
@@ -15,4 +15,4 @@
15
15
  <% end %>
16
16
  </ul>
17
17
  </div>
18
- </div>
18
+ </div>
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+ de:
3
+ blogit:
4
+ comments:
5
+ leave_a_comment: "Schreibe einen Kommentar"
6
+ name: "Name *"
7
+ email_never_displayed: "E-Mail * (nicht öffentlich)"
8
+ your_website: "Deine Webseite"
9
+ your_comment: "Dein Kommentar *"
10
+ add_comment: "Kommentar hinzufügen"
11
+ adding_comment: "Kommentar wird hinzugefügt..."
12
+ wrote: "schrieb:"
13
+ posted_on: "Geschrieben am"
14
+ delete: "löschen"
15
+ are_you_sure_you_want_to_remove_this_comment: "Bist Du sicher, dass Du den Kommentar löschen möchtest?"
16
+ successfully_added_comment: "Kommentar wurde hinzugefügt!"
17
+ successfully_removed_comment: "Kommentar wurde gelöscht."
18
+ posts:
19
+ written_by: "Verfasst von %{author} am"
20
+ there_are_no_posts_about: "Es gibt leider keine Beiträge zum Thema \"%{tag}\"."
21
+ prohibited_this_post_from_being_saved:
22
+ one: "Der Beitrag konnte nicht gespeichert werden, da ein Fehler aufgetreten ist:"
23
+ other: "Der Beitrag konnte nicht gespeichert werden, da %{count} Fehler aufgetreten sind:"
24
+ give_your_post_a_title: "Gib dem Beitrag einen Titel"
25
+ write_something_here: "Schreibe den Text hier..."
26
+ tags: "Kategorien"
27
+ tag_placeholder: "Kategorie eins, Kategorie zwei, usw."
28
+ tip_you_can_style_your_post_using: "Tipp: der Beitrag kann mit '%{parser}' formatiert werden"
29
+ or: "oder"
30
+ cancel: "abbrechen"
31
+ edit: "bearbeiten"
32
+ delete: "löschen"
33
+ are_you_sure_you_want_to_remove_this_post: "Bist Du sicher, dass Du den Beitrag löschen möchtest?"
34
+ comment:
35
+ one: "ein Kommentar"
36
+ other: "%{count} Kommentare"
37
+ edit_blog_post: "Beitrag #%{id} bearbeiten"
38
+ new_blog_post: "Neuer Beitrag"
39
+ write_a_new_blog_post: "Verfasse einen neuen Beitrag"
40
+ blog_post_was_successfully_created: "Beitrag wurde erfolgreich erstellt."
41
+ blog_post_was_successfully_updated: "Beitrag wurde erfolgreich aktualisiert."
42
+ blog_post_was_successfully_destroyed: "Beitrag wurde erfolgreich entfernt."
43
+ tags: "Kategorien"
44
+ related_posts: "Verwandte Beiträge"
45
+ share_bar:
46
+ facebook: "de_DE"
47
+
48
+ time:
49
+ formats:
50
+ plain_month_only: "%B"
@@ -16,14 +16,11 @@ en:
16
16
  successfully_removed_comment: "Successfully removed comment."
17
17
  posts:
18
18
  written_by: "Written by %{author} on"
19
- there_are_no_posts_about: "Sorry, there are no posts about \"%{tag}\"."
20
19
  prohibited_this_post_from_being_saved:
21
20
  one: "One error prohibited this post form being saved:"
22
21
  other: "%{count} errors prohibited this post form being saved:"
23
22
  give_your_post_a_title: "Give your post a title"
24
23
  write_something_here: "Write something here..."
25
- tags: "Tags"
26
- tag_placeholder: "tag one, tag two, etc..."
27
24
  tip_you_can_style_your_post_using: "Tip: you can style your post using %{parser}"
28
25
  or: "or"
29
26
  cancel: "cancel"
@@ -39,12 +36,12 @@ en:
39
36
  blog_post_was_successfully_created: "Blog post was successfully created."
40
37
  blog_post_was_successfully_updated: "Blog post was successfully updated."
41
38
  blog_post_was_successfully_destroyed: "Blog post was successfully destroyed."
42
- tags: "Tags"
43
39
  related_posts: "Related posts"
40
+ tag_placeholder: "Add tags to your post"
41
+
44
42
  share_bar:
45
43
  facebook: "en_US"
46
44
 
47
45
  time:
48
46
  formats:
49
47
  plain_month_only: "%B"
50
-
@@ -16,14 +16,11 @@ fr:
16
16
  successfully_removed_comment: "Commentaire supprimé avec succès."
17
17
  posts:
18
18
  written_by: "Ecrit par %{author} le"
19
- there_are_no_posts_about: "Désolé, il n'y a pas d'article à propos de \"%{tag}\"."
20
19
  prohibited_this_post_from_being_saved:
21
20
  one: "Une erreur a empêché cet article d'être enregistré :"
22
21
  other: "%{count} erreurs ont empêché cet article d'être enregistré :"
23
22
  give_your_post_a_title: "Donnez un nom à votre article"
24
23
  write_something_here: "Ecrivez quelque chose ici ..."
25
- tags: "Libellés"
26
- tag_placeholder: "Libellé 1, Libellé 2 ..."
27
24
  tip_you_can_style_your_post_using: "Astuce : vous pouvez styler votre article en utilisant %{parser}"
28
25
  or: "ou"
29
26
  cancel: "annuler"
@@ -40,7 +37,6 @@ fr:
40
37
  blog_post_was_successfully_created: "Article ajouté avec succès."
41
38
  blog_post_was_successfully_updated: "Article modifié avec succès."
42
39
  blog_post_was_successfully_destroyed: "Article supprimé avec succès."
43
- tags: "Catégories"
44
40
  related_posts: "Articles similaires"
45
41
  share_bar:
46
42
  facebook: "fr_FR"
data/config/routes.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  Blogit::Engine.routes.draw do
2
2
 
3
3
  # Keep these above the posts resources block
4
- match "posts/page/:page" => "posts#index"
5
- match "posts/tagged/:tag" => 'posts#tagged', as: :tagged_blog_posts
4
+ get "posts/page/:page" => "posts#index"
5
+ get "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
- match "/" => "posts#index", as: :blog_root
11
+ get "/" => "posts#index", as: :blog_root
12
12
  end
@@ -0,0 +1,15 @@
1
+ class CreateBlogitPosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :blogit_posts do |t|
4
+ t.with_options(null: false) do |r|
5
+ r.string :title
6
+ r.text :body
7
+ r.string :state, default: Blogit::configuration.hidden_states.first.to_s
8
+ r.integer :comments_count, default: 0
9
+ end
10
+ t.references :blogger, polymorphic: true
11
+ t.timestamps
12
+ end
13
+ add_index :blogit_posts, [:blogger_type, :blogger_id]
14
+ end
15
+ end
@@ -1,6 +1,6 @@
1
- class CreateBlogComments < ActiveRecord::Migration
1
+ class CreateBlogitComments < ActiveRecord::Migration
2
2
  def change
3
- create_table :blog_comments do |t|
3
+ create_table :blogit_comments do |t|
4
4
  t.string :name, null: false
5
5
  t.string :email, null: false
6
6
  t.string :website
@@ -10,6 +10,6 @@ class CreateBlogComments < ActiveRecord::Migration
10
10
 
11
11
  t.timestamps
12
12
  end
13
- add_index :blog_comments, :post_id
13
+ add_index :blogit_comments, :post_id
14
14
  end
15
15
  end