plug 0.1.19 → 0.1.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +31 -9
  3. data/Rakefile +3 -1
  4. data/app/assets/javascripts/plug/application.js +5 -0
  5. data/app/assets/javascripts/plug/trix-core.js +12 -0
  6. data/app/assets/stylesheets/plug/application.scss +2 -0
  7. data/app/assets/stylesheets/plug/blocks/_state.scss +4 -2
  8. data/app/assets/stylesheets/plug/milligram.scss +632 -599
  9. data/app/assets/stylesheets/plug/trix-overrides.scss +8 -0
  10. data/app/assets/stylesheets/plug/trix.scss +374 -0
  11. data/app/controllers/plug/api/api_controller.rb +2 -0
  12. data/app/controllers/plug/api/features_controller.rb +21 -0
  13. data/app/controllers/plug/api/site_notices_controller.rb +2 -0
  14. data/app/controllers/plug/application_controller.rb +5 -3
  15. data/app/controllers/plug/features_controller.rb +13 -19
  16. data/app/controllers/plug/site_notices_controller.rb +13 -19
  17. data/app/helpers/plug/application_helper.rb +2 -0
  18. data/app/mailers/plug/application_mailer.rb +2 -0
  19. data/app/models/plug/application_record.rb +2 -0
  20. data/app/models/plug/concerns/model_helpers.rb +6 -5
  21. data/app/models/plug/feature.rb +2 -0
  22. data/app/models/plug/resources/feature.rb +15 -0
  23. data/app/models/plug/resources/site_notice.rb +2 -2
  24. data/app/models/plug/site_notice.rb +2 -1
  25. data/app/services/plug/task_execution_service.rb +2 -0
  26. data/app/views/plug/features/index.html.haml +6 -6
  27. data/app/views/plug/shared/_head.html.haml +1 -1
  28. data/app/views/plug/shared/_nav.html.haml +1 -1
  29. data/app/views/plug/site_notices/_form.html.haml +3 -2
  30. data/app/views/plug/site_notices/index.html.haml +7 -7
  31. data/config/routes.rb +4 -0
  32. data/db/migrate/20171207020316_create_plug_features.rb +1 -1
  33. data/db/migrate/20180128202026_add_notice_to_plug_features.rb +1 -1
  34. data/db/migrate/20180403024712_create_plug_site_notices.rb +1 -1
  35. data/db/migrate/20180424015828_add_theme_to_plug_site_notice.rb +2 -0
  36. data/lib/generators/plug/install_generator.rb +3 -1
  37. data/lib/generators/plug/templates/plug.rb +1 -0
  38. data/lib/plug.rb +15 -13
  39. data/lib/plug/configuration.rb +11 -9
  40. data/lib/plug/constraint.rb +4 -2
  41. data/lib/plug/engine.rb +4 -0
  42. data/lib/plug/version.rb +3 -1
  43. data/lib/tasks/plug_tasks.rake +1 -0
  44. metadata +32 -29
  45. data/app/models/plug/concerns/themeable.rb +0 -16
@@ -1,12 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_dependency 'plug/application_controller'
2
4
 
3
5
  module Plug
4
6
  class SiteNoticesController < ApplicationController
5
- if Rails.version.to_i < 5
6
- before_filter :set_site_notice, only: [:edit, :update, :destroy]
7
- else
8
- before_action :set_site_notice, only: [:edit, :update, :destroy]
9
- end
7
+ before_action :set_site_notice, only: %i[edit update destroy]
10
8
 
11
9
  # GET /site_notices
12
10
  def index
@@ -37,7 +35,7 @@ module Plug
37
35
 
38
36
  # PATCH/PUT /site_notices/1
39
37
  def update
40
- if @site_notice.update_attributes(site_notice_params)
38
+ if @site_notice.update(site_notice_params)
41
39
  redirect_to site_notices_path, notice: 'Site Notice was successfully updated.'
42
40
  else
43
41
  render :edit
@@ -51,19 +49,15 @@ module Plug
51
49
  end
52
50
 
53
51
  private
54
- # Use callbacks to share common setup or constraints between actions.
55
- def set_site_notice
56
- @site_notice = SiteNotice.find(params[:id])
57
- end
58
52
 
