blogit 0.0.13 → 0.1.0

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.
Files changed (52) hide show
  1. data/app/assets/stylesheets/blogit/index.css +75 -3
  2. data/app/controllers/blogit/application_controller.rb +15 -1
  3. data/app/controllers/blogit/comments_controller.rb +12 -11
  4. data/app/controllers/blogit/posts_controller.rb +18 -26
  5. data/app/models/blogit/post.rb +5 -2
  6. data/app/sweepers/blogit/blogit_sweeper.rb +9 -0
  7. data/app/views/blogit/comments/_admin_links.html.erb +1 -1
  8. data/app/views/blogit/comments/_comment.html.erb +4 -3
  9. data/app/views/blogit/comments/_form.html.erb +5 -5
  10. data/app/views/blogit/comments/create.js.erb +2 -2
  11. data/app/views/blogit/comments/destroy.js.erb +1 -1
  12. data/app/views/blogit/posts/_form.html.erb +5 -5
  13. data/app/views/blogit/posts/_pagination.html.erb +1 -1
  14. data/app/views/blogit/posts/edit.html.erb +1 -1
  15. data/app/views/blogit/posts/index.html.erb +2 -2
  16. data/app/views/blogit/posts/show.html.erb +2 -2
  17. data/lib/blogit.rb +9 -1
  18. data/lib/blogit/configuration.rb +5 -1
  19. data/lib/blogit/version.rb +1 -1
  20. data/lib/generators/templates/blogit.rb +16 -14
  21. data/spec/controllers/blogit/posts_controller_spec.rb +6 -6
  22. data/spec/dummy/app/assets/javascripts/application.js +1 -1
  23. data/spec/dummy/app/controllers/sessions_controller.rb +4 -5
  24. data/spec/dummy/config/initializers/blogit.rb +20 -7
  25. data/spec/dummy/db/development.sqlite3 +0 -0
  26. data/spec/dummy/db/test.sqlite3 +0 -0
  27. data/spec/dummy/log/development.log +3595 -0
  28. data/spec/dummy/log/production.log +350 -0
  29. data/spec/dummy/log/test.log +2562 -0
  30. data/spec/dummy/tmp/cache/11C/511/http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fblogit.css%3F +0 -0
  31. data/spec/dummy/tmp/cache/32F/2C1/http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fapplication.css%3F +0 -0
  32. data/spec/dummy/tmp/cache/A67/FC0/00e6805637a9665e1a42a74d29e98005efabb763 +0 -0
  33. data/spec/dummy/tmp/cache/AF8/620/e1e89c69903e241156121a94f96b1efc3cc6cee1 +0 -0
  34. data/spec/dummy/tmp/cache/assets/CEF/560/sprockets%2Fa1bf08ab120c72351b460a65e4800af6 +0 -0
  35. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  36. data/{app/assets/stylesheets/blogit/posts.css → spec/dummy/tmp/cache/assets/D33/240/sprockets%2Ffd4446a4ab97006a073ba30d57fdd617} +0 -0
  37. data/spec/dummy/tmp/cache/assets/D4A/D70/sprockets%2F16a7df19fe9d18a2054dde377f7d4704 +0 -0
  38. data/spec/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +0 -0
  39. data/spec/dummy/tmp/cache/assets/D61/6F0/sprockets%2F02da53eeca228bcef0c49278517111fe +0 -0
  40. data/spec/dummy/tmp/cache/assets/D7B/550/sprockets%2F439d3388bfb2b3843b2d7e7fae1cd679 +0 -0
  41. data/spec/dummy/tmp/cache/assets/D82/800/sprockets%2F72f633d76779cbfb7d9a57b5623c3faf +0 -0
  42. data/spec/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +0 -0
  43. data/spec/dummy/tmp/cache/assets/DAA/EC0/sprockets%2F5ce7f7ceaea79177a501679df3ff134a +0 -0
  44. data/spec/dummy/tmp/cache/assets/DCA/9B0/sprockets%2Fdf0e8f8a85e5d4056b3fe1cec3b7131a +0 -0
  45. data/spec/dummy/tmp/cache/assets/DCB/C80/sprockets%2Fb37cd626dabfc434d8e92b5cb5d16f05 +0 -0
  46. data/spec/dummy/tmp/cache/assets/DFF/B40/sprockets%2Fe0d60af9df95b2a58c278acd3f2beb55 +0 -0
  47. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  48. data/spec/dummy/tmp/cache/assets/E0A/870/sprockets%2Fbba31cc2875be0fddf5901fef9b99e48 +0 -0
  49. data/spec/dummy/tmp/cache/assets/E30/DC0/sprockets%2F9ddd7093ee1d47cbacd526f4bdd36e3c +0 -0
  50. data/spec/lib/configuration_spec.rb +4 -1
  51. metadata +159 -30
  52. data/app/assets/stylesheets/blogit/comments.css +0 -16
