plug 0.1.19 → 0.1.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -9
- data/Rakefile +3 -1
- data/app/assets/javascripts/plug/application.js +5 -0
- data/app/assets/javascripts/plug/trix-core.js +12 -0
- data/app/assets/stylesheets/plug/application.scss +2 -0
- data/app/assets/stylesheets/plug/blocks/_state.scss +4 -2
- data/app/assets/stylesheets/plug/milligram.scss +632 -599
- data/app/assets/stylesheets/plug/trix-overrides.scss +8 -0
- data/app/assets/stylesheets/plug/trix.scss +374 -0
- data/app/controllers/plug/api/api_controller.rb +2 -0
- data/app/controllers/plug/api/features_controller.rb +21 -0
- data/app/controllers/plug/api/site_notices_controller.rb +2 -0
- data/app/controllers/plug/application_controller.rb +5 -3
- data/app/controllers/plug/features_controller.rb +13 -19
- data/app/controllers/plug/site_notices_controller.rb +13 -19
- data/app/helpers/plug/application_helper.rb +2 -0
- data/app/mailers/plug/application_mailer.rb +2 -0
- data/app/models/plug/application_record.rb +2 -0
- data/app/models/plug/concerns/model_helpers.rb +6 -5
- data/app/models/plug/feature.rb +2 -0
- data/app/models/plug/resources/feature.rb +15 -0
- data/app/models/plug/resources/site_notice.rb +2 -2
- data/app/models/plug/site_notice.rb +2 -1
- data/app/services/plug/task_execution_service.rb +2 -0
- data/app/views/plug/features/index.html.haml +6 -6
- data/app/views/plug/shared/_head.html.haml +1 -1
- data/app/views/plug/shared/_nav.html.haml +1 -1
- data/app/views/plug/site_notices/_form.html.haml +3 -2
- data/app/views/plug/site_notices/index.html.haml +7 -7
- data/config/routes.rb +4 -0
- data/db/migrate/20171207020316_create_plug_features.rb +1 -1
- data/db/migrate/20180128202026_add_notice_to_plug_features.rb +1 -1
- data/db/migrate/20180403024712_create_plug_site_notices.rb +1 -1
- data/db/migrate/20180424015828_add_theme_to_plug_site_notice.rb +2 -0
- data/lib/generators/plug/install_generator.rb +3 -1
- data/lib/generators/plug/templates/plug.rb +1 -0
- data/lib/plug.rb +15 -13
- data/lib/plug/configuration.rb +11 -9
- data/lib/plug/constraint.rb +4 -2
- data/lib/plug/engine.rb +4 -0
- data/lib/plug/version.rb +3 -1
- data/lib/tasks/plug_tasks.rake +1 -0
- metadata +32 -29
- 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
|
-
|
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.
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
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: "#{
|
13
|
-
uniqueness: { message: "#{
|
14
|
-
validates :state, presence: { message: "#{
|
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
|
-
|
41
|
+
name.demodulize.underscore.humanize.capitalize
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
data/app/models/plug/feature.rb
CHANGED
@@ -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.
|
38
|
+
%i.fas.fa-check-circle.fa-2x.state.state--enabled
|
39
39
|
- else
|
40
|
-
%i.fas.fa-times-circle.fa-2x.
|
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?' }
|
@@ -11,13 +11,14 @@
|
|
11
11
|
= f.text_field :name
|
12
12
|
.field
|
13
13
|
= f.label :notice
|
14
|
-
= f.
|
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
|
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.
|
34
|
+
%i.fas.fa-check-circle.fa-2x.state.state--enabled
|
35
35
|
- else
|
36
|
-
%i.fas.fa-times-circle.fa-2x.
|
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,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('
|
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'
|
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
|
-
|
16
|
-
rescue
|
17
|
-
|
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
|
-
|
32
|
+
rescue StandardError
|
33
|
+
nil
|
32
34
|
end
|
33
35
|
|
34
36
|
private
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
+
def get_feature(arg)
|
39
|
+
arg = arg.to_s if arg.is_a? Symbol
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
+
return Plug::Feature.slug_and_name(arg).first
|
42
|
+
end
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
+
def render_notice(notice, &block)
|
45
|
+
return notice unless block_given?
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
+
yield(notice)
|
48
|
+
end
|
47
49
|
end
|
data/lib/plug/configuration.rb
CHANGED
@@ -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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
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[
|
25
|
+
Hash[* VALID_OPTIONS_KEYS.map { |key| [key, send(key)] }.flatten]
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
data/lib/plug/constraint.rb
CHANGED
@@ -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?(
|
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
|