59
- # Only allow a trusted parameter "white list" through.
60
- # TODO: Strong params not available for older Rails
61
- def site_notice_params
62
- if Rails.version.to_i < 5
63
- ActiveSupport::HashWithIndifferentAccess.new(params[:site_notice])
64
- else
65
- params.require(:site_notice).permit(:name, :notice, :state, :theme)
66
- end
67
- end
53
+ # Use callbacks to share common setup or constraints between actions.
54
+ def set_site_notice
55
+ @site_notice = SiteNotice.find(params[:id])
56
+ end
57
+
58
+ # Only allow a trusted parameter "white list" through.
59
+ def site_notice_params
60
+ params.require(:site_notice).permit(:name, :notice, :state, :theme)
61
+ end
68
62
  end
69
63
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  module ApplicationHelper
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  class ApplicationMailer < ActionMailer::Base
3
5
  default from: 'from@example.com'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  class ApplicationRecord < ActiveRecord::Base
3
5
  self.abstract_class = true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
 
3
5
  module Plug
@@ -9,9 +11,9 @@ module Plug
9
11
  include AASM
10
12
 
11
13
  # Validations
12
- validates :name, presence: { message: "#{self.humanized_class_name} name is required" },
13
- uniqueness: { message: "#{self.humanized_class_name} name must be unique", case_sensitive: false }
14
- validates :state, presence: { message: "#{self.humanized_class_name} state is required" }
14
+ validates :name, presence: { message: "#{humanized_class_name} name is required" },
15
+ uniqueness: { message: "#{humanized_class_name} name must be unique", case_sensitive: false }
16
+ validates :state, presence: { message: "#{humanized_class_name} state is required" }
15
17
 
16
18
  # Callbacks
17
19
  before_save { self.slug = name.parameterize }
@@ -32,12 +34,11 @@ module Plug
32
34
  transitions from: :enabled, to: :disabled
33
35
  end
34
36
  end
35
-
36
37
  end
37
38
 
38
39
  module ClassMethods
39
40
  def humanized_class_name
40
- self.name.demodulize.underscore.humanize.capitalize
41
+ name.demodulize.underscore.humanize.capitalize
41
42
  end
42
43
  end
43
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  class Feature < ApplicationRecord
3
5
  include AASM
@@ -0,0 +1,15 @@
1
+ module Plug
2
+ module Resources
3
+ class Feature < ActiveResource::Base
4
+ self.site = Plug.api_path
5
+
6
+ def enabled?
7
+ state == 'enabled'
8
+ end
9
+
10
+ def disabled?
11
+ state == 'disabled'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,8 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  module Resources
3
5
  class SiteNotice < ActiveResource::Base
4
- include Plug::Concerns::Themeable
5
-
6
6
  self.site = Plug.api_path
7
7
 
8
8
  def enabled?
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  class SiteNotice < ApplicationRecord
3
5
  include AASM
4
6
  include Plug::Concerns::ModelHelpers
5
- include Plug::Concerns::Themeable
6
7
  end
7
8
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake'
2
4
 
3
5
  module Plug
@@ -19,10 +19,10 @@
19
19
  %table
20
20
  %thead
21
21
  %tr
22
- %th Name
22
+ %th{ width: 200 } Name
23
23
  %th Description
24
- %th Slug
25
- %th State
24
+ %th{ width: 200 } Slug
25
+ %th{ width: 150, align: 'center' } State
26
26
 
27
27
  - if Plug.allow_delete
28
28
  %th Actions
@@ -33,11 +33,11 @@
33
33
  %td= link_to feature.name, edit_feature_path(feature), class: 'strong'
34
34
  %td= feature.description
35
35
  %td= feature.slug
36
- %td
36
+ %td{ width: 150, align: 'center' }
37
37
  - if feature.state == 'enabled'
38
- %i.fas.fa-check-circle.fa-2x.state__enabled
38
+ %i.fas.fa-check-circle.fa-2x.state.state--enabled
39
39
  - else
40
- %i.fas.fa-times-circle.fa-2x.state__disabled
40
+ %i.fas.fa-times-circle.fa-2x.state.state--disabled
41
41
 
42
42
  - if Plug.allow_delete
43
43
  %td= link_to 'Destroy', feature, method: :delete, data: { confirm: 'Are you sure?' }
