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
@@ -4,9 +4,9 @@
4
4
  = form.text_field :slug, data: {slug: true}
5
5
 
6
6
  - if (options = ::Comfy::Cms::Layout.options_for_select(@site)).present?
7
- = form.select :layout_id, options, {}, {data: {url: form_fragments_comfy_admin_cms_site_page_path(@site, @post.id.to_i)}, id: "fragments-toggle"}
7
+ = form.select :layout_id, options, {}, {data: {url: form_fragments_comfy_admin_blog_post_path(@site, @post.id.to_i)}, id: "fragments-toggle"}
8
8
 
9
- = render "comfy/admin/cms/pages/form_fragments", form: form, record: @post
9
+ = render "comfy/admin/cms/fragments/form_fragments", form: form, record: @post
10
10
 
11
11
  = render 'comfy/admin/cms/categories/form', form: form
12
12
 
@@ -0,0 +1 @@
1
+ $('#form-fragments').replaceWith('<%= escape_javascript(render("comfy/admin/cms/fragments/form_fragments", record: @post)) %>');
@@ -1,8 +1,8 @@
1
- xml.instruct! :xml, version: '1.0'
2
- xml.rss version: '2.0' do
1
+ xml.instruct! :xml, version: "1.0"
2
+ xml.rss version: "2.0" do
3
3
  xml.channel do
4
- xml.title 'My Blog'
5
- xml.description 'My Blog Description'
4
+ xml.title "My Blog"
5
+ xml.description "My Blog Description"
6
6
  xml.link comfy_blog_posts_url(@cms_site.path)
7
7
 
8
8
  @blog_posts.each do |post|
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ system(*args) || abort("\n== Command #{args} failed ==")
10
+ end
11
+
12
+ chdir APP_ROOT do
13
+ # This script is a starting point to setup your application.
14
+ # Add necessary setup steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # Install JavaScript dependencies if using Yarn
21
+ # system('bin/yarn')
22
+
23
+ # puts "\n== Copying sample files =="
24
+ # unless File.exist?('config/database.yml')
25
+ # cp 'config/database.yml.sample', 'config/database.yml'
26
+ # end
27
+
28
+ puts "\n== Preparing database =="
29
+ system! 'bin/rails db:setup'
30
+
31
+ puts "\n== Removing old logs and tempfiles =="
32
+ system! 'bin/rails log:clear tmp:clear'
33
+
34
+ puts "\n== Restarting application server =="
35
+ system! 'bin/rails restart'
36
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ system(*args) || abort("\n== Command #{args} failed ==")
10
+ end
11
+
12
+ chdir APP_ROOT do
13
+ # This script is a way to update your development environment automatically.
14
+ # Add necessary update steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # Install JavaScript dependencies if using Yarn
21
+ # system('bin/yarn')
22
+
23
+ puts "\n== Updating database =="
24
+ system! 'bin/rails db:migrate'
25
+
26
+ puts "\n== Removing old logs and tempfiles =="
27
+ system! 'bin/rails log:clear tmp:clear'
28
+
29
+ puts "\n== Restarting application server =="
30
+ system! 'bin/rails restart'
31
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ VENDOR_PATH = File.expand_path('..', __dir__)
3
+ Dir.chdir(VENDOR_PATH) do
4
+ begin
5
+ exec "yarnpkg #{ARGV.join(' ')}"
6
+ rescue Errno::ENOENT
7
+ $stderr.puts "Yarn executable was not detected in the system."
8
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
9
+ exit 1
10
+ end
11
+ end
@@ -1,23 +1,23 @@
1
- $:.push File.expand_path("../lib", __FILE__)
1
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
2
2
 
3
- require 'comfy_blog/version'
3
+ require "comfy_blog/version"
4
4
 
5
5
  # Describe your gem and declare its dependencies:
6
6
  Gem::Specification.new do |s|
7
- s.name = 'comfy_blog'
7
+ s.name = "comfy_blog"
8
8
  s.version = ComfyBlog::VERSION
9
9
  s.authors = ["Oleg Khabarov"]
10
10
  s.email = ["oleg@khabarov.ca"]
11
11
  s.homepage = "http://github.com/comfy/comfy-blog"
