comfy_blog 2.0.2 → 2.0.3
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.
- checksums.yaml +4 -4
- data/.github/issue_template.md +22 -0
- data/.github/pull_request_template.md +6 -0
- data/.rubocop.yml +96 -0
- data/.travis.yml +2 -1
- data/CONTRIBUTING.md +32 -0
- data/Gemfile +8 -8
- data/README.md +1 -0
- data/Rakefile +1 -1
- data/app/controllers/comfy/admin/blog/posts_controller.rb +19 -11
- data/app/controllers/comfy/admin/blog/revisions/post_controller.rb +9 -3
- data/app/controllers/comfy/blog/posts_controller.rb +15 -12
- data/app/models/comfy/blog/post.rb +13 -12
- data/app/views/comfy/admin/blog/posts/_form.html.haml +2 -2
- data/app/views/comfy/admin/blog/posts/form_fragments.js.erb +1 -0
- data/app/views/comfy/blog/posts/index.rss.builder +4 -4
- data/bin/bundle +3 -0
- data/bin/rails +4 -0
- data/bin/rake +4 -0
- data/bin/setup +36 -0
- data/bin/update +31 -0
- data/bin/yarn +11 -0
- data/comfy_blog.gemspec +6 -6
- data/config.ru +2 -2
- data/config/application.rb +5 -4
- data/config/boot.rb +3 -3
- data/config/environment.rb +1 -1
- data/config/environments/development.rb +2 -2
- data/config/environments/test.rb +1 -1
- data/config/initializers/comfy_blog.rb +0 -2
- data/lib/comfy_blog.rb +10 -10
- data/lib/comfy_blog/configuration.rb +1 -1
- data/lib/comfy_blog/engine.rb +12 -7
- data/lib/comfy_blog/routes/blog.rb +8 -8
- data/lib/comfy_blog/routes/blog_admin.rb +5 -3
- data/lib/comfy_blog/routing.rb +2 -2
- data/lib/comfy_blog/version.rb +3 -1
- data/lib/generators/comfy/blog/blog_generator.rb +9 -9
- data/test/controllers/comfy/admin/blog/posts_controller_test.rb +53 -32
- data/test/controllers/comfy/admin/blog/revisions/post_controller_test.rb +6 -6
- data/test/controllers/comfy/blog/posts_controller_test.rb +7 -6
- data/test/gemfiles/Gemfile.rails.5.2 +5 -4
- data/test/generators/blog_generator_test.rb +7 -6
- data/test/integration/i18n_test.rb +8 -7
- data/test/lib/configuration_test.rb +4 -3
- data/test/models/posts_test.rb +12 -11
- data/test/test_helper.rb +24 -21
- metadata +15 -5
- data/script/rails +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c23d02796c11c424383ef59503f004d9d11a14a7
|
4
|
+
data.tar.gz: 2bcdbffe51266427e3598a4cb27097b1abecd76f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8973cc41e1de0ce35f3ce0e115471f5b6fb86dff10c14737693f12bc7e68d54d8e8b5e594948eda998a6b196f9a30f5ef8416ca54168e627fab1499251e1ba9
|
7
|
+
data.tar.gz: 107f15a97709acce139482c6536602c1029269f4ba90ee5b7c463bd42614c2d15f3bd446b41b52e6bc2aafc7aed5911f5fbcd84d1f5f1e4802f5829b36f9fd22
|
@@ -0,0 +1,22 @@
|
|
1
|
+
*Note:* For general questions and feature requests please leave a message
|
2
|
+
on Gitter: https://gitter.im/comfy/comfortable-mexican-sofa
|
3
|
+
|
4
|
+
### Expected behavior
|
5
|
+
Tell us what should happen
|
6
|
+
|
7
|
+
### Actual behavior
|
8
|
+
Tell us what happens instead
|
9
|
+
|
10
|
+
### Steps to reproduce
|
11
|
+
Things that help:
|
12
|
+
|
13
|
+
* Describe issue in detail.
|
14
|
+
* Add relevant code snippets.
|
15
|
+
* Create a failing test case.
|
16
|
+
|
17
|
+
### System configuration
|
18
|
+
**Rails version**:
|
19
|
+
|
20
|
+
**CMS version**:
|
21
|
+
|
22
|
+
**Ruby version**:
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.2
|
3
|
+
Exclude:
|
4
|
+
- bin/*
|
5
|
+
- db/schema.rb
|
6
|
+
- db/migrate/**/*
|
7
|
+
- test/fixtures/**/*
|
8
|
+
- tmp/**/*
|
9
|
+
|
10
|
+
# -- Performance ---------------------------------------------------------------
|
11
|
+
Performance/Casecmp:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
# -- Metrics -------------------------------------------------------------------
|
15
|
+
Metrics/PerceivedComplexity:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/MethodLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Metrics/MethodLength:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Metrics/ParameterLists:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Metrics/LineLength:
|
28
|
+
Max: 120
|
29
|
+
|
30
|
+
Metrics/CyclomaticComplexity:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Metrics/ClassLength:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Metrics/BlockLength:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Metrics/AbcSize:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
# -- Layout --------------------------------------------------------------------
|
43
|
+
Layout/MultilineOperationIndentation:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Layout/MultilineMethodCallIndentation:
|
47
|
+
EnforcedStyle: indented
|
48
|
+
|
49
|
+
Layout/MultilineHashBraceLayout:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Layout/IndentArray:
|
53
|
+
EnforcedStyle: consistent
|
54
|
+
|
55
|
+
Layout/EmptyLinesAroundModuleBody:
|
56
|
+
EnforcedStyle: empty_lines_except_namespace
|
57
|
+
|
58
|
+
Layout/EmptyLinesAroundExceptionHandlingKeywords:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
Layout/EmptyLinesAroundClassBody:
|
62
|
+
EnforcedStyle: empty_lines_except_namespace
|
63
|
+
|
64
|
+
Layout/AlignParameters:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
Layout/AccessModifierIndentation:
|
68
|
+
EnforcedStyle: outdent
|
69
|
+
|
70
|
+
# -- Style ---------------------------------------------------------------------
|
71
|
+
Style/StringLiterals:
|
72
|
+
EnforcedStyle: double_quotes
|
73
|
+
|
74
|
+
Style/RegexpLiteral:
|
75
|
+
EnforcedStyle: percent_r
|
76
|
+
|
77
|
+
Style/Lambda:
|
78
|
+
EnforcedStyle: literal
|
79
|
+
|
80
|
+
Style/IfUnlessModifier:
|
81
|
+
Enabled: false
|
82
|
+
|
83
|
+
Style/GuardClause:
|
84
|
+
Enabled: false
|
85
|
+
|
86
|
+
Style/Documentation:
|
87
|
+
Enabled: false
|
88
|
+
|
89
|
+
Style/DateTime:
|
90
|
+
Enabled: false
|
91
|
+
|
92
|
+
Style/ClassAndModuleChildren:
|
93
|
+
Enabled: false
|
94
|
+
|
95
|
+
Style/AsciiComments:
|
96
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
Contribute your code to ComfyBlog in 5 easy steps:
|
4
|
+
|
5
|
+
### 1. Fork it
|
6
|
+
|
7
|
+
Fork the project. Optionally, create a branch you want to work on.
|
8
|
+
|
9
|
+
### 2. Get it running locally
|
10
|
+
|
11
|
+
- Install gem dependencies with `bundle install`
|
12
|
+
- There's nothing to configure, by default database is SQLite so it will be created for you.
|
13
|
+
Just run `rake db:migrate`
|
14
|
+
- Make sure that existing tests are passing by running `rake test`
|
15
|
+
- You should be able to start the app via `rails s` and navigate to http://localhost:3000/admin
|
16
|
+
|
17
|
+
### 3. Hack away
|
18
|
+
|
19
|
+
- Create a few small pull requests instead of a humoungous one. I can merge small stuff faster.
|
20
|
+
- When adding new code just make sure it follows the same slyle as the existing code.
|
21
|
+
- Avoid adding 3rd party dependencies if you can.
|
22
|
+
- Tests please, but nothing complicated. UnitTest / Fixtures all the way. Make sure all tests pass.
|
23
|
+
- Run `bundle exec rubocop` and fix any issues raised.
|
24
|
+
|
25
|
+
### 4. Make a pull request
|
26
|
+
|
27
|
+
- If you never done it before read this: https://help.github.com/articles/using-pull-requests
|
28
|
+
- When PR is submitted check if TravisCI ran all tests successfully and Rubocop didn't raise any issues
|
29
|
+
|
30
|
+
### 5. Done!
|
31
|
+
|
32
|
+
If everything is good your changes will be merged into master branch. Eventually a new version of gem will be published.
|
data/Gemfile
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
source
|
1
|
+
source "http://rubygems.org"
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem
|
5
|
+
gem "kaminari"
|
6
6
|
|
7
7
|
group :development do
|
8
|
-
gem
|
9
|
-
gem 'listen'
|
8
|
+
gem "listen"
|
10
9
|
gem "rubocop", "~> 0.51.0", require: false
|
10
|
+
gem "web-console"
|
11
11
|
end
|
12
12
|
|
13
13
|
group :test do
|
14
|
-
gem
|
15
|
-
gem
|
16
|
-
gem
|
17
|
-
gem
|
14
|
+
gem "coveralls", require: false
|
15
|
+
gem "mocha", require: false
|
16
|
+
gem "rails-controller-testing"
|
17
|
+
gem "sqlite3"
|
18
18
|
end
|
data/README.md
CHANGED
@@ -8,6 +8,7 @@ ComfyBlog is a simple blog management engine for [ComfortableMexicanSofa](https:
|
|
8
8
|
[](https://gemnasium.com/comfy/comfy-blog)
|
9
9
|
[](https://codeclimate.com/github/comfy/comfy-blog)
|
10
10
|
[](https://coveralls.io/r/comfy/comfy-blog?branch=master)
|
11
|
+
[](https://gitter.im/comfy/comfortable-mexican-sofa)
|
11
12
|
|
12
13
|
## Dependencies
|
13
14
|
|
data/Rakefile
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
class Comfy::Admin::Blog::PostsController < Comfy::Admin::Cms::BaseController
|
2
2
|
|
3
|
-
before_action :build_post, only: [
|
4
|
-
before_action :load_post, only: [
|
3
|
+
before_action :build_post, only: %i[new create]
|
4
|
+
before_action :load_post, only: %i[edit update destroy]
|
5
5
|
before_action :authorize
|
6
6
|
|
7
7
|
def index
|
8
|
-
return redirect_to action: :new if @site.blog_posts.count
|
8
|
+
return redirect_to action: :new if @site.blog_posts.count.zero?
|
9
9
|
|
10
|
-
posts_scope = @site.blog_posts
|
11
|
-
includes(:categories)
|
10
|
+
posts_scope = @site.blog_posts
|
11
|
+
.includes(:categories)
|
12
|
+
.for_category(params[:categories])
|
13
|
+
.order(published_at: :desc)
|
12
14
|
@posts = comfy_paginate(posts_scope)
|
13
15
|
end
|
14
16
|
|
@@ -18,11 +20,11 @@ class Comfy::Admin::Blog::PostsController < Comfy::Admin::Cms::BaseController
|
|
18
20
|
|
19
21
|
def create
|
20
22
|
@post.save!
|
21
|
-
flash[:success] = t(
|
23
|
+
flash[:success] = t(".created")
|
22
24
|
redirect_to action: :edit, id: @post
|
23
25
|
|
24
26
|
rescue ActiveRecord::RecordInvalid
|
25
|
-
flash.now[:danger] = t(
|
27
|
+
flash.now[:danger] = t(".create_failure")
|
26
28
|
render action: :new
|
27
29
|
end
|
28
30
|
|
@@ -32,26 +34,31 @@ class Comfy::Admin::Blog::PostsController < Comfy::Admin::Cms::BaseController
|
|
32
34
|
|
33
35
|
def update
|
34
36
|
@post.update_attributes!(post_params)
|
35
|
-
flash[:success] = t(
|
37
|
+
flash[:success] = t(".updated")
|
36
38
|
redirect_to action: :edit, id: @post
|
37
39
|
|
38
40
|
rescue ActiveRecord::RecordInvalid
|
39
|
-
flash.now[:danger] = t(
|
41
|
+
flash.now[:danger] = t(".update_failure")
|
40
42
|
render action: :edit
|
41
43
|
end
|
42
44
|
|
43
45
|
def destroy
|
44
46
|
@post.destroy
|
45
|
-
flash[:success] = t(
|
47
|
+
flash[:success] = t(".deleted")
|
46
48
|
redirect_to action: :index
|
47
49
|
end
|
48
50
|
|
51
|
+
def form_fragments
|
52
|
+
@post = @site.blog_posts.find_by(id: params[:id]) || @site.blog_posts.new
|
53
|
+
@post.layout = @site.layouts.find_by(id: params[:layout_id])
|
54
|
+
end
|
55
|
+
|
49
56
|
protected
|
50
57
|
|
51
58
|
def load_post
|
52
59
|
@post = @site.blog_posts.find(params[:id])
|
53
60
|
rescue ActiveRecord::RecordNotFound
|
54
|
-
flash[:danger] = t(
|
61
|
+
flash[:danger] = t(".not_found")
|
55
62
|
redirect_to action: :index
|
56
63
|
end
|
57
64
|
|
@@ -65,4 +72,5 @@ protected
|
|
65
72
|
def post_params
|
66
73
|
params.fetch(:post, {}).permit!
|
67
74
|
end
|
75
|
+
|
68
76
|
end
|
@@ -1,8 +1,13 @@
|
|
1
1
|
class Comfy::Admin::Blog::Revisions::PostController < Comfy::Admin::Cms::Revisions::BaseController
|
2
2
|
|
3
3
|
def show
|
4
|
-
@current_content
|
5
|
-
|
4
|
+
@current_content = @record.fragments.each_with_object({}) do |b, c|
|
5
|
+
c[b.identifier] = b.content
|
6
|
+
end
|
7
|
+
@versioned_content = @record.fragments.each_with_object({}) do |b, c|
|
8
|
+
data = @revision.data["fragments_attributes"].detect { |r| r[:identifier] == b.identifier }
|
9
|
+
c[b.identifier] = data.try(:[], :content)
|
10
|
+
end
|
6
11
|
|
7
12
|
render "comfy/admin/cms/revisions/show"
|
8
13
|
end
|
@@ -12,11 +17,12 @@ private
|
|
12
17
|
def load_record
|
13
18
|
@record = @site.blog_posts.find(params[:blog_post_id])
|
14
19
|
rescue ActiveRecord::RecordNotFound
|
15
|
-
flash[:danger] = I18n.t(
|
20
|
+
flash[:danger] = I18n.t("comfy.admin.cms.revisions.record_not_found")
|
16
21
|
redirect_to comfy_admin_blog_posts_path(@site)
|
17
22
|
end
|
18
23
|
|
19
24
|
def record_path
|
20
25
|
edit_comfy_admin_blog_post_path(@site, @record)
|
21
26
|
end
|
27
|
+
|
22
28
|
end
|
@@ -3,12 +3,13 @@ class Comfy::Blog::PostsController < Comfy::Cms::BaseController
|
|
3
3
|
include Comfy::Paginate
|
4
4
|
|
5
5
|
def index
|
6
|
-
scope =
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
scope =
|
7
|
+
if params[:year]
|
8
|
+
scope = @cms_site.blog_posts.published.for_year(params[:year])
|
9
|
+
params[:month] ? scope.for_month(params[:month]) : scope
|
10
|
+
else
|
11
|
+
@cms_site.blog_posts.published
|
12
|
+
end
|
12
13
|
|
13
14
|
scope = scope.for_category(params[:category]) if params[:category]
|
14
15
|
|
@@ -24,18 +25,19 @@ class Comfy::Blog::PostsController < Comfy::Cms::BaseController
|
|
24
25
|
content_type: "text/html"
|
25
26
|
|
26
27
|
rescue ActiveRecord::RecordNotFound
|
27
|
-
render cms_page:
|
28
|
+
render cms_page: "/404", status: 404
|
28
29
|
end
|
29
30
|
|
30
31
|
private
|
31
32
|
|
32
33
|
def load_post
|
33
34
|
post_scope = @cms_site.blog_posts.published.where(slug: params[:slug])
|
34
|
-
@cms_post =
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
@cms_post =
|
36
|
+
if params[:year] && params[:month]
|
37
|
+
post_scope.where(year: params[:year], month: params[:month]).first!
|
38
|
+
else
|
39
|
+
post_scope.first!
|
40
|
+
end
|
39
41
|
@cms_layout = @cms_post.layout
|
40
42
|
end
|
41
43
|
|
@@ -43,4 +45,5 @@ private
|
|
43
45
|
return false unless @cms_layout
|
44
46
|
@cms_layout.app_layout.present? ? @cms_layout.app_layout : false
|
45
47
|
end
|
48
|
+
|
46
49
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Comfy::Blog::Post < ActiveRecord::Base
|
2
2
|
|
3
|
-
self.table_name =
|
3
|
+
self.table_name = "comfy_blog_posts"
|
4
4
|
|
5
5
|
include Comfy::Cms::WithFragments
|
6
6
|
include Comfy::Cms::WithCategories
|
@@ -9,19 +9,19 @@ class Comfy::Blog::Post < ActiveRecord::Base
|
|
9
9
|
|
10
10
|
# -- Relationships -----------------------------------------------------------
|
11
11
|
belongs_to :site,
|
12
|
-
class_name:
|
12
|
+
class_name: "Comfy::Cms::Site"
|
13
13
|
|
14
14
|
# -- Validations -------------------------------------------------------------
|
15
15
|
validates :title, :slug, :year, :month,
|
16
16
|
presence: true
|
17
17
|
validates :slug,
|
18
|
-
uniqueness: {scope: [
|
19
|
-
format: {with:
|
18
|
+
uniqueness: { scope: %i[site_id year month] },
|
19
|
+
format: { with: %r{\A%*\w[a-z0-9_%-]*\z}i }
|
20
20
|
|
21
21
|
# -- Scopes ------------------------------------------------------------------
|
22
|
-
scope :published, -> {where(is_published: true)}
|
23
|
-
scope :for_year, ->
|
24
|
-
scope :for_month, ->
|
22
|
+
scope :published, -> { where(is_published: true) }
|
23
|
+
scope :for_year, ->(year) { where(year: year) }
|
24
|
+
scope :for_month, ->(month) { where(month: month) }
|
25
25
|
|
26
26
|
# -- Callbacks ---------------------------------------------------------------
|
27
27
|
before_validation :set_slug,
|
@@ -31,22 +31,23 @@ class Comfy::Blog::Post < ActiveRecord::Base
|
|
31
31
|
# -- Instance Mathods --------------------------------------------------------
|
32
32
|
def url(relative: false)
|
33
33
|
public_blog_path = ComfyBlog.config.public_blog_path
|
34
|
-
post_path = [
|
35
|
-
[
|
34
|
+
post_path = ["/", public_blog_path, year, month, slug].join("/").squeeze("/")
|
35
|
+
[site.url(relative: relative), post_path].join
|
36
36
|
end
|
37
37
|
|
38
38
|
protected
|
39
39
|
|
40
40
|
def set_slug
|
41
|
-
self.slug ||=
|
41
|
+
self.slug ||= title.to_s.parameterize
|
42
42
|
end
|
43
43
|
|
44
44
|
def set_date
|
45
|
-
self.year =
|
46
|
-
self.month =
|
45
|
+
self.year = published_at.year
|
46
|
+
self.month = published_at.month
|
47
47
|
end
|
48
48
|
|
49
49
|
def set_published_at
|
50
50
|
self.published_at ||= Time.zone.now
|
51
51
|
end
|
52
|
+
|
52
53
|
end
|