comfy_blog 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.github/issue_template.md +22 -0
  3. data/.github/pull_request_template.md +6 -0
  4. data/.rubocop.yml +96 -0
  5. data/.travis.yml +2 -1
  6. data/CONTRIBUTING.md +32 -0
  7. data/Gemfile +8 -8
  8. data/README.md +1 -0
  9. data/Rakefile +1 -1
  10. data/app/controllers/comfy/admin/blog/posts_controller.rb +19 -11
  11. data/app/controllers/comfy/admin/blog/revisions/post_controller.rb +9 -3
  12. data/app/controllers/comfy/blog/posts_controller.rb +15 -12
  13. data/app/models/comfy/blog/post.rb +13 -12
  14. data/app/views/comfy/admin/blog/posts/_form.html.haml +2 -2
  15. data/app/views/comfy/admin/blog/posts/form_fragments.js.erb +1 -0
  16. data/app/views/comfy/blog/posts/index.rss.builder +4 -4
  17. data/bin/bundle +3 -0
  18. data/bin/rails +4 -0
  19. data/bin/rake +4 -0
  20. data/bin/setup +36 -0
  21. data/bin/update +31 -0
  22. data/bin/yarn +11 -0
  23. data/comfy_blog.gemspec +6 -6
  24. data/config.ru +2 -2
  25. data/config/application.rb +5 -4
  26. data/config/boot.rb +3 -3
  27. data/config/environment.rb +1 -1
  28. data/config/environments/development.rb +2 -2
  29. data/config/environments/test.rb +1 -1
  30. data/config/initializers/comfy_blog.rb +0 -2
  31. data/lib/comfy_blog.rb +10 -10
  32. data/lib/comfy_blog/configuration.rb +1 -1
  33. data/lib/comfy_blog/engine.rb +12 -7
  34. data/lib/comfy_blog/routes/blog.rb +8 -8
  35. data/lib/comfy_blog/routes/blog_admin.rb +5 -3
  36. data/lib/comfy_blog/routing.rb +2 -2
  37. data/lib/comfy_blog/version.rb +3 -1
  38. data/lib/generators/comfy/blog/blog_generator.rb +9 -9
  39. data/test/controllers/comfy/admin/blog/posts_controller_test.rb +53 -32
  40. data/test/controllers/comfy/admin/blog/revisions/post_controller_test.rb +6 -6
  41. data/test/controllers/comfy/blog/posts_controller_test.rb +7 -6
  42. data/test/gemfiles/Gemfile.rails.5.2 +5 -4
  43. data/test/generators/blog_generator_test.rb +7 -6
  44. data/test/integration/i18n_test.rb +8 -7
  45. data/test/lib/configuration_test.rb +4 -3
  46. data/test/models/posts_test.rb +12 -11
  47. data/test/test_helper.rb +24 -21
  48. metadata +15 -5
  49. data/script/rails +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed87b17424062fedd960bd78ef9b0c6bd9b8923d
4
- data.tar.gz: a652f008197705629d93c583c1d36cb79a9b9712
3
+ metadata.gz: c23d02796c11c424383ef59503f004d9d11a14a7
4
+ data.tar.gz: 2bcdbffe51266427e3598a4cb27097b1abecd76f
5
5
  SHA512:
6
- metadata.gz: d1489b02510daba80054da073d9c0ef0ee001146e6f00fdd0eeca4594cf69b74699d36843ff07dd29532b3dbaff5cd127b1a758ed36cead694851d8d6aa67cc7
7
- data.tar.gz: '0586168fa718e0f0123e98568a8f20f9c71a17ad3b98debda40ba06854d645a71ed85332d6f03c93721d25f6ceab735046d639539b29b7ee0d578e5bc0b530e7'
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**:
@@ -0,0 +1,6 @@
1
+ ### Summary
2
+
3
+ General information about what this PR is all about. If it fixes any issues
4
+ please don't forget to tag them.
5
+
6
+ Thanks for contributing!
@@ -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
@@ -4,7 +4,8 @@ before_install:
4
4
  before_script:
5
5
  - rake db:migrate
6
6
  script:
7
- - rake test
7
+ - bundle exec rake test
8
+ - bundle exec rubocop
8
9
  rvm:
9
10
  - 2.2.7
10
11
  - 2.3.5
@@ -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 'http://rubygems.org'
1
+ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'kaminari'
5
+ gem "kaminari"
6
6
 
7
7
  group :development do
8
- gem 'web-console'
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 'rails-controller-testing'
15
- gem 'sqlite3'
16
- gem 'mocha', require: false
17
- gem 'coveralls', require: false
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
  [![Dependency Status](https://img.shields.io/gemnasium/comfy/comfy-blog.svg?style=flat)](https://gemnasium.com/comfy/comfy-blog)
9
9
  [![Code Climate](https://img.shields.io/codeclimate/maintainability/comfy/comfy-blog.svg?style=flat)](https://codeclimate.com/github/comfy/comfy-blog)
10
10
  [![Coverage Status](https://img.shields.io/coveralls/comfy/comfy-blog.svg?style=flat)](https://coveralls.io/r/comfy/comfy-blog?branch=master)
11
+ [![Gitter](https://badges.gitter.im/comfy/comfortable-mexican-sofa.svg)](https://gitter.im/comfy/comfortable-mexican-sofa)
11
12
 
12
13
  ## Dependencies
13
14
 
data/Rakefile CHANGED
@@ -1,3 +1,3 @@
1
- require_relative 'config/application'
1
+ require_relative "config/application"
2
2
 
3
3
  Rails.application.load_tasks
@@ -1,14 +1,16 @@
1
1
  class Comfy::Admin::Blog::PostsController < Comfy::Admin::Cms::BaseController
2
2
 
3
- before_action :build_post, only: [:new, :create]
4
- before_action :load_post, only: [:edit, :update, :destroy]
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 == 0
8
+ return redirect_to action: :new if @site.blog_posts.count.zero?
9
9
 
10
- posts_scope = @site.blog_posts.
11
- includes(:categories).for_category(params[:categories]).order(published_at: :desc)
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('.created')
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('.create_failure')
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('.updated')
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('.update_failure')
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('.deleted')
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('.not_found')
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 = @record.fragments.inject({}){|c, b| c[b.identifier] = b.content; c }
5
- @versioned_content = @record.fragments.inject({}){|c, b| c[b.identifier] = @revision.data['fragments_attributes'].detect{|r| r[:identifier] == b.identifier}.try(:[], :content); c }
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('comfy.admin.cms.revisions.record_not_found')
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 = if params[:year]
7
- scope = @cms_site.blog_posts.published.for_year(params[:year])
8
- params[:month] ? scope.for_month(params[:month]) : scope
9
- else
10
- @cms_site.blog_posts.published
11
- end
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: '/404', status: 404
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 = if params[:year] && params[:month]
35
- post_scope = post_scope.where(year: params[:year], month: params[:month]).first!
36
- else
37
- post_scope.first!
38
- end
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 = 'comfy_blog_posts'
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: 'Comfy::Cms::Site'
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: [:site_id, :year, :month]},
19
- format: {with: /\A%*\w[a-z0-9_\-\%]*\z/i }
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, -> year {where(year: year)}
24
- scope :for_month, -> month {where(month: 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 = ['/', public_blog_path, self.year, self.month, self.slug].join('/').squeeze('/')
35
- [self.site.url(relative: relative), post_path].join
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 ||= self.title.to_s.parameterize
41
+ self.slug ||= title.to_s.parameterize
42
42
  end
43
43
 
44
44
  def set_date
45
- self.year = self.published_at.year
46
- self.month = self.published_at.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