12
12
  s.summary = "Simple Blog Engine for ComfortableMexicanSofa"
13
13
  s.description = "Simple Blog Engine for ComfortableMexicanSofa"
14
- s.license = 'MIT'
14
+ s.license = "MIT"
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.platform = Gem::Platform::RUBY
18
- s.require_paths = ['lib']
18
+ s.require_paths = ["lib"]
19
19
 
20
20
  s.required_ruby_version = ">= 2.2.2"
21
21
 
22
- s.add_dependency 'comfortable_mexican_sofa', '>= 2.0.2'
22
+ s.add_dependency "comfortable_mexican_sofa", ">= 2.0.3"
23
23
  end
data/config.ru CHANGED
@@ -1,4 +1,4 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
4
- run ComfyBlog::Application
3
+ require ::File.expand_path("../config/environment", __FILE__)
4
+ run ComfyBlog::Application
@@ -1,6 +1,6 @@
1
- require_relative 'boot'
1
+ require_relative "boot"
2
2
 
3
- require 'rails/all'
3
+ require "rails/all"
4
4
 
5
5
  # Require the gems listed in Gemfile, including any gems
6
6
  # you've limited to :test, :development, or :production.
@@ -9,7 +9,7 @@ Bundler.require(*Rails.groups)
9
9
  module ComfyBlog
10
10
  class Application < Rails::Application
11
11
 
12
- require_relative '../lib/comfy_blog'
12
+ require_relative "../lib/comfy_blog"
13
13
 
14
14
  config.load_defaults 5.2
15
15
 
@@ -29,8 +29,9 @@ module ComfyBlog
29
29
  config.railties_order = [ActiveStorage::Engine, :main_app, :all]
30
30
 
31
31
  # Making sure we don't load our dev routes as part of the engine
32
- config.paths['config/routes.rb'] << 'config/blog_routes.rb'
32
+ config.paths["config/routes.rb"] << "config/blog_routes.rb"
33
33
 
34
34
  config.i18n.enforce_available_locales = true
35
+
35
36
  end
36
37
  end
@@ -1,5 +1,5 @@
1
1
  # Set up gems listed in the Gemfile.
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
3
3
 
4
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
5
- File.exists?(ENV['BUNDLE_GEMFILE'])
4
+ require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
5
+ File.exist?(ENV["BUNDLE_GEMFILE"])
@@ -1,5 +1,5 @@
1
1
  # Load the rails application
2
- require File.expand_path('../application', __FILE__)
2
+ require File.expand_path("../application", __FILE__)
3
3
 
4
4
  # Initialize the rails application
5
5
  ComfyBlog::Application.initialize!
@@ -14,12 +14,12 @@ defined?(ComfyBlog::Application) && ComfyBlog::Application.configure do
14
14
 
15
15
  # Enable/disable caching. By default caching is disabled.
16
16
  # Run rails dev:cache to toggle caching.
17
- if Rails.root.join('tmp/caching-dev.txt').exist?
17
+ if Rails.root.join("tmp/caching-dev.txt").exist?
18
18
  config.action_controller.perform_caching = true
19
19
 
20
20
  config.cache_store = :memory_store
21
21
  config.public_file_server.headers = {
22
- 'Cache-Control' => "public, max-age=#{2.days.to_i}"
22
+ "Cache-Control" => "public, max-age=#{2.days.to_i}"
23
23
  }
24
24
  else
25
25
  config.action_controller.perform_caching = false
@@ -15,7 +15,7 @@ defined?(ComfyBlog::Application) && ComfyBlog::Application.configure do
15
15
  # Configure public file server for tests with Cache-Control for performance.
16
16
  config.public_file_server.enabled = true
17
17
  config.public_file_server.headers = {
18
- 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
18
+ "Cache-Control" => "public, max-age=#{1.hour.to_i}"
19
19
  }
20
20
 
21
21
  # Show full error reports and disable caching.
@@ -1,9 +1,7 @@
1
1
  ComfyBlog.configure do |config|
2
-
3
2
  # application layout to be used to index blog posts
4
3
  # config.app_layout = 'comfy/blog/application'
5
4
 
6
5
  # Number of posts per page. Default is 10