@@ -7,4 +7,4 @@
7
7
  = javascript_include_tag 'plug/application'
8
8
  = csrf_meta_tags
9
9
 
10
- %script{ defer: '', src: 'https://use.fontawesome.com/releases/v5.0.4/js/all.js' }
10
+ %script{ defer: '', src: 'https://use.fontawesome.com/releases/v5.13.0/js/all.js' }
@@ -1,7 +1,7 @@
1
1
  %nav.clearfix.nav
2
2
  .float-left
3
3
  %h3
4
- = link_to 'Plug', plug.root_path, class: 'nav__logo'
4
+ = link_to 'plug', plug.root_path, class: 'nav__logo'
5
5
  %small /unplug features
6
6
  .float-right
7
7
  %ul.menu
@@ -11,13 +11,14 @@
11
11
  = f.text_field :name
12
12
  .field
13
13
  = f.label :notice
14
- = f.text_area :notice, rows: 10
14
+ = f.hidden_field :notice
15
+ %trix-editor{ input: 'site_notice_notice' }
15
16
  .field
16
17
  = f.label :state
17
18
  = f.select :state, ['enabled', 'disabled']
18
19
  .field
19
20
  = f.label :theme
20
- = f.select :theme, Plug.themes.map { |theme| [theme[:name], "#{theme[:style].to_a.map { |s| s.join(':') }.join(';')}"] }
21
+ = f.select :theme, Plug.themes
21
22
  .actions.clearfix
22
23
  .float-left
23
24
  = link_to 'Back', site_notices_path, class: 'button'
@@ -15,10 +15,10 @@
15
15
  %table
16
16
  %thead
17
17
  %tr
18
- %th Name
18
+ %th{ width: 200 } Name
19
19
  %th Notice
20
- %th Slug
21
- %th State
20
+ %th{ width: 200 } Slug
21
+ %th{ width: 150, align: 'center' } State
22
22
 
23
23
  - if Plug.allow_delete
24
24
  %th Actions
@@ -27,13 +27,13 @@
27
27
  - @site_notices.each do |site_notice|
28
28
  %tr
29
29
  %td= link_to site_notice.name, edit_site_notice_path(site_notice), class: 'strong'
30
- %td= site_notice.notice
30
+ %td= site_notice.notice.html_safe
31
31
  %td= site_notice.slug
32
- %td
32
+ %td{ width: 150, align: 'center' }
33
33
  - if site_notice.state == 'enabled'
34
- %i.fas.fa-check-circle.fa-2x.state__enabled
34
+ %i.fas.fa-check-circle.fa-2x.state.state--enabled
35
35
  - else
36
- %i.fas.fa-times-circle.fa-2x.state__disabled
36
+ %i.fas.fa-times-circle.fa-2x.state.state--disabled
37
37
 
38
38
  - if Plug.allow_delete
39
39
  %td= link_to 'Destroy', site_notice, method: :delete, data: { confirm: 'Are you sure?' }
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Plug::Engine.routes.draw do
2
4
  root to: 'features#index'
3
5
 
@@ -10,6 +12,8 @@ Plug::Engine.routes.draw do
10
12
  namespace :api, defaults: { format: :json } do
11
13
  get '/site_notices/:slug', to: 'site_notices#show'
12
14
  get '/site_notices', to: 'site_notices#index'
15
+ get '/features/:slug', to: 'features#show'
16
+ get '/features', to: 'features#index'
13
17
  end
14
18
 
15
19
  post '/task', to: 'features#task_execution', as: :task_execution
@@ -1,4 +1,4 @@
1
- class CreatePlugFeatures < ActiveRecord::Migration
1
+ class CreatePlugFeatures < ActiveRecord::Migration[5.1]
2
2
  def change
3
3
  create_table :plug_features do |t|
4
4
  t.string :name
@@ -1,4 +1,4 @@
1
- class AddNoticeToPlugFeatures < ActiveRecord::Migration
1
+ class AddNoticeToPlugFeatures < ActiveRecord::Migration[5.1]
2
2
  def change
3
3
  add_column :plug_features, :notice, :text
4
4
  end
@@ -1,4 +1,4 @@
1
- class CreatePlugSiteNotices < ActiveRecord::Migration
1
+ class CreatePlugSiteNotices < ActiveRecord::Migration[5.1]
2
2
  def change