@@ -1,3 +1,75 @@
1
- /*
2
- *= require_tree
3
- */
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
+ }
60
+ #new_blog_comment{
61
+ width: 600px;
62
+ margin: 0 auto;
63
+ }
64
+ #new_blog_comment .hidden {
65
+ display: none;
66
+ }
67
+ .blog_comment{
68
+ width: 600px;
69
+ margin: 1em auto;
70
+ padding: 0 0 1em;
71
+ border-bottom: thin solid silver;
72
+ }
73
+ .blog_comment .actions, .blog_post .actions{
74
+ text-align: right;
75
+ }
@@ -2,7 +2,7 @@ module Blogit
2
2
 
3
3
  # Inherits from the application's controller instead of ActionController::Base
4
4
  class ApplicationController < ::ApplicationController
5
-
5
+
6
6
  helper :all
7
7
  helper_method :current_blogger, :blogit_conf
8
8
 
@@ -19,6 +19,20 @@ module Blogit
19
19
  Blogit::configuration
20
20
  end
21
21
 
22
+ # Turns on page caching for the given actions if
23
+ # Blogit.configuration.include_admin_links is true
24
+ def self.blogit_cacher(*args)
25
+ if blogit_conf.include_admin_links
26
+ caches_page *args
27
+ end
28
+ end
29
+
30
+ def self.blogit_sweeper(*args)
31
+ if blogit_conf.include_admin_links
32
+ cache_sweeper Blogit::BlogitSweeper, only: args
33
+ end
34
+ end
35
+
22
36
  # A helper method to access the Blogit::configuration
23
37
  # at the controller instance level
24
38
  def blogit_conf
@@ -3,25 +3,19 @@ module Blogit
3
3
 
4
4
  blogit_authenticate except: [:create]
5
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
- }
6
+ blogit_sweeper(:create, :update, :destroy)
14
7
 
15
8
 
16
9
  def create
10
+ @comment = post.comments.new(params[:comment])
17
11
  respond_to do |format|
18
12
  format.js {
19
13
  # the rest is dealt with in the view
20
- comment.save
14
+ @comment.save
21
15
  }
22
16
 