7
6
  # config.posts_per_page = 10
8
-
9
7
  end
@@ -1,12 +1,12 @@
1
- require_relative 'comfy_blog/version'
2
- require_relative 'comfy_blog/engine'
3
- require_relative 'comfy_blog/configuration'
4
- require_relative 'comfy_blog/routing'
1
+ require_relative "comfy_blog/version"
2
+ require_relative "comfy_blog/engine"
3
+ require_relative "comfy_blog/configuration"
4
+ require_relative "comfy_blog/routing"
5
5
 
6
6
  module ComfyBlog
7
-
7
+
8
8
  class << self
9
-
9
+
10
10
  # Modify Blog configuration
11
11
  # Example:
12
12
  # ComfyBlog.configure do |config|
@@ -15,13 +15,13 @@ module ComfyBlog
15
15
  def configure
16
16
  yield configuration
17
17
  end
18
-
18
+
19
19
  # Accessor for ComfyBlog::Configuration
20
20
  def configuration
21
21
  @configuration ||= ComfyBlog::Configuration.new
22
22
  end
23
- alias :config :configuration
24
-
23
+ alias config configuration
24
+
25
25
  end
26
-
26
+
27
27
  end
@@ -14,7 +14,7 @@ module ComfyBlog
14
14
  # Configuration defaults
15
15
  def initialize
16
16
  @posts_per_page = 10
17
- @app_layout = 'comfy/blog/application'
17
+ @app_layout = "comfy/blog/application"
18
18
  @public_blog_path = nil
19
19
  end
20
20
 
@@ -1,25 +1,30 @@
1
- require 'rubygems'
2
- require 'rails'
3
- require 'comfortable_mexican_sofa'
4
- require 'comfy_blog'
1
+ require "rubygems"
2
+ require "rails"
3
+ require "comfortable_mexican_sofa"
4
+ require "comfy_blog"
5
5
 
6
6
  module ComfyBlog
7
7
 
8
8
  module CmsSiteExtensions
9
+
9
10
  extend ActiveSupport::Concern
10
11
  included do
11
12
  has_many :blog_posts,
12
- class_name: 'Blog::Post',
13
+ class_name: "Blog::Post",
13
14
  dependent: :destroy
14
15
  end
16
+
15
17
  end
16
18
 
17
19
  class Engine < ::Rails::Engine
18
- initializer 'comfy_blog.configuration' do |app|
19
- ComfortableMexicanSofa::ViewHooks.add(:navigation, '/comfy/admin/blog/partials/navigation')
20
+
21
+ initializer "comfy_blog.configuration" do
22
+ ComfortableMexicanSofa::ViewHooks.add(:navigation, "/comfy/admin/blog/partials/navigation")
20
23
  config.to_prepare do
21
24
  Comfy::Cms::Site.send :include, ComfyBlog::CmsSiteExtensions
22
25
  end
23
26
  end
27
+
24
28
  end
29
+
25
30
  end
@@ -1,19 +1,19 @@
1
1
  class ActionDispatch::Routing::Mapper
2
2
 
3
3
  def comfy_route_blog(options = {})
4
-
5
- ComfyBlog.configuration.public_blog_path = options[:path] || 'blog'
6
- path = ['(:cms_path)', ComfyBlog.configuration.public_blog_path].join('/')
4
+ ComfyBlog.configuration.public_blog_path = options[:path] || "blog"
5
+ path = ["(:cms_path)", ComfyBlog.configuration.public_blog_path].join("/")
7
6
 
8
7
  scope module: :comfy, as: :comfy do
9
8
  namespace :blog, path: path do
10
- with_options constraints: {year: /\d{4}/, month: /\d{1,2}/} do |o|
11
- o.get ':year', to: 'posts#index', as: :posts_of_year
12
- o.get ':year/:month', to: 'posts#index', as: :posts_of_month
13
- o.get ':year/:month/:slug', to: 'posts#show', as: :post
14
- o.get '/', to: 'posts#index', as: :posts
9
+ with_options constraints: { year: %r{\d{4}}, month: %r{\d{1,2}} } do |o|
10
+ o.get ":year", to: "posts#index", as: :posts_of_year
11
+ o.get ":year/:month", to: "posts#index", as: :posts_of_month
12
+ o.get ":year/:month/:slug", to: "posts#show", as: :post
13
+ o.get "/", to: "posts#index", as: :posts
15
14
  end
