comfy_blog 1.12.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -15
  3. data/Gemfile +7 -6
  4. data/LICENSE +1 -1
  5. data/README.md +14 -9
  6. data/Rakefile +1 -32
  7. data/app/controllers/comfy/admin/blog/posts_controller.rb +26 -22
  8. data/app/controllers/comfy/blog/posts_controller.rb +31 -38
  9. data/app/models/comfy/blog/post.rb +34 -36
  10. data/app/views/comfy/admin/blog/partials/_navigation.html.haml +4 -6
  11. data/app/views/comfy/admin/blog/posts/_form.html.haml +23 -11
  12. data/app/views/comfy/admin/blog/posts/edit.html.haml +2 -2
  13. data/app/views/comfy/admin/blog/posts/index.html.haml +29 -25
  14. data/app/views/comfy/admin/blog/posts/new.html.haml +2 -2
  15. data/app/views/comfy/blog/posts/index.html.haml +25 -10
  16. data/app/views/comfy/blog/posts/index.rss.builder +12 -12
  17. data/app/views/layouts/comfy/blog/application.html.erb +22 -0
  18. data/comfy_blog.gemspec +3 -1
  19. data/config/application.rb +13 -7
  20. data/config/blog_routes.rb +2 -2
  21. data/config/environments/development.rb +37 -4
  22. data/config/environments/test.rb +13 -4
  23. data/config/initializers/comfy_blog.rb +3 -7
  24. data/config/locales/cs.yml +38 -0
  25. data/config/locales/da.yml +38 -0
  26. data/config/locales/de.yml +38 -0
  27. data/config/locales/en.yml +38 -0
  28. data/config/locales/es.yml +38 -0
  29. data/config/locales/fr.yml +38 -0
  30. data/config/locales/it.yml +38 -0
  31. data/config/locales/ja.yml +38 -0
  32. data/config/locales/nb.yml +38 -0
  33. data/config/locales/nl.yml +38 -0
  34. data/config/locales/pl.yml +38 -0
  35. data/config/locales/pt-BR.yml +38 -0
  36. data/config/locales/ru.yml +38 -0
  37. data/config/locales/sv.yml +38 -0
  38. data/config/locales/tr.yml +38 -0
  39. data/config/locales/uk.yml +38 -0
  40. data/config/locales/zh-CN.yml +38 -0
  41. data/config/locales/zh-TW.yml +38 -0
  42. data/config/storage.yml +35 -0
  43. data/db/migrate/00_create_cms.rb +144 -116
  44. data/db/migrate/01_create_blog.rb +15 -43
  45. data/lib/comfy_blog/configuration.rb +9 -9
  46. data/lib/comfy_blog/engine.rb +7 -7
  47. data/lib/comfy_blog/routes/blog.rb +12 -13
  48. data/lib/comfy_blog/routes/blog_admin.rb +7 -12
  49. data/lib/comfy_blog/version.rb +1 -1
  50. data/lib/generators/comfy/blog/blog_generator.rb +16 -14
  51. data/test/controllers/comfy/admin/blog/posts_controller_test.rb +83 -59
  52. data/test/controllers/comfy/blog/posts_controller_test.rb +56 -42
  53. data/test/fixtures/comfy/blog/posts.yml +3 -4
  54. data/test/fixtures/comfy/cms/layouts.yml +10 -0
  55. data/test/fixtures/comfy/cms/sites.yml +1 -1
  56. data/test/fixtures/generators/blog/routes.rb +2 -3
  57. data/test/gemfiles/Gemfile.rails.5.2 +22 -0
  58. data/test/generators/blog_generator_test.rb +7 -7
  59. data/test/integration/i18n_test.rb +37 -0
  60. data/test/lib/configuration_test.rb +4 -5
  61. data/test/models/posts_test.rb +35 -30
  62. data/test/test_helper.rb +40 -29
  63. metadata +29 -35
  64. data/app/controllers/comfy/admin/blog/base_controller.rb +0 -12
  65. data/app/controllers/comfy/admin/blog/blogs_controller.rb +0 -51
  66. data/app/controllers/comfy/admin/blog/comments_controller.rb +0 -33
  67. data/app/controllers/comfy/blog/base_controller.rb +0 -33
  68. data/app/controllers/comfy/blog/comments_controller.rb +0 -33
  69. data/app/models/comfy/blog/blog.rb +0 -31
  70. data/app/models/comfy/blog/comment.rb +0 -29
  71. data/app/views/comfy/admin/blog/blogs/_form.html.haml +0 -11
  72. data/app/views/comfy/admin/blog/blogs/edit.html.haml +0 -5
  73. data/app/views/comfy/admin/blog/blogs/index.html.haml +0 -26
  74. data/app/views/comfy/admin/blog/blogs/new.html.haml +0 -5
  75. data/app/views/comfy/admin/blog/comments/_comment.html.haml +0 -17
  76. data/app/views/comfy/admin/blog/comments/index.html.haml +0 -17
  77. data/app/views/comfy/admin/blog/comments/toggle_publish.js.erb +0 -1
  78. data/app/views/comfy/blog/comments/_form.html.haml +0 -10
  79. data/app/views/comfy/blog/posts/show.html.haml +0 -18
  80. data/app/views/layouts/comfy/blog/application.html.haml +0 -7
  81. data/config/initializers/secret_token.rb +0 -15
  82. data/test/controllers/comfy/admin/blog/blogs_controller_test.rb +0 -94
  83. data/test/controllers/comfy/admin/blog/comments_controller_test.rb +0 -57
  84. data/test/controllers/comfy/blog/comments_controller_test.rb +0 -36
  85. data/test/fixtures/comfy/blog/blogs.yml +0 -7
  86. data/test/fixtures/comfy/blog/comments.yml +0 -6
  87. data/test/gemfiles/Gemfile.rails.4.0 +0 -10
  88. data/test/gemfiles/Gemfile.rails.4.1 +0 -10
  89. data/test/gemfiles/Gemfile.rails.4.2 +0 -10
  90. data/test/gemfiles/Gemfile.rails.master +0 -10
  91. data/test/models/blog_test.rb +0 -59
  92. data/test/models/comments_test.rb +0 -45
