casein 5.3.0.0 → 5.4.0.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.
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Casein
2
4
  class AdminUserSession < ::Authlogic::Session::Base
3
- include ActiveModel::Conversion
5
+ include ActiveModel::Conversion
4
6
  extend ActiveModel::Naming
5
- def persisted?
6
- false
7
+ def persisted?
8
+ false
7
9
  end
8
10
  end
9
11
  end
data/app/models/casein.rb CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Casein
2
4
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # config/initializers/will_paginate.rb
2
- #
4
+ #
3
5
  # This extension code was written by Isaac Bowen, originally found
4
6
  # at http://isaacbowen.com/blog/using-will_paginate-action_view-and-bootstrap/
5
7
 
@@ -7,20 +9,22 @@ require 'will_paginate/view_helpers/action_view'
7
9
 
8
10
  module WillPaginate
9
11
  module ActionView
10
-
11
12
  def will_paginate(collection = nil, options = {})
12
- options, collection = collection, nil if collection.is_a? Hash
13
+ if collection.is_a? Hash
14
+ options = collection
15
+ collection = nil
16
+ end
13
17
  # Taken from original will_paginate code to handle if the helper is not passed a collection object.
14
- collection ||= infer_collection_from_controller
18
+ collection ||= infer_collection_from_controller
15
19
  options[:renderer] ||= BootstrapLinkRenderer
16
20
  super.try :html_safe
17
21
  end
18
22
 
19
23
  class BootstrapLinkRenderer < LinkRenderer
20
24
  protected
21
-
25
+
22
26
  def html_container(html)
23
- tag :div, tag(:ul, html, class: "pagination"), container_attributes
27
+ tag :div, tag(:ul, html, class: 'pagination'), container_attributes
24
28
  end
25
29
 
26
30
  def page_number(page)
@@ -33,8 +37,8 @@ module WillPaginate
33
37
 
34
38
  def previous_or_next_page(page, text, classname)
35
39
  tag :li, link(text, page || '#'),
36
- class: [(classname[0..3] if @options[:page_links]), (classname if @options[:page_links]), ('disabled' unless page)].join(' ')
40
+ class: [(classname[0..3] if @options[:page_links]), (classname if @options[:page_links]), ('disabled' unless page)].join(' ')
37
41
  end
38
42
  end
39
43
  end
40
- end
44
+ end
data/config/routes.rb CHANGED
@@ -1,20 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Rails.application.routes.draw do
2
-
3
- match "/admin" => redirect("/casein"), via: :get
4
-
4
+ match '/admin' => redirect('/casein'), via: :get
5
+
5
6
  namespace :casein do
6
-
7
7
  resources :admin_users do
8
8
  member do
9
9
  patch :update_password, :reset_password
10
10
  end
11
11
  end
12
-
13
- resource :admin_user_session, only: [:new, :create, :destroy]
14
- resource :password_reset, only: [:create, :edit, :update]
15
-
16
- match "/blank" => "casein#blank", via: :get
17
- root to: "casein#index"
12
+
13
+ resource :admin_user_session, only: %i[new create destroy]
14
+ resource :password_reset, only: %i[create edit update]
15
+
16
+ match '/blank' => 'casein#blank', via: :get
17
+ root to: 'casein#index'
18
18
  end
19
-
20
19
  end
data/lib/casein/engine.rb CHANGED
@@ -1,17 +1,18 @@
1
- require "casein"
2
- require "rails"
1
+ # frozen_string_literal: true
2
+
3
+ require 'casein'
4
+ require 'rails'
3
5
  require 'bootstrap-sass'
4
6
  require 'jquery-rails'
5
7
 
6
8
  module Casein
7
9
  class Engine < Rails::Engine