16
15
  end
17
16
  end
18
17
  end
18
+
19
19
  end
@@ -1,14 +1,15 @@
1
1
  class ActionDispatch::Routing::Mapper
2
2
 
3
3
  def comfy_route_blog_admin(options = {})
4
- options[:path] ||= 'admin'
5
- path = [options[:path], 'sites', ':site_id'].join('/')
4
+ options[:path] ||= "admin"
5
+ path = [options[:path], "sites", ":site_id"].join("/")
6
6
 
7
7
  scope module: :comfy, as: :comfy do
8
8
  scope module: :admin do
9
9
  namespace :blog, as: :admin, path: path, except: [:show] do
10
10
  resources :posts, as: :blog_posts, path: "blog-posts" do
11
- resources :revisions, only: [:index, :show], controller: "revisions/post" do
11
+ get :form_fragments, on: :member
12
+ resources :revisions, only: %i[index show], controller: "revisions/post" do
12
13
  patch :revert, on: :member
13
14
  end
14
15
  end
@@ -16,4 +17,5 @@ class ActionDispatch::Routing::Mapper
16
17
  end
17
18
  end
18
19
  end
20
+
19
21
  end
@@ -1,2 +1,2 @@
1
- require_relative 'routes/blog_admin'
2
- require_relative 'routes/blog'
1
+ require_relative "routes/blog_admin"
2
+ require_relative "routes/blog"
@@ -1,3 +1,5 @@
1
1
  module ComfyBlog
2
- VERSION = "2.0.2"
2
+
3
+ VERSION = "2.0.3".freeze
4
+
3
5
  end
@@ -1,4 +1,4 @@
1
- require 'rails/generators/active_record'
1
+ require "rails/generators/active_record"
2
2
 
3
3
  module Comfy
4
4
  module Generators
@@ -7,27 +7,27 @@ module Comfy
7
7
  include Rails::Generators::Migration
8
8
  include Thor::Actions
9
9
 
10
- source_root File.expand_path('../../../../..', __FILE__)
10
+ source_root File.expand_path("../../../../..", __FILE__)
11
11
 
12
12
  def self.next_migration_number(dirname)
13
13
  ActiveRecord::Generators::Base.next_migration_number(dirname)
14
14
  end
15
15
 
16
16
  def generate_migration
17
- destination = File.expand_path('db/migrate/01_create_blog.rb', self.destination_root)
17
+ destination = File.expand_path("db/migrate/01_create_blog.rb", destination_root)
18
18
  migration_dir = File.dirname(destination)
19
- destination = self.class.migration_exists?(migration_dir, 'create_blog')
19
+ destination = self.class.migration_exists?(migration_dir, "create_blog")
20
20
 
21
21
  if destination
22
22
  puts "\e[0m\e[31mFound existing create_blog migration. Remove it if you want to regenerate.\e[0m"
23
23
  else
24
- migration_template 'db/migrate/01_create_blog.rb', 'db/migrate/create_blog.rb'
24
+ migration_template "db/migrate/01_create_blog.rb", "db/migrate/create_blog.rb"
25
25
  end
26
26
  end
27
27
 
28
28
  def generate_initialization
29
- copy_file 'config/initializers/comfy_blog.rb',
30
- 'config/initializers/comfy_blog.rb'
29
+ copy_file "config/initializers/comfy_blog.rb",
30
+ "config/initializers/comfy_blog.rb"
31
31
  end
32
32
 
33
33
  def generate_routing
@@ -39,11 +39,11 @@ module Comfy
39
39
  end
40
40
 
41
41
  def generate_views
42
- directory 'app/views/comfy/blog', 'app/views/comfy/blog'
42
+ directory "app/views/comfy/blog", "app/views/comfy/blog"
43
43
  end
44
44
 
45
45
  def show_readme
46
- readme 'lib/generators/comfy/blog/README'
46
+ readme "lib/generators/comfy/blog/README"
47
47
  end
48
48
 
49
49
  end