@@ -1,12 +0,0 @@
1
- class Comfy::Admin::Blog::BaseController < Comfy::Admin::Cms::BaseController
2
-
3
- protected
4
-
5
- def load_blog
6
- @blog = @site.blogs.find(params[:blog_id] || params[:id])
7
- rescue ActiveRecord::RecordNotFound
8
- flash[:error] = 'Blog not found'
9
- redirect_to comfy_admin_blogs_path(@site)
10
- end
11
-
12
- end
@@ -1,51 +0,0 @@
1
- class Comfy::Admin::Blog::BlogsController < Comfy::Admin::Blog::BaseController
2
-
3
- before_action :build_blog, :only => [:new, :create]
4
- before_action :load_blog, :only => [:edit, :update, :destroy]
5
-
6
- def index
7
- @blogs = comfy_paginate(@site.blogs)
8
- end
9
-
10
- def new
11
- render
12
- end
13
-
14
- def edit
15
- render
16
- end
17
-
18
- def create
19
- @blog.save!
20
- flash[:success] = 'Blog created'
21
- redirect_to :action => :edit, :id => @blog
22
- rescue ActiveRecord::RecordInvalid
23
- flash.now[:error] = 'Failed to create Blog'
24
- render :action => :new
25
- end
26
-
27
- def update
28
- @blog.update_attributes!(blog_params)
29
- flash[:success] = 'Blog updated'
30
- redirect_to :action => :edit, :id => @blog
31
- rescue ActiveRecord::RecordInvalid
32
- flash.now[:error] = 'Failed to update Blog'
33
- render :action => :edit
34
- end
35
-
36
- def destroy
37
- @blog.destroy
38
- flash[:success] = 'Blog deleted'
39
- redirect_to :action => :index
40
- end
41
-
42
- protected
43
-
44
- def build_blog
45
- @blog = @site.blogs.new(blog_params)
46
- end
47
-
48
- def blog_params
49
- params.fetch(:blog, {}).permit!
50
- end
51
- end
@@ -1,33 +0,0 @@
1
- class Comfy::Admin::Blog::CommentsController < Comfy::Admin::Blog::BaseController
2
-
3
- before_action :load_blog
4
- before_action :load_comment, :only => [:destroy, :toggle_publish]
5
-
6
- def index
7
- @comments = if @post = @blog.posts.where(:id => params[:post_id]).first
8
- comfy_paginate(@post.comments)
9
- else
10
- comfy_paginate(@blog.comments)
11
- end
12
- end
13
-
14
- def destroy
15
- @comment.destroy
16
- flash[:success] = 'Comment deleted'
17
- redirect_to :action => :index
18
- end
19
-
20
- def toggle_publish
21
- @comment.update_attribute(:is_published, !@comment.is_published?)
22
- end
23
-
24
- protected
25
-
26
- def load_comment
27
- @comment = @blog.comments.find(params[:id])
28
- rescue ActiveRecord::RecordNotFound
29
- flash[:error] = 'Comment not found'
30
- redirect_to :action => :index
31
- end
32
-
33
- end
@@ -1,33 +0,0 @@
1
- class Comfy::Blog::BaseController < Comfy::Cms::BaseController
2
-
3
- include Comfy::Paginate
4
-
5
- layout :set_blog_layout
6
-
7
- before_action :load_blog
8
-
9
- protected
10
-
11
- def load_cms_site
12
- super
13
- if @cms_site.path.blank? && params[:cms_path].present?
14
- raise ActionController::RoutingError.new('Site Not Found')
15
- end
16
- end
17
-
18
- def load_blog
19
- @blog = if @cms_site.blogs.count <= 1
20
- @cms_site.blogs.first!
21
- else
22
- @cms_site.blogs.where(:path => params[:blog_path]).first!
23
- end
24
-
25
- rescue ActiveRecord::RecordNotFound
26
- raise ActionController::RoutingError.new('Blog Not Found')
27
- end
28
-
29
- def set_blog_layout
30
- @blog.app_layout
31
- end
32
-
33
- end
@@ -1,33 +0,0 @@
1
- class Comfy::Blog::CommentsController < Comfy::Blog::BaseController
2
-
3
- before_action :load_post,
4
- :build_comment
5
-
6
- def create
7
- @comment.save!
8
-
9
- flash[:success] = 'Comment created'
10
- redirect_to comfy_blog_post_path(@cms_site.path, @blog.path, @post.slug)
11
-
12
- rescue ActiveRecord::RecordInvalid
13
- flash[:error] = 'Failed to create Comment'
14
- render 'comfy/blog/posts/show'
15
- end
16
-
17
- protected
18
-
19
- def load_post
20
- @post = @blog.posts.published.where(:slug => params[:slug]).first!
21
- rescue ActiveRecord::RecordNotFound
22
- flash[:error] = 'Blog Post not found'
23
- redirect_to comfy_blog_posts_path(@cms_site.path, @blog.path)
24
- end
25
-
26
- def build_comment
27
- @comment = @post.comments.new(comment_params)
28
- end
29
-
30
- def comment_params
31
- params.fetch(:comment, {}).permit(:author, :email, :content)
32
- end
33
- end
@@ -1,31 +0,0 @@
1
- class Comfy::Blog::Blog < ActiveRecord::Base
2
-
3
- self.table_name = 'comfy_blogs'
4
-
5
- # -- Relationhips ---------------------------------------------------------
6
- belongs_to :site, :class_name => 'Comfy::Cms::Site'
7
-
8
- has_many :posts,
9
- :dependent => :destroy
10
- has_many :comments,
11
- :through => :posts
12
-
13
- # -- Validations ----------------------------------------------------------
14
- validates :site_id, :label, :identifier,
15
- :presence => true
16
- validates :identifier,
17
- :format => { :with => /\A\w[a-z0-9_-]*\z/i }
18
- validates :path,
19
- :uniqueness => { :scope => :site_id },
20
- :format => { :with => /\A\w[a-z0-9_-]*\z/i },
21
- :presence => true,
22
- :if => 'restricted_path?'
23
-
24
- protected
25
-
26
- def restricted_path?
27
- (self.class.count > 1 && self.persisted?) ||
28
- (self.class.count >= 1 && self.new_record?)
29
- end
30
-
31
- end
@@ -1,29 +0,0 @@
1
- class Comfy::Blog::Comment < ActiveRecord::Base
2
-
3
- self.table_name = 'comfy_blog_comments'
4
-
5
- # -- Relationships --------------------------------------------------------
6
- belongs_to :post
7
-
8
- # -- Callbacks ------------------------------------------------------------
9
- before_create :set_is_published
10
-
11
- # -- Validations ----------------------------------------------------------
12
- validates :post_id, :content, :author, :email,
13
- :presence => true
14
- validates :email,
15
- :format => { :with => /\A([\w.%-+]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }
16
-
17
- # -- Scopes ---------------------------------------------------------------
18
- scope :published, -> {
19
- where(:is_published => true)
20
- }
21
-
22
- protected
23
-
24
- def set_is_published
25
- self.is_published = ComfyBlog.config.auto_publish_comments
26
- return
27
- end
28
-
29
- end
@@ -1,11 +0,0 @@
1
- = form.text_field :label, :data => {:slugify => @blog.new_record?}
2
- = form.text_field :identifier, :data => {:slug => true}
3
- = form.text_field :path
4
-
5
- - if (options = Comfy::Cms::Layout.app_layouts_for_select).present?
6
- = form.select :app_layout, options
7
-
8
- = form.text_area :description, :class => 'short'
9
-
10
- = form.form_group :class => 'form-actions' do
11
- = form.submit :class => 'btn btn-primary'
@@ -1,5 +0,0 @@
1
- .page-header
2
- %h2 Edit Blog
3
-
4
- = comfy_form_for @blog, :as => :blog, :url => {:action => :update} do |form|
5
- = render form
@@ -1,26 +0,0 @@
1
- .page-header
2
- = link_to 'New Blog', new_comfy_admin_blog_path(@site), :class => 'btn btn-default pull-right'
3
- %h2 Blogs
4
-
5
- = comfy_paginate @blogs
6
-
7
- %table.table.table-hover.table-bordered
8
- - @blogs.each do |blog|
9
- %tr
10
- %td.main
11
- = link_to blog.label, edit_comfy_admin_blog_path(@site, blog)
12
- .item-meta
13
- = blog.identifier
14
- %br
15
- - blog_path = comfy_blog_posts_url(@site.path, blog.path)
16
- = link_to blog_path, blog_path, :target => '_blank'
17
- %td
18
- .btn-group.btn-group-sm
19
- = link_to pluralize(blog.posts.count, 'Post'), comfy_admin_blog_posts_path(@site, blog), :class => 'btn btn-info'
20
- = link_to pluralize(blog.comments.count, 'Comment'), comfy_admin_blog_comments_path(@site, blog), :class => 'btn btn-info'
21
- %td
22
- .btn-group.btn-group-sm
23
- = link_to 'Edit', edit_comfy_admin_blog_path(@site, blog), :class => 'btn btn-default'
24
- = link_to 'Delete', comfy_admin_blog_path(@site, blog), :method => :delete, :data => {:confirm => 'Are you sure?'}, :class => 'btn btn-danger'
25
-
26
- = comfy_paginate @blogs
@@ -1,5 +0,0 @@
1
- .page-header
2
- %h2 New Blog
3
-
4
- = comfy_form_for @blog, :as => :blog, :url => {:action => :create} do |form|
5
- = render form
@@ -1,17 +0,0 @@
1
- %tr{:id => dom_id(comment)}
2
- %td
3
- = link_to comment.post.title.truncate(25), comfy_admin_blog_comments_path(@site, @blog, :post_id => comment.post)
4
- %td.main
5
- = comment.author
6
- .item-meta
7
- = mail_to comment.email
8
- %br
9
- = comment.content
10
- %td
11
- = comment.created_at.to_s(:db)
12
- %td
13
- - label, css_class = comment.is_published?? ['Unpublish', 'btn-danger'] : ['Publish', 'btn-info']
14
- = link_to label, toggle_publish_comfy_admin_blog_comment_path(@site, @blog, comment), :method => :patch, :remote => true, :class => "btn btn-sm #{css_class}"
15
- %td
16
- .btn-group.btn-group-sm
17
- = link_to 'Delete', comfy_admin_blog_comment_path(@site, @blog, comment), :method => :delete, :data => {:confirm => 'Are you sure?'}, :class => 'btn btn-danger'
@@ -1,17 +0,0 @@
1
- .page-header
2
- %h2 Blog Comments
3
-
4
- = comfy_paginate @comments
5
-
6
- %table.table.table-hover
7
- %tr
8
- %th Post
9
- %th.main Comment
10
- %th Posted
11
- %th Status
12
- %th
13
-
14
- - @comments.each do |comment|
15
- = render :partial => 'comment', :object => comment
16
-
17
- = comfy_paginate @comments
@@ -1 +0,0 @@
1
- $('tr#<%= dom_id(@comment) %>').replaceWith('<%= escape_javascript(render(:partial => "comment", :object => @comment)) %>')
@@ -1,10 +0,0 @@
1
- = comfy_form_for @comment, :as => :comment, :url => comfy_blog_comments_path(@cms_site.path, @blog.path, @post.slug) do |form|
2
-
3
- -# don't need this when installed into your app
4
- = form.hidden_field :authenticity_token, :value => form_authenticity_token
5
-
6
- = form.text_field :author
7
- = form.text_field :email
8
- = form.text_area :content
9
-
10
- = form.submit 'Submit'
@@ -1,18 +0,0 @@
1
- %h1 Blog Post
2
-
3
- %h1= @post.title
4
-
5
- .author
6
- = @post.author
7
- .date
8
- = @post.published_at.to_s(:db)
9
- .content
10
- = @post.content.html_safe
11
-
12
- .comments
13
- - @post.comments.published.each do |comment|
14
- .comment
15
- .author= comment.author
16
- .content= comment.content
17
-
18
- = render :partial => 'comfy/blog/comments/form'
@@ -1,7 +0,0 @@
1
- !!!
2
- %html
3
- %head
4
- %title Comfy Blog
5
- %body
6
- = yield
7
-
@@ -1,15 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key for verifying the integrity of signed cookies.
4
- # If you change this key, all old signed cookies will become invalid!
5
-
6
- # Make sure the secret is at least 30 characters and all random,
7
- # no regular words or you'll be exposed to dictionary attacks.
8
- # You can use `rake secret` to generate a secure secret key.
9
-
10
- # Make sure your secret_key_base is kept private
11
- # if you're sharing your code publicly.
12
-
13
- if defined?(ComfyBlog::Application)
14
- ComfyBlog::Application.config.secret_key_base = 'supersecrettoken'
15
- end
@@ -1,94 +0,0 @@
1
- require_relative '../../../../test_helper'
2
-
3
- class Comfy::Admin::Blog::BlogsControllerTest < ActionController::TestCase
4
-
5
- def setup
6
- @site = comfy_cms_sites(:default)
7
- @blog = comfy_blog_blogs(:default)
8
- end
9
-
10
- def test_get_index
11
- get :index, :site_id => @site
12
- assert_response :success
13
- assert assigns(:blogs)
14
- assert_template :index
15
- end
16
-
17
- def test_get_new
18
- get :new, :site_id => @site
19
- assert_response :success
20
- assert assigns(:blog)
21
- assert_template :new
22
- assert_select "form[action='/admin/sites/#{@site.id}/blogs']"
23
- end
24
-
25
- def test_get_edit
26
- get :edit, :site_id => @site, :id => @blog
27
- assert_response :success
28
- assert assigns(:blog)
29
- assert_template :edit
30
- assert_select "form[action='/admin/sites/#{@site.id}/blogs/#{@blog.id}']"
31
- end
32
-
33
- def test_get_edit_failure
34
- get :edit, :site_id => @site, :id => 'invalid'
35
- assert_response :redirect
36
- assert_redirected_to :action => :index
37
- assert_equal 'Blog not found', flash[:error]
38
- end
39
-
40
- def test_creation
41
- assert_difference 'Comfy::Blog::Blog.count' do
42
- post :create, :site_id => @site, :blog => {
43
- :label => 'Test Blog',
44
- :identifier => 'test-blog',
45
- :path => 'test-blog',
46
- :description => 'Test Description'
47
- }
48
- blog = Comfy::Blog::Blog.last
49
- assert_response :redirect
50
- assert_redirected_to :action => :edit, :id => blog
51
- assert_equal 'Blog created', flash[:success]
52
- end
53
- end
54
-
55
- def test_creation_failure
56
- assert_no_difference 'Comfy::Blog::Blog.count' do
57
- post :create, :site_id => @site, :blog => { }
58
- assert_response :success
59
- assert_template :new
60
- assert_equal 'Failed to create Blog', flash[:error]
61
- end
62
- end
63
-
64
- def test_update
65
- put :update, :site_id => @site, :id => @blog, blog: {
66
- :label => 'Updated'
67
- }
68
- assert_response :redirect
69
- assert_redirected_to :action => :edit, :id => @blog
70
- assert_equal 'Blog updated', flash[:success]
71
- @blog.reload
72
- assert_equal 'Updated', @blog.label
73
- end
74
-
75
- def test_update_failure
76
- put :update, :site_id => @site, :id => @blog, :blog => {
77
- :label => ''
78
- }
79
- assert_response :success
80
- assert_template :edit
81
- assert_equal 'Failed to update Blog', flash[:error]
82
- @blog.reload
83
- refute_equal '', @blog.label
84
- end
85
-
86
- def test_destroy
87
- assert_difference 'Comfy::Blog::Blog.count', -1 do
88
- delete :destroy, :site_id => @site, :id => @blog
89
- assert_response :redirect
90
- assert_redirected_to :action => :index
91
- assert_equal 'Blog deleted', flash[:success]
92
- end
93
- end
94
- end