blogit 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.md +3 -0
- data/Rakefile +39 -0
- data/app/assets/javascripts/blogit/index.js +1 -0
- data/app/assets/stylesheets/blogit/comments.css +16 -0
- data/app/assets/stylesheets/blogit/index.css +3 -0
- data/app/assets/stylesheets/blogit/posts.css +59 -0
- data/app/controllers/blogit/application_controller.rb +41 -0
- data/app/controllers/blogit/comments_controller.rb +44 -0
- data/app/controllers/blogit/posts_controller.rb +55 -0
- data/app/helpers/blogit/application_helper.rb +64 -0
- data/app/helpers/blogit/comments_helper.rb +19 -0
- data/app/helpers/blogit/posts_helper.rb +26 -0
- data/app/models/blogit/comment.rb +59 -0
- data/app/models/blogit/post.rb +57 -0
- data/app/views/blogit/comments/_comment.html.erb +16 -0
- data/app/views/blogit/comments/_form.html.erb +42 -0
- data/app/views/blogit/comments/create.js.erb +7 -0
- data/app/views/blogit/comments/destroy.js.erb +1 -0
- data/app/views/blogit/posts/_blog_post_spacer.html.erb +1 -0
- data/app/views/blogit/posts/_blogger_information.html.erb +4 -0
- data/app/views/blogit/posts/_comments_count.html.erb +5 -0
- data/app/views/blogit/posts/_form.html.erb +43 -0
- data/app/views/blogit/posts/_pagination.html.erb +1 -0
- data/app/views/blogit/posts/_post.html.erb +19 -0
- data/app/views/blogit/posts/_post_body.html.erb +1 -0
- data/app/views/blogit/posts/_post_head.html.erb +3 -0
- data/app/views/blogit/posts/_post_links.html.erb +5 -0
- data/app/views/blogit/posts/edit.html.erb +3 -0
- data/app/views/blogit/posts/index.html.erb +10 -0
- data/app/views/blogit/posts/new.html.erb +3 -0
- data/app/views/blogit/posts/show.html.erb +7 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20110814091434_create_blog_posts.rb +12 -0
- data/db/migrate/20110814093229_create_blog_comments.rb +15 -0
- data/db/migrate/20110814103306_acts_as_taggable_on_migration.rb +28 -0
- data/lib/blogit.rb +24 -0
- data/lib/blogit/blogs.rb +19 -0
- data/lib/blogit/configuration.rb +74 -0
- data/lib/blogit/engine.rb +14 -0
- data/lib/blogit/parsers.rb +5 -0
- data/lib/blogit/parsers/html_parser.rb +9 -0
- data/lib/blogit/parsers/markdown_parser.rb +21 -0
- data/lib/blogit/parsers/textile_parser.rb +13 -0
- data/lib/blogit/version.rb +3 -0
- data/lib/generators/blogit/USAGE +8 -0
- data/lib/generators/blogit/install_generator.rb +15 -0
- data/lib/generators/templates/blogit.rb +42 -0
- data/lib/tasks/blog_tasks.rake +4 -0
- data/lib/validators.rb +3 -0
- data/lib/validators/absence_validator.rb +13 -0
- data/spec/blogit_spec.rb +20 -0
- data/spec/controllers/blogit/comments_controller_spec.rb +111 -0
- data/spec/controllers/blogit/posts_controller_spec.rb +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +3 -0
- data/spec/dummy/app/assets/stylesheets/application.css +18 -0
- data/spec/dummy/app/controllers/application_controller.rb +19 -0
- data/spec/dummy/app/controllers/people_controller.rb +83 -0
- data/spec/dummy/app/controllers/sessions_controller.rb +23 -0
- data/spec/dummy/app/controllers/users_controller.rb +83 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/people_helper.rb +2 -0
- data/spec/dummy/app/helpers/sessions_helper.rb +2 -0
- data/spec/dummy/app/helpers/users_helper.rb +2 -0
- data/spec/dummy/app/models/person.rb +2 -0
- data/spec/dummy/app/models/user.rb +11 -0
- data/spec/dummy/app/views/layouts/application.html.erb +28 -0
- data/spec/dummy/app/views/people/_form.html.erb +21 -0
- data/spec/dummy/app/views/people/edit.html.erb +6 -0
- data/spec/dummy/app/views/people/index.html.erb +23 -0
- data/spec/dummy/app/views/people/new.html.erb +5 -0
- data/spec/dummy/app/views/people/show.html.erb +10 -0
- data/spec/dummy/app/views/sessions/new.html.erb +17 -0
- data/spec/dummy/app/views/users/_form.html.erb +25 -0
- data/spec/dummy/app/views/users/edit.html.erb +6 -0
- data/spec/dummy/app/views/users/index.html.erb +25 -0
- data/spec/dummy/app/views/users/new.html.erb +5 -0
- data/spec/dummy/app/views/users/show.html.erb +15 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +25 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +51 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/blogit.rb +40 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +11 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20110814091304_create_users.rb +10 -0
- data/spec/dummy/db/migrate/20110819103335_create_people.rb +9 -0
- data/spec/dummy/db/schema.rb +71 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +21145 -0
- data/spec/dummy/log/test.log +32053 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/test/fixtures/people.yml +7 -0
- data/spec/dummy/test/fixtures/users.yml +9 -0
- data/spec/dummy/test/functional/people_controller_test.rb +49 -0
- data/spec/dummy/test/functional/sessions_controller_test.rb +9 -0
- data/spec/dummy/test/functional/users_controller_test.rb +49 -0
- data/spec/dummy/test/unit/helpers/people_helper_test.rb +4 -0
- data/spec/dummy/test/unit/helpers/sessions_helper_test.rb +4 -0
- data/spec/dummy/test/unit/helpers/users_helper_test.rb +4 -0
- data/spec/dummy/test/unit/person_test.rb +7 -0
- data/spec/dummy/test/unit/user_test.rb +7 -0
- data/spec/dummy/tmp/cache/assets/BC4/870/sprockets%2F64a399278031122c8576726e146081d5 +0 -0
- data/spec/dummy/tmp/cache/assets/C49/710/sprockets%2F8a389a2323475a7053fc419c4103814f +0 -0
- data/spec/dummy/tmp/cache/assets/C9E/F00/sprockets%2Fdbb1755717649d42fe9df99326657618 +0 -0
- data/spec/dummy/tmp/cache/assets/CAA/0C0/sprockets%2Feec4505e23136c45e543a609b0c69554 +0 -0
- data/spec/dummy/tmp/cache/assets/CDE/240/sprockets%2Fcf7da81f64139020d3a4a78f904609c4 +0 -0
- data/spec/dummy/tmp/cache/assets/CEF/560/sprockets%2Fa1bf08ab120c72351b460a65e4800af6 +0 -0
- data/spec/dummy/tmp/cache/assets/CF0/1D0/sprockets%2F6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/spec/dummy/tmp/cache/assets/D08/D50/sprockets%2F36daa544802ddf93249b8d07dab81125 +0 -0
- data/spec/dummy/tmp/cache/assets/D0A/410/sprockets%2F7e74a40717d2324f9a30ddff29ea5124 +0 -0
- data/spec/dummy/tmp/cache/assets/D0E/C00/sprockets%2F3091a34f307d562f44ee24f4c776baa9 +0 -0
- data/spec/dummy/tmp/cache/assets/D0F/180/sprockets%2F1ea0059d1fca1d25898ff37c7c150944 +0 -0
- data/spec/dummy/tmp/cache/assets/D10/610/sprockets%2F5883b6e94dcea7e32d57de13201563c3 +0 -0
- data/spec/dummy/tmp/cache/assets/D11/D20/sprockets%2Fcac21eac42152981882bf9e489316af4 +0 -0
- data/spec/dummy/tmp/cache/assets/D1F/730/sprockets%2F2f81ed50f6f293b326c576a8528ce9f3 +0 -0
- data/spec/dummy/tmp/cache/assets/D22/380/sprockets%2Fda1670e413fe4633d84eb9394fd7797c +0 -0
- data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/D33/240/sprockets%2Ffd4446a4ab97006a073ba30d57fdd617 +0 -0
- data/spec/dummy/tmp/cache/assets/D34/140/sprockets%2F0d8b2740eca50a83fc91e51292f9f00c +0 -0
- data/spec/dummy/tmp/cache/assets/D34/680/sprockets%2Fb2cb3891a4cb197ecb1a37299d14c531 +0 -0
- data/spec/dummy/tmp/cache/assets/D3C/3A0/sprockets%2F40c65286b76c2cbc9d2bd92a60e7f126 +0 -0
- data/spec/dummy/tmp/cache/assets/D3D/C40/sprockets%2F4654852579bc0bea406bcd54d38a7dc3 +0 -0
- data/spec/dummy/tmp/cache/assets/D46/650/sprockets%2Ff56253b5f374fff1a33fbbc9881c9124 +0 -0
- data/spec/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +0 -0
- data/spec/dummy/tmp/cache/assets/D58/1E0/sprockets%2Fdd863e40bd669f77bb549b257d88d6b5 +0 -0
- data/spec/dummy/tmp/cache/assets/D61/6F0/sprockets%2F02da53eeca228bcef0c49278517111fe +0 -0
- data/spec/dummy/tmp/cache/assets/D63/720/sprockets%2Fe625e6b0d13c0bd8ca548a48e1d4508b +0 -0
- data/spec/dummy/tmp/cache/assets/D70/D70/sprockets%2Fc9ac544160bbcc29d775b54ca8f0269f +0 -0
- data/spec/dummy/tmp/cache/assets/D73/220/sprockets%2F3dbc0a37f98fb43ec819b85a64d32c55 +0 -0
- data/spec/dummy/tmp/cache/assets/D7A/BD0/sprockets%2Ff645c87585af5bf4be27a271f20b39ff +0 -0
- data/spec/dummy/tmp/cache/assets/D80/960/sprockets%2F269feebf3271f38b09bd01e9b748f77d +0 -0
- data/spec/dummy/tmp/cache/assets/D82/800/sprockets%2F72f633d76779cbfb7d9a57b5623c3faf +0 -0
- data/spec/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +0 -0
- data/spec/dummy/tmp/cache/assets/D8D/EA0/sprockets%2Fe64949cb167a0aa27a33a1adf1d544be +0 -0
- data/spec/dummy/tmp/cache/assets/DCA/9B0/sprockets%2Fdf0e8f8a85e5d4056b3fe1cec3b7131a +0 -0
- data/spec/dummy/tmp/cache/assets/DF3/BA0/sprockets%2Ffddeae525be5a563ca0d194b614bf64b +0 -0
- data/spec/dummy/tmp/cache/assets/DFF/B40/sprockets%2Fe0d60af9df95b2a58c278acd3f2beb55 +0 -0
- data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/E0A/870/sprockets%2Fbba31cc2875be0fddf5901fef9b99e48 +0 -0
- data/spec/dummy/tmp/cache/assets/E27/590/sprockets%2F097d2347f3f9d2ec19abefaaa5dd0ec1 +0 -0
- data/spec/dummy/tmp/cache/assets/E30/DC0/sprockets%2F9ddd7093ee1d47cbacd526f4bdd36e3c +0 -0
- data/spec/dummy/tmp/cache/assets/E49/530/sprockets%2F10dadda372ee79deb251d7bbbb025cec +0 -0
- data/spec/dummy/tmp/cache/assets/E82/4C0/sprockets%2F0d49c3fa07b559dbecbaabf2a4bad9c8 +0 -0
- data/spec/dummy/tmp/pids/server.pid +1 -0
- data/spec/factories.rb +28 -0
- data/spec/helpers/blogit/application_helper_spec.rb +14 -0
- data/spec/helpers/blogit/posts_helper_spec.rb +34 -0
- data/spec/lib/blogs_spec.rb +23 -0
- data/spec/lib/configuration_spec.rb +57 -0
- data/spec/lib/parsers/html_parser_spec.rb +12 -0
- data/spec/lib/parsers/markdown_parser_spec.rb +12 -0
- data/spec/lib/parsers/textile_parser_spec.rb +12 -0
- data/spec/models/blogit/comment_spec.rb +64 -0
- data/spec/models/blogit/post_spec.rb +153 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/authentication.rb +9 -0
- data/spec/support/configuration.rb +5 -0
- metadata +415 -0
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2011 YOURNAME
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
begin
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
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
|
+
|
|
23
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
|
24
|
+
load 'rails/tasks/engine.rake'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
Bundler::GemHelper.install_tasks
|
|
28
|
+
|
|
29
|
+
require 'rake/testtask'
|
|
30
|
+
|
|
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
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
task :default => :test
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#new_blog_comment{
|
|
2
|
+
width: 600px;
|
|
3
|
+
margin: 0 auto;
|
|
4
|
+
}
|
|
5
|
+
#new_blog_comment .hidden {
|
|
6
|
+
display: none;
|
|
7
|
+
}
|
|
8
|
+
.blog_comment{
|
|
9
|
+
width: 600px;
|
|
10
|
+
margin: 1em auto;
|
|
11
|
+
padding: 0 0 1em;
|
|
12
|
+
border-bottom: thin solid silver;
|
|
13
|
+
}
|
|
14
|
+
.blog_comment .actions, .blog_post .actions{
|
|
15
|
+
text-align: right;
|
|
16
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
article.blog_post {
|
|
2
|
+
width: 600px;
|
|
3
|
+
margin: 0 auto;
|
|
4
|
+
}
|
|
5
|
+
.blog_post header h1 a{
|
|
6
|
+
text-decoration: none;
|
|
7
|
+
color: #55D;
|
|
8
|
+
}
|
|
9
|
+
.blog_post p{
|
|
10
|
+
line-height: 1.6em;
|
|
11
|
+
}
|
|
12
|
+
.blog_post_comments_count{
|
|
13
|
+
margin: 1em 0;
|
|
14
|
+
text-align: right;
|
|
15
|
+
}
|
|
16
|
+
.blog_post_spacer{
|
|
17
|
+
width: 80%;
|
|
18
|
+
margin: 1em auto;
|
|
19
|
+
border-color: thin solid silver;
|
|
20
|
+
border-top: none;
|
|
21
|
+
}
|
|
22
|
+
.blog_post_footer, footer{
|
|
23
|
+
font-size: 0.8em;
|
|
24
|
+
font-style: italic;
|
|
25
|
+
color: silver;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
#new_blogit_post_link{
|
|
29
|
+
text-align: right;
|
|
30
|
+
}
|
|
31
|
+
#new_blogit_post, .edit_blogit_post{
|
|
32
|
+
width: 100%;
|
|
33
|
+
}
|
|
34
|
+
#post_title, #post_body{
|
|
35
|
+
width: 100%;
|
|
36
|
+
}
|
|
37
|
+
.new_blog_post fieldset{
|
|
38
|
+
border: none;
|
|
39
|
+
padding: 0;
|
|
40
|
+
margin: 0;
|
|
41
|
+
}
|
|
42
|
+
.new_blog_post input,.new_blog_post textarea{
|
|
43
|
+
font-size: 17px;
|
|
44
|
+
}
|
|
45
|
+
.new_blog_post .blog_post_tip{
|
|
46
|
+
margin: 0;
|
|
47
|
+
float: right;
|
|
48
|
+
width: 55%;
|
|
49
|
+
text-align: right;
|
|
50
|
+
color: #333;
|
|
51
|
+
font-style: italic;
|
|
52
|
+
}
|
|
53
|
+
#new_blog_post_tag_field{
|
|
54
|
+
float: left;
|
|
55
|
+
width: 40%;
|
|
56
|
+
}
|
|
57
|
+
.new_blog_post .actions{
|
|
58
|
+
margin: 1em 0;
|
|
59
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Blogit
|
|
2
|
+
|
|
3
|
+
# Inherits from the application's controller instead of ActionController::Base
|
|
4
|
+
class ApplicationController < ::ApplicationController
|
|
5
|
+
|
|
6
|
+
helper :all
|
|
7
|
+
helper_method :current_blogger, :blogit_conf
|
|
8
|
+
|
|
9
|
+
# Sets a class method to specify a before-filter calling
|
|
10
|
+
# whatever Blogit.configuration.authentication_method is set to
|
|
11
|
+
# Accepts the usual before_filter optionss
|
|
12
|
+
def self.blogit_authenticate(options ={})
|
|
13
|
+
before_filter blogit_conf.authentication_method, options
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# A helper method to access the Blogit::configuration
|
|
17
|
+
# at the class level
|
|
18
|
+
def self.blogit_conf
|
|
19
|
+
Blogit::configuration
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# A helper method to access the Blogit::configuration
|
|
23
|
+
# at the controller instance level
|
|
24
|
+
def blogit_conf
|
|
25
|
+
self.class.blogit_conf
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Returns the currently logged in blogger by calling
|
|
29
|
+
# whatever Blogit.current_blogger_method is set to
|
|
30
|
+
def current_blogger
|
|
31
|
+
send blogit_conf.current_blogger_method
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Returns true if the current_blogger is the owner of the post
|
|
35
|
+
# @param post An instance of Blogit::Post
|
|
36
|
+
def this_blogger?(post)
|
|
37
|
+
current_blogger == post.blogger
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module Blogit
|
|
2
|
+
class CommentsController < ApplicationController
|
|
3
|
+
|
|
4
|
+
blogit_authenticate except: [:create]
|
|
5
|
+
|
|
6
|
+
expose(:post) { Blogit::Post.find(params[:post_id]) }
|
|
7
|
+
expose(:comments) { post.comments }
|
|
8
|
+
expose(:comment) {
|
|
9
|
+
case params[:action]
|
|
10
|
+
when /create/ then comments.new(params[:comment])
|
|
11
|
+
when /destroy/ then comments.find(params[:id])
|
|
12
|
+
end
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def create
|
|
17
|
+
respond_to do |format|
|
|
18
|
+
format.js {
|
|
19
|
+
# the rest is dealt with in the view
|
|
20
|
+
comment.save
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
format.html {
|
|
24
|
+
if comment.save
|
|
25
|
+
redirect_to(post, notice: "Successfully added comment!")
|
|
26
|
+
else
|
|
27
|
+
render "blogit/posts/show"
|
|
28
|
+
end
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def destroy
|
|
36
|
+
comment.destroy
|
|
37
|
+
respond_to do |format|
|
|
38
|
+
format.html { redirect_to(post, notice: "Successfully removed comment.") }
|
|
39
|
+
format.js
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module Blogit
|
|
2
|
+
class PostsController < ApplicationController
|
|
3
|
+
|
|
4
|
+
blogit_authenticate(except: [:index, :show])
|
|
5
|
+
|
|
6
|
+
expose(:posts) { Post.for_index(params[:page]) }
|
|
7
|
+
expose(:post) do
|
|
8
|
+
case action_name
|
|
9
|
+
when /new|create/
|
|
10
|
+
current_blogger.blog_posts.new(params[:post])
|
|
11
|
+
when /edit|update|destroy/
|
|
12
|
+
current_blogger.blog_posts.find(params[:id])
|
|
13
|
+
when /show/
|
|
14
|
+
Blogit::Post.find(params[:id])
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
expose(:comments) { post.comments }
|
|
19
|
+
expose(:comment) { post.comments.build }
|
|
20
|
+
|
|
21
|
+
def index
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def show
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def new
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def edit
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def create
|
|
34
|
+
if post.save
|
|
35
|
+
redirect_to post, notice: 'Blog post was successfully created.'
|
|
36
|
+
else
|
|
37
|
+
render action: "new"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def update
|
|
42
|
+
if post.update_attributes(params[:post])
|
|
43
|
+
redirect_to post, notice: 'Blog post was successfully updated.'
|
|
44
|
+
else
|
|
45
|
+
render action: "edit"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def destroy
|
|
50
|
+
post.destroy
|
|
51
|
+
redirect_to posts_url, notice: "Blog post was successfully destroyed."
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module Blogit
|
|
2
|
+
module ApplicationHelper
|
|
3
|
+
|
|
4
|
+
TIMETAG_FORMAT = "%Y-%m-%dT%TZ"
|
|
5
|
+
|
|
6
|
+
# Returns the first error message for an ActiveRecord model instance
|
|
7
|
+
# @param object A model instance to check
|
|
8
|
+
# @param attribute A symbol or string for attribute name to check for
|
|
9
|
+
# errors
|
|
10
|
+
def errors_on(object, attribute)
|
|
11
|
+
object.errors[attribute].first.to_s
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# A helper method for creating a +<div>+ tag with class 'field'
|
|
15
|
+
# Used for separating form fields
|
|
16
|
+
def field(content_or_options={}, options ={}, &block)
|
|
17
|
+
div_with_default_class(:field, content_or_options, options, &block)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# A helper method for creating a +<div>+ tag with class 'actions'
|
|
21
|
+
# Used for option links and form buttons
|
|
22
|
+
def actions(content_or_options={}, options ={}, &block)
|
|
23
|
+
div_with_default_class(:actions, content_or_options, options, &block)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# A helper method for creating a +<div>+ tag with class 'login_required'
|
|
27
|
+
# Will only render content if there is a logged in user
|
|
28
|
+
def login_required(content_or_options={}, options ={}, &block)
|
|
29
|
+
div_with_default_class(:login_required, content_or_options, options, &block) if current_blogger
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Returns an HTML 5 time tag
|
|
33
|
+
# @param time_object Any Time or DateTime object
|
|
34
|
+
# @param format [String, Symbol] If passed a string will treat as a strftime format.
|
|
35
|
+
# If passed a symbol will treat as pre-set datetime format.
|
|
36
|
+
def time_tag(time_object, format = nil, options ={})
|
|
37
|
+
# if there's a specified format and it's a string, assume it's an strftime string
|
|
38
|
+
if format && format.is_a?(String)
|
|
39
|
+
time_string = time_object.strftime(format)
|
|
40
|
+
# if there's a specified format and it's a symbol, assume it's a predefined format
|
|
41
|
+
elsif format && format.is_a?(Symbol)
|
|
42
|
+
time_string = time_object.to_s(format)
|
|
43
|
+
else
|
|
44
|
+
time_string = time_object.to_s
|
|
45
|
+
end
|
|
46
|
+
options.merge(datetime: time_object.strftime(TIMETAG_FORMAT))
|
|
47
|
+
content_tag(:time, time_string, options)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def div_with_default_class(default_class, content_or_options={}, options={}, &block)
|
|
53
|
+
if block_given?
|
|
54
|
+
content = capture(&block)
|
|
55
|
+
options = content_or_options
|
|
56
|
+
else
|
|
57
|
+
content = content_or_options
|
|
58
|
+
end
|
|
59
|
+
options[:class] = "#{default_class} #{options[:class]}".strip
|
|
60
|
+
content_tag(:div, content, options)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Blogit
|
|
2
|
+
module CommentsHelper
|
|
3
|
+
|
|
4
|
+
# Creates a div tag with class 'blog_comment_' + name
|
|
5
|
+
# Eg:
|
|
6
|
+
# blog_comment_tag(:email, "") # => <div class="blog_comment_email"></div>
|
|
7
|
+
def blog_comment_tag(name, content_or_options = {}, options ={}, &block)
|
|
8
|
+
if block_given?
|
|
9
|
+
content = capture(&block)
|
|
10
|
+
options = content_or_options
|
|
11
|
+
else
|
|
12
|
+
content = content_or_options
|
|
13
|
+
end
|
|
14
|
+
options[:class] = "#{options[:class]} blog_comment_#{name}".strip
|
|
15
|
+
content_tag(name, content, options)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Blogit
|
|
2
|
+
module PostsHelper
|
|
3
|
+
|
|
4
|
+
# Format content using the {Blogit::Configuration#default_parser_class default_parser_class}
|
|
5
|
+
def format_content(content = nil, &block)
|
|
6
|
+
content = capture(&block) if block_given?
|
|
7
|
+
parser = Blogit::configuration.default_parser_class.new(content)
|
|
8
|
+
parser.parsed.html_safe
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Creates a div tag with class 'blog_post_' + name
|
|
12
|
+
# Eg:
|
|
13
|
+
# blog_post_tag(:title, "") # => <div class="blog_post_title"></div>
|
|
14
|
+
def blog_post_tag(name, content_or_options = {}, options ={}, &block)
|
|
15
|
+
if block_given?
|
|
16
|
+
content = capture(&block)
|
|
17
|
+
options = content_or_options
|
|
18
|
+
else
|
|
19
|
+
content = content_or_options
|
|
20
|
+
end
|
|
21
|
+
options[:class] = "#{options[:class]} blog_post_#{name}".strip
|
|
22
|
+
content_tag(name, content, options)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module Blogit
|
|
2
|
+
class Comment < ActiveRecord::Base
|
|
3
|
+
|
|
4
|
+
self.table_name = "blog_comments"
|
|
5
|
+
|
|
6
|
+
# ================
|
|
7
|
+
# = Associations =
|
|
8
|
+
# ================
|
|
9
|
+
|
|
10
|
+
belongs_to :post, class_name: "Blogit::Post", foreign_key: "post_id", counter_cache: true
|
|
11
|
+
|
|
12
|
+
# TODO: Check if this is optimal
|
|
13
|
+
URL_REGEX = /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
|
|
14
|
+
|
|
15
|
+
# TODO: Check if this is optimal
|
|
16
|
+
EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
|
|
17
|
+
|
|
18
|
+
# ============
|
|
19
|
+
# = Callbacks =
|
|
20
|
+
# ============
|
|
21
|
+
|
|
22
|
+
before_validation :format_website
|
|
23
|
+
|
|
24
|
+
# ==============
|
|
25
|
+
# = Attributes =
|
|
26
|
+
# ==============
|
|
27
|
+
|
|
28
|
+
# nickname acts as a "honeypot" to catch spam
|
|
29
|
+
# the form field should be hidden using CSS and so
|
|
30
|
+
# if present, must be spam.
|
|
31
|
+
#
|
|
32
|
+
# @attribute
|
|
33
|
+
attr_accessor :nickname
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# ===============
|
|
37
|
+
# = Validations =
|
|
38
|
+
# ===============
|
|
39
|
+
|
|
40
|
+
# nickname acts as a "honeypot" to catch spam
|
|
41
|
+
# the form field should be hidden using CSS and so
|
|
42
|
+
# if present, must be spam.
|
|
43
|
+
validates :nickname, absence: true
|
|
44
|
+
validates :name, presence: true
|
|
45
|
+
validates :email, presence: true, format: {with: EMAIL_REGEX, allow_blank: true }
|
|
46
|
+
validates :body, presence: true, length: { minimum: 4, allow_blank: true}
|
|
47
|
+
validates :website, format: {with: URL_REGEX, allow_blank: true}
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
# Prepend http to the url before the validation check
|
|
52
|
+
def format_website
|
|
53
|
+
if self.website.present? and self.website !~ /^http/i
|
|
54
|
+
self.website = "http://#{self.website}"
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
end
|