3
3
  create_table :plug_site_notices do |t|
4
4
  t.string :name
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddThemeToPlugSiteNotice < ActiveRecord::Migration[5.1]
2
4
  def change
3
5
  add_column :plug_site_notices, :theme, :string
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  class InstallGenerator < Rails::Generators::Base
3
- source_root File.expand_path('../templates', __FILE__)
5
+ source_root File.expand_path('templates', __dir__)
4
6
 
5
7
  def copy_initializer_file
6
8
  copy_file 'plug.rb', 'config/initializers/plug.rb'
@@ -3,4 +3,5 @@
3
3
  Plug.configure do |config|
4
4
  config.auth_user = 'admin'
5
5
  config.auth_password = 'password'
6
+ config.themes = ['default', 'dark']
6
7
  end
data/lib/plug.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'plug/engine'
2
4
  require 'plug/configuration'
3
5
  require 'plug/constraint'
@@ -12,9 +14,9 @@ module Plug
12
14
  #
13
15
  # @return [Boolean] true - Feature found and enabled | true - Feature not found (We don't want to block) | false - Feature was set to disabled
14
16
  def enabled?(arg)
15
- return get_feature(arg).enabled?
16
- rescue
17
- return true
17
+ get_feature(arg).enabled?
18
+ rescue StandardError
19
+ true
18
20
  end
19
21
 
20
22
  #
@@ -27,21 +29,21 @@ module Plug
27
29
  feature = get_feature(arg)
28
30
 
29
31
  render_notice(feature.notice, &block) unless feature.enabled? || feature.notice.blank?
30
- rescue
31
- return nil
32
+ rescue StandardError
33
+ nil
32
34
  end
33
35
 
34
36
  private
35
37
 
36
- def get_feature(arg)
37
- arg = arg.to_s if arg.is_a? Symbol
38
+ def get_feature(arg)
39
+ arg = arg.to_s if arg.is_a? Symbol
38
40
 
39
- return Plug::Feature.slug_and_name(arg).first
40
- end
41
+ return Plug::Feature.slug_and_name(arg).first
42
+ end
41
43
 
42
- def render_notice(notice, &block)
43
- return notice unless block_given?
44
+ def render_notice(notice, &block)
45
+ return notice unless block_given?
44
46
 
45
- yield(notice)
46
- end
47
+ yield(notice)
48
+ end
47
49
  end
@@ -1,26 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  module Configuration
3
5
  AUTH_USER = ''
4
6
  AUTH_PASSWORD = ''
5
7
  ALLOW_DELETE = true
6
8
 
7
- VALID_OPTIONS_KEYS = [
8
- :auth_user,
9
- :auth_password,
10
- :allow_delete,
11
- :buttons,
12
- :api_path,
13
- :themes
9
+ VALID_OPTIONS_KEYS = %i[
10
+ auth_user
11
+ auth_password
12
+ allow_delete
13
+ buttons
14
+ api_path
15
+ themes
14
16
  ].freeze
15
17
 
16
- attr_accessor *VALID_OPTIONS_KEYS
18
+ attr_accessor(*VALID_OPTIONS_KEYS)
17
19
 
18
20
  def configure
19
21
  yield self
20
22
  end
21
23
 
22
24
  def options
23
- Hash[ * VALID_OPTIONS_KEYS.map { |key| [key, send(key)] }.flatten ]
25
+ Hash[* VALID_OPTIONS_KEYS.map { |key| [key, send(key)] }.flatten]
24
26
  end
25
27
  end
26
28
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  class Constraint
3
5
  def initialize(feature)
4
6
  @feature = feature
5
7
  end
6
8
 
7
- def matches?(request)
9
+ def matches?(_request)
8
10
  Plug.enabled?(@feature)
9
- rescue
11
+ rescue StandardError
10
12
  true
11
13
  end
12
14
  end
data/lib/plug/engine.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Require engine dependencies
2
4
  require 'haml-rails'
3
5
  require 'aasm'
@@ -9,6 +11,8 @@ module Plug
9
11
 
10
12
  config.generators do |g|
11
13
  g.test_framework :rspec
14
+ g.fixture_replacement :factory_bot
15
+ g.factory_bot dir: 'spec/factories'
12
16
  end
13
17
  end
14
18
  end