23
17
  format.html {
24
- if comment.save
18
+ if @comment.save
25
19
  redirect_to(post, notice: "Successfully added comment!")
26
20
  else
27
21
  render "blogit/posts/show"
@@ -33,12 +27,19 @@ module Blogit
33
27
  end
34
28
 
35
29
  def destroy
36
- comment.destroy
30
+ @comment = post.comments.find(params[:id])
31
+ @comment.destroy
37
32
  respond_to do |format|
38
33
  format.html { redirect_to(post, notice: "Successfully removed comment.") }
39
34
  format.js
40
35
  end
41
36
  end
37
+
38
+ private
42
39
 
40
+ def post
41
+ @post ||= Blogit::Post.find(params[:post_id])
42
+ end
43
+
43
44
  end
44
45
  end
@@ -1,4 +1,5 @@
1
1
  module Blogit
2
+
2
3
  class PostsController < ApplicationController
3
4
 
4
5
  unless blogit_conf.include_admin_actions
@@ -6,62 +7,53 @@ module Blogit
6
7
  end
7
8
 
8
9
  blogit_authenticate(except: [:index, :show, :tagged])
9
-
10
- expose(:posts) {
11
- if params[:tag]
12
- Post.for_index(params[:page]).tagged_with(params[:tag])
13
- else
14
- Post.for_index(params[:page])
15
- end
16
- }
17
- expose(:post) do
18
- case action_name
19
- when /new|create/
20
- current_blogger.blog_posts.new(params[:post])
21
- when /edit|update|destroy/
22
- current_blogger.blog_posts.find(params[:id])
23
- when /show/
24
- Blogit::Post.find(params[:id])
25
- end
26
- end
27
-
28
- expose(:comments) { post.comments }
29
- expose(:comment) { post.comments.build }
10
+
11
+ blogit_cacher(:index, :show, :tagged)
12
+ blogit_sweeper(:create, :update, :destroy)
30
13
 
31
14
  def index
15
+ @posts = Post.for_index(params[:page])
32
16
  end
33
17
 
34
18
  def show
19
+ @post = Post.find(params[:id])
20
+ @comment = @post.comments.new
35
21
  end
36
22
 
37
23
  def tagged
24
+ @posts = Post.for_index(params[:page]).tagged_with(params[:tag])
38
25
  render :index
39
26
  end
40
27
 
41
28
  def new
29
+ @post = current_blogger.blog_posts.new(params[:post])
42
30
  end
43
31
 
44
32
  def edit
33
+ @post = current_blogger.blog_posts.find(params[:id])
45
34
  end
46
35
 
47
36
  def create
48
- if post.save
49
- redirect_to post, notice: 'Blog post was successfully created.'
37
+ @post = current_blogger.blog_posts.new(params[:post])
38
+ if @post.save
39
+ redirect_to @post, notice: 'Blog post was successfully created.'
50
40
  else
51
41
  render action: "new"
52
42
  end
53
43
  end
54
44
 
55
45
  def update
56
- if post.update_attributes(params[:post])
57
- redirect_to post, notice: 'Blog post was successfully updated.'
46
+ @post = current_blogger.blog_posts.find(params[:id])
47
+ if @post.update_attributes(params[:post])
48
+ redirect_to @post, notice: 'Blog post was successfully updated.'
58
49
  else
59
50
  render action: "edit"
60
51
  end
61
52
  end
62
53
 
63
54
  def destroy
64
- post.destroy
55
+ @post = current_blogger.blog_posts.find(params[:id])
56
+ @post.destroy
65
57
  redirect_to posts_url, notice: "Blog post was successfully destroyed."
66
58
  end
67
59
 
@@ -1,11 +1,14 @@
1
1
  module Blogit
2
2
  class Post < ActiveRecord::Base
3
3
 
4
+ require "acts-as-taggable-on"
5
+ require "kaminari"
6
+
4
7
  acts_as_taggable
5
8
 
6
9
  self.table_name = "blog_posts"
7
10
 
8
- paginates_per Blogit.configuration.posts_per_page
11
+ self.paginates_per Blogit.configuration.posts_per_page
9
12
 
10
13
  # ===============
11
14
  # = Validations =
@@ -31,7 +34,7 @@ module Blogit
31
34
 
32
35
  # Returns the blog posts paginated for the index page
33
36
  # @scope class
34
- scope :for_index, lambda { |page = 1| order("updated_at DESC").page(page) }
37
+ scope :for_index, lambda { |page_no = 1| order("updated_at DESC").page(page_no) }
35
38
 
36
39
  # ====================
37
40
  # = Instance Methods =
@@ -0,0 +1,9 @@
1
+ module Blogit
2
+
3
+ class BlogitSweeper < ActionController::Caching::Sweeper
4
+
5
+ observe Blogit::Post, Blogit::Comment
6
+
7
+ end
8
+
9
+ end
@@ -1,3 +1,3 @@
1
1
  <%= login_required(class: "actions") do %>
2
- <%= link_to("delete", [post, comment], method: :delete) %>
2
+ <%= link_to("delete", [@post, @comment], method: :delete) %>
3
3
  <% end %>
@@ -6,13 +6,14 @@
6
6
 
7
7
  <%= content_tag(:div, class: "blog_comment_body",
8
8
  id: "blog_comment_#{comment.id}_body") do %>
9
- <%= format_content comment.body %>
9
+ <%= format_content comment.body || "" %>
10
10
  <% end %>
11
11
 
12
12
  <%= blog_comment_tag(:footer) do %>
13
- Posted on <%= time_tag(post.created_at, Blogit.configuration.datetime_format) %>
13
+ Posted on <%= time_tag(@post.created_at, Blogit.configuration.datetime_format) %>
14
14
  <% end %>
15
15
 
16
16
  <%= render partial: "blogit/comments/admin_links" %>
17
17
 
18
- <% end %>
18
+ <% end if comment.persisted? %>
19
+
@@ -1,5 +1,5 @@
1
1
 
2
- <%= form_for [post, comment], remote: true,
2
+ <%= form_for [@post, @comment], remote: true,
3
3
  html: {
4
4
  class: "new_blog_comment", id: "new_blog_comment" } do |f| -%>
5
5
 
@@ -14,26 +14,26 @@
14
14
  <%= field do %>
15
15
  <%= f.label :name, "Name *" %><br>
16
16
  <%= f.text_field :name %>
17
- <%= errors_on(comment, :name) %>
17
+ <%= errors_on(@comment, :name) %>
18
18
  <% end %>
19
19
 
20
20
  <%= field do %>
21
21
  <%= f.label :email, "Email" %> (never displayed)<br>
22
22
  <%= f.email_field :email %>
23
- <%= errors_on(comment, :email) %>
23
+ <%= errors_on(@comment, :email) %>
24
24
  <% end %>
25
25
 
26
26
  <%= field do %>
27
27
  <%= f.label :website, "Your Website" %><br>
28
28
  <%= f.url_field :website %>
29
- <%= errors_on(comment, :website) %>
29
+ <%= errors_on(@comment, :website) %>
30
30
  <% end %>
31
31
 
32
32
 
33
33
  <%= field do %>
34
34
  <%= f.label :body, "Your comment *" %><br>
35
35
  <%= f.text_area :body %><br>
36
- <%= errors_on(comment, :body) %>
36
+ <%= errors_on(@comment, :body) %>
37
37
  <% end %>
38
38
 
39
39
  <%= actions do %>
@@ -1,6 +1,6 @@
1
1
  var $form = $("form#new_blog_comment");
2
- <% if comment.save %>
3
- $("#comments").append("<%= escape_javascript(render(comment)) %>");
2
+ <% if @comment.save %>
3
+ $("#comments").append("<%= escape_javascript(render(@comment)) %>");
4
4
  $form.get(0).reset();
5
5
  <% else %>
6
6
  $form.html("<%= escape_javascript(render('form')) %>");
@@ -1 +1 @@
1
- $("#comment_<%= comment.id %>").remove();
1
+ $("#comment_<%= @comment.id %>").remove();
@@ -1,11 +1,11 @@
1
- <%= form_for(post, html: {class: "new_blog_post", id: "new_blog_post"}) do |f| %>
1
+ <%= form_for(@post, html: {class: "new_blog_post", id: "new_blog_post"}) do |f| %>
2
2
 
3
- <% if post.errors.any? %>
3
+ <% if @post.errors.any? %>
4
4
  <div id="error_explanation">
5
- <h2><%= pluralize(post.errors.count, "error") %> prohibited this post from being saved:</h2>
5
+ <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
6
6
 
7
7
  <ul>
8
- <% post.errors.full_messages.each do |msg| %>
8
+ <% @post.errors.full_messages.each do |msg| %>
9
9
  <li><%= msg %></li>
10
10
  <% end %>
11
11
  </ul>
@@ -37,7 +37,7 @@
37
37
 
38
38
  <%= actions do %>
39
39
  <%= f.submit %> or
40
- <%= link_to("cancel", post.new_record? ? root_path : post_path(post)) %>
40
+ <%= link_to("cancel", @post.new_record? ? root_path : post_path(@post)) %>
41
41
  <% end %>
42
42
 
43
43
  <% end %>
@@ -1 +1 @@
1
- <%= paginate(posts) %>
1
+ <%= paginate(@posts) %>
@@ -1,3 +1,3 @@
1
- <h2>Edit Blog Post #<%= post.id %></h2>
1
+ <h2>Edit Blog Post #<%= @post.id %></h2>
2
2
 
3
3
  <%= render 'form' %>
@@ -2,10 +2,10 @@
2
2
  <%= link_to 'New Blog post', new_post_path %>
3
3
  <% end %>
4
4
 
5
- <% if posts.any? %>
5
+ <% if @posts.any? %>
6
6
 
7
7
  <%= render partial: "blogit/posts/post",
8
- collection: posts,
8
+ collection: @posts,
9
9
  spacer_template: "blog_post_spacer",
10
10
  locals: {show_comments_count: true} %>
11
11
  <% else %>
@@ -1,7 +1,7 @@
1
- <%= render post %>
1
+ <%= render @post %>
2
2
  <% if blogit_conf.include_comments %>
3
3
  <div id="comments">
4
- <%= render comments %>
4
+ <%= render @post.comments %>
5
5
  </div>
6
6
  <%= render "blogit/comments/form" %>
7
7
  <% end %>
data/lib/blogit.rb CHANGED
@@ -1,11 +1,19 @@
1
+ # Third-party requirements
2
+ require "acts-as-taggable-on"
3
+ require "kaminari"
4
+ require "redcarpet"
5
+
1
6
  require "blogit/configuration"
2
7
  require "blogit/blogs"
3
8
  require "blogit/engine"
4
9
  require "blogit/parsers"
5
- require "validators"
6
10
 
11
+ require "validators"
7
12
  module Blogit
8
13
 
14
+ autoload :ActsAsTaggableOn, "acts-as-taggable-on"
15
+ autoload :Kaminari, "kaminari"
16
+
9
17
  # Exception raised when gem may not be configured properly
10
18
  class ConfigurationError < StandardError;end
11
19
 
@@ -58,6 +58,9 @@ module Blogit
58
58
  # Defaults to REDCARPET_OPTIONS
59
59
  attr_accessor :redcarpet_options
60
60
 
61
+ # Should the controllers cache the blog pages as HTML?
62
+ attr_accessor :cache_pages
63
+
61
64
  REDCARPET_OPTIONS = [:hard_wrap, :filter_html, :autolink,
62
65
  :no_intraemphasis, :fenced_code, :gh_blockcode]
63
66
 
@@ -71,7 +74,8 @@ module Blogit
71
74
  @author_edits_only = false
72
75
  @ajax_comments = true
73
76
  @include_admin_actions = true
74
- @include_admin_links = true
77
+ @include_admin_links = true
78
+ @cache_pages = false
75
79
  @default_parser = :markdown
76
80
  @highlight_code_syntax = true
77
81
  @redcarpet_options = REDCARPET_OPTIONS