8
-
9
- initializer "casein.assets.precompile" do |app|
10
- app.config.assets.precompile += %w(casein/login.css casein/casein.css casein/casein.js casein/html5shiv.js casein/custom.css casein/custom.js casein/auth_custom.css casein/auth_custom.js casein/*.png)
10
+ initializer 'casein.assets.precompile' do |app|
11
+ app.config.assets.precompile += %w[casein/login.css casein/casein.css casein/casein.js casein/html5shiv.js casein/custom.css casein/custom.js casein/auth_custom.css casein/auth_custom.js casein/*.png]
11
12
  end
12
13
 
13
14
  rake_tasks do
14
- load "railties/tasks.rake"
15
+ load 'railties/tasks.rake'
15
16
  end
16
17
 
17
18
  config.generators do |g|
@@ -20,16 +21,14 @@ module Casein
20
21
  g.assets false
21
22
  g.helper false
22
23
  end
23
-
24
24
  end
25
-
26
- class RouteConstraint
27
25
 
28
- def matches?(request)
29
- return false if request.fullpath.include?("/casein")
30
- return false if request.fullpath.include?("/admin")
31
- true
32
- end
26
+ class RouteConstraint
27
+ def matches?(request)
28
+ return false if request.fullpath.include?('/casein')
29
+ return false if request.fullpath.include?('/admin')
33
30
 
31
+ true
32
+ end
34
33
  end
35
34
  end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Casein
2
- VERSION_HASH = { major: 5, minor: 3, patch: 0, build: 0 }
3
- VERSION = VERSION_HASH.values.join(".")
4
+ VERSION_HASH = { major: 5, minor: 4, patch: 0, build: 0 }
5
+ VERSION = VERSION_HASH.values.join('.')
4
6
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Casein
4
+ <<<<<<< HEAD
5
+ VERSION_HASH = { major: 5, minor: 4, patch: 0, build: 0 }
6
+ =======
7
+ VERSION_HASH = { major: 5, minor: 5, patch: 0, build: 0 }.freeze
8
+ >>>>>>> e30a2164a5c79f1cf607075d5e6a99dc014b74b6
9
+ VERSION = VERSION_HASH.values.join('.')
10
+ end
data/lib/casein.rb CHANGED
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if defined?(Rails) && Rails::VERSION::MAJOR >= 5
2
- require 'casein/engine'
3
- require 'casein/version'
4
- require 'will_paginate'
5
- require 'authlogic'
4
+ require 'casein/engine'
5
+ require 'casein/version'
6
+ require 'will_paginate'
7
+ require 'authlogic'
6
8
  else
7
- puts("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
8
- puts("!!! WARNING! This version of Casein requires Rails >= 5.x !!!")
9
- puts("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
10
- end
9
+ puts('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
10
+ puts('!!! WARNING! This version of Casein requires Rails >= 5.x !!!')
11
+ puts('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
12
+ end
@@ -1,39 +1,40 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Casein
2
4
  class InstallGenerator < Rails::Generators::Base
3
-
4
- include Rails::Generators::Migration
5
- source_root File.expand_path('../templates', __FILE__)
6
-
7
- def self.next_migration_number dirname
8
- if ActiveRecord::Base.timestamped_migrations
9
- Time.now.utc.strftime("%Y%m%d%H%M%S")
10
- else
11
- "%.3d" % (current_migration_number(dirname) + 1)
12
- end
5
+ include Rails::Generators::Migration
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ def self.next_migration_number(dirname)
9
+ if ActiveRecord::Base.timestamped_migrations
10
+ Time.now.utc.strftime('%Y%m%d%H%M%S')
11
+ else
12
+ format('%.3d', (current_migration_number(dirname) + 1))
13
13
  end
14
-
15
- def generate_files
16
- puts "*** WARNING - Generating configuration files. Make sure you have backed up any files before overwriting them. ***"
17
-
18
- #config helper
19
- copy_file "app/helpers/casein/config_helper.rb", "app/helpers/casein/config_helper.rb"
20
-
21
- #initial view partials
22
- copy_file "app/views/casein/layouts/_tab_navigation.html.erb", "app/views/casein/layouts/_tab_navigation.html.erb"
23
- copy_file "app/views/casein/layouts/_top_navigation.html.erb", "app/views/casein/layouts/_top_navigation.html.erb"
24
-
25
- #robots.txt
26
- puts " ** Overwrite if you haven't yet modified your robots.txt, otherwise add disallow rules for /casein and /admin manually **"
27
- copy_file "public/robots.txt", "public/robots.txt"
28
-
29
- #blank stylesheets and JavaScript files
30
- copy_file "app/assets/stylesheets/casein/custom.scss", "app/assets/stylesheets/casein/custom.scss"
31
- copy_file "app/assets/javascripts/casein/custom.js", "app/assets/javascripts/casein/custom.js"
32
- copy_file "app/assets/stylesheets/casein/auth_custom.scss", "app/assets/stylesheets/casein/auth_custom.scss"
33
- copy_file "app/assets/javascripts/casein/auth_custom.js", "app/assets/javascripts/casein/auth_custom.js"
34
-
35
- #migrations
36
- migration_template 'db/migrate/casein_create_admin_users.rb', "db/migrate/casein_create_admin_users.rb"
37
- end
14
+ end
15
+
16
+ def generate_files
17
+ puts '*** WARNING - Generating configuration files. Make sure you have backed up any files before overwriting them. ***'
18
+
19
+ # config helper
20
+ copy_file 'app/helpers/casein/config_helper.rb', 'app/helpers/casein/config_helper.rb'
21
+
22
+ # initial view partials
23
+ copy_file 'app/views/casein/layouts/_tab_navigation.html.erb', 'app/views/casein/layouts/_tab_navigation.html.erb'
24
+ copy_file 'app/views/casein/layouts/_top_navigation.html.erb', 'app/views/casein/layouts/_top_navigation.html.erb'
25
+
26
+ # robots.txt
27
+ puts " ** Overwrite if you haven't yet modified your robots.txt, otherwise add disallow rules for /casein and /admin manually **"
28
+ copy_file 'public/robots.txt', 'public/robots.txt'
29
+
30
+ # blank stylesheets and JavaScript files
31
+ copy_file 'app/assets/stylesheets/casein/custom.scss', 'app/assets/stylesheets/casein/custom.scss'
32
+ copy_file 'app/assets/javascripts/casein/custom.js', 'app/assets/javascripts/casein/custom.js'
33
+ copy_file 'app/assets/stylesheets/casein/auth_custom.scss', 'app/assets/stylesheets/casein/auth_custom.scss'
34
+ copy_file 'app/assets/javascripts/casein/auth_custom.js', 'app/assets/javascripts/casein/auth_custom.js'
35
+
36
+ # migrations
37
+ migration_template 'db/migrate/casein_create_admin_users.rb', 'db/migrate/casein_create_admin_users.rb'
38
+ end
38
39
  end
39
- end
40
+ end
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Casein
2
4
  module ConfigHelper
3
-
4
5
  # Name of website or client — used throughout Casein.
5
6
  def casein_config_website_name
6
7
  'Casein'
@@ -24,32 +25,31 @@ module Casein
24
25
  def casein_config_email_from_address
25
26
  'donotreply@caseincms.com'
26
27
  end
27
-
28
+
28
29
  # The initial page the user is shown after they sign in or click the logo. Probably this should be set to the first tab.
29
30
  # Do not point this at casein/index!
30
31
  def casein_config_dashboard_url
31
32
  url_for controller: :casein, action: :blank
32
33
  end
33
-
34
+
34
35
  # A list of stylesheets to include. Do not remove the core casein/casein, but you can change the load order, if required.
35
36
  def casein_config_stylesheet_includes
36
37
  %w[casein/casein casein/custom]
37
38
  end
38
-
39
+
39
40
  # A list of JavaScript files to include. Do not remove the core casein/casein, but you can change the load order, if required.
40
41
  def casein_config_javascript_includes
41
42
  %w[casein/casein casein/custom]
42
43
  end
43
44
 
44
- # A list of stylesheets to include in the authentication layout. Do not remove the core casein/login, but you can change the load order, if required.
45
+ # A list of stylesheets to include in the authentication layout. Do not remove the core casein/login, but you can change the load order, if required.
45
46
  def casein_config_auth_stylesheet_includes
46
47
  %w[casein/login casein/auth_custom]
47
48
  end
48
-
49
+
49
50
  # A list of JavaScript files to includein the authentication layout. Do not remove the core casein/casein, but you can change the load order, if required.
50
51
  def casein_config_auth_javascript_includes
51
52
  %w[casein/casein casein/auth_custom]
52
53
  end
53
-
54
54
  end
55
- end
55
+ end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CaseinCreateAdminUsers < ActiveRecord::Migration[5.1]
2
-
3
4
  def change
4
- create_table :casein_admin_users do |t|
5
+ create_table :casein_admin_users do |t|
5
6
  t.string :login, null: false
6
7
  t.string :name
7
8
  t.string :email
@@ -22,5 +23,4 @@ class CaseinCreateAdminUsers < ActiveRecord::Migration[5.1]
22
23
  t.timestamps
23
24
  end
24
25
  end
25
-
26
- end
26
+ end
@@ -1,24 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Casein
2
4
  class ScaffoldGenerator < Rails::Generators::NamedBase
3
-
4
5
  include Casein::CaseinHelper
5
6
  include Rails::Generators::Migration
6
- source_root File.expand_path('../templates', __FILE__)
7
+ source_root File.expand_path('templates', __dir__)
7
8
 
8
- argument :attributes, type: :array, required: true, desc: "attribute list required"
9
+ argument :attributes, type: :array, required: true, desc: 'attribute list required'
9
10
 
10
11
  class_options create_model_and_migration: false, read_only: false, no_index: false
11
12
 
12
- def self.next_migration_number dirname
13
+ def self.next_migration_number(dirname)
13
14
  if ActiveRecord::Base.timestamped_migrations
14
- Time.now.utc.strftime("%Y%m%d%H%M%S")
15
+ Time.now.utc.strftime('%Y%m%d%H%M%S')
15
16
  else
16
- "%.3d" % (current_migration_number(dirname) + 1)
17
+ format('%.3d', (current_migration_number(dirname) + 1))
17
18
  end
18
19
  end
19
20
 
20
21
  def generate_files
21
- @plural_route = (plural_name != singular_name) ? plural_name : "#{plural_name}_index"
22
+ @plural_route = plural_name
22
23
  @read_only = options[:read_only]
23
24
  @no_index = options[:no_index]
24
25
 
@@ -39,15 +40,15 @@ module Casein
39
40
  end
40
41
  end
41
42
 
42
- protected
43
+ protected
43
44
 
44
- #replacements for standard Rails generator route. This one only adds once
45
+ # replacements for standard Rails generator route. This one only adds once
45
46
  def add_namespace_to_routes
46
- puts " casein adding namespace to routes.rb"
47
+ puts ' casein adding namespace to routes.rb'
47
48
  file_to_update = Rails.root + 'config/routes.rb'
48
- line_to_add = "namespace :casein do"
49
+ line_to_add = 'namespace :casein do'
49
50
  insert_sentinel = 'Application.routes.draw do'
50
- if File.read(file_to_update).scan(/(#{Regexp.escape("#{line_to_add}")})/mi).blank?
51
+ if File.read(file_to_update).scan(/(#{Regexp.escape(line_to_add.to_s)})/mi).blank?
51
52
  gsub_add_once plural_name, file_to_update, "\n#Casein routes\n" + line_to_add + "\nend\n", insert_sentinel
52
53
  end
53
54
  end
@@ -56,18 +57,18 @@ module Casein
56
57
  puts " casein adding #{plural_name} resources to routes.rb"
57
58
  file_to_update = Rails.root + 'config/routes.rb'
58
59
 
59
- if @no_index && @read_only
60
- line_to_add = "resources :#{plural_name}, only: [:show]"
61
- elsif @no_index
62
- line_to_add = "resources :#{plural_name}, except: [:index]"
63
- elsif @read_only
64
- line_to_add = "resources :#{plural_name}, only: [:index, :show]"
65
- else
66
- line_to_add = "resources :#{plural_name}"
67
- end
60
+ line_to_add = if @no_index && @read_only
61
+ "resources :#{plural_name}, only: [:show]"
62
+ elsif @no_index
63
+ "resources :#{plural_name}, except: [:index]"
64
+ elsif @read_only
65
+ "resources :#{plural_name}, only: [:index, :show]"
66
+ else
67
+ "resources :#{plural_name}"
68
+ end
68
69
 
69
70
  insert_sentinel = 'namespace :casein do'
70
- gsub_add_once plural_name, file_to_update, " " + line_to_add, insert_sentinel
71
+ gsub_add_once plural_name, file_to_update, ' ' + line_to_add, insert_sentinel
71
72
  end
72
73
 
73
74
  def add_to_navigation
@@ -78,9 +79,9 @@ module Casein
78
79
  gsub_add_once plural_name, file_to_update, line_to_add, insert_sentinel
79
80
  end
80
81
 
81
- def gsub_add_once m, file, line, sentinel
82
+ def gsub_add_once(_m, file, line, sentinel)
82
83
  unless options[:pretend]
83
- gsub_file file, /(#{Regexp.escape("\n#{line}")})/mi do |match|
84
+ gsub_file file, /(#{Regexp.escape("\n#{line}")})/mi do |_match|
84
85
  ''
85
86
  end
86
87
  gsub_file file, /(#{Regexp.escape(sentinel)})/mi do |match|
@@ -96,13 +97,13 @@ module Casein
96
97
 
97
98
  def field_type(type)
98
99
  case type.to_s.to_sym
99
- when :integer, :float, :decimal then :text_field
100
- when :date then :date_select
101
- when :time, :timestamp then :time_select
102
- when :datetime then :datetime_select
103
- when :string then :text_field
104
- when :text then :text_area
105
- when :boolean then :check_box
100
+ when :integer, :float, :decimal then :text_field
101
+ when :date then :date_select
102
+ when :time, :timestamp then :time_select
103
+ when :datetime then :datetime_select
104
+ when :string then :text_field
105
+ when :text then :text_area
106
+ when :boolean then :check_box
106
107
  else
107
108
  :text_field
108
109
  end
@@ -1,33 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'authlogic'
2
4
  require 'securerandom'
3
5
 
4
6
  namespace :casein do
5
-
6
7
  namespace :users do
7
-
8
- desc "Create default admin user"
8
+ desc 'Create default admin user'
9
9
  task create_admin: :environment do
10
+ raise 'Usage: specify email address, e.g. rake [task] email=mail@caseincms.com [(optional) password=mypassword]' unless ENV.include?('email')
10
11
 
11
- raise "Usage: specify email address, e.g. rake [task] email=mail@caseincms.com [(optional) password=mypassword]" unless ENV.include?("email")
12
12
  password = ENV['password'] || SecureRandom.hex
13
- admin = Casein::AdminUser.new({ login: 'admin', name: 'Admin', email: ENV['email'], access_level: $CASEIN_USER_ACCESS_LEVEL_ADMIN, password: password, password_confirmation: password })
13
+ admin = Casein::AdminUser.new(login: 'admin', name: 'Admin', email: ENV['email'], access_level: $CASEIN_USER_ACCESS_LEVEL_ADMIN, password: password, password_confirmation: password)
14
14
 
15
- unless admin.save
16
- puts "[Casein] Failed. Rails said:"
17
- puts admin.errors.full_messages.join("\n")
18
- else
15
+ if admin.save
19
16
  puts "[Casein] Created new admin user with username 'admin' and password '#{password}'"
17
+ else
18
+ puts '[Casein] Failed. Rails said:'
19
+ puts admin.errors.full_messages.join("\n")
20
20
  end
21
21
  end
22
22
 
23
- desc "Remove all users"
23
+ desc 'Remove all users'
24
24
  task remove_all: :environment do
25
25
  users = Casein::AdminUser.all
26
26
  num_users = users.size
27
27
  users.destroy_all
28
28
  puts "[Casein] Removed #{num_users} user(s)"
29
29
  end
30
-
31
30
  end
32
-
33
31
  end