plug 0.1.14 → 0.1.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +37 -1
  3. data/app/assets/javascripts/plug/application.js +5 -0
  4. data/app/assets/javascripts/plug/trix-core.js +12 -0
  5. data/app/assets/stylesheets/plug/application.scss +4 -1
  6. data/app/assets/stylesheets/plug/blocks/_menu.scss +11 -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 +7 -0
  12. data/app/controllers/plug/api/site_notices_controller.rb +21 -0
  13. data/app/controllers/plug/application_controller.rb +2 -0
  14. data/app/controllers/plug/features_controller.rb +3 -5
  15. data/app/controllers/plug/site_notices_controller.rb +69 -0
  16. data/app/models/plug/concerns/model_helpers.rb +45 -0
  17. data/app/models/plug/feature.rb +1 -25
  18. data/app/models/plug/resources/site_notice.rb +17 -0
  19. data/app/models/plug/site_notice.rb +6 -0
  20. data/app/services/plug/task_execution_service.rb +18 -0
  21. data/app/views/plug/features/index.html.haml +18 -15
  22. data/app/views/plug/shared/_head.html.haml +1 -1
  23. data/app/views/plug/shared/_nav.html.haml +8 -5
  24. data/app/views/plug/site_notices/_form.html.haml +26 -0
  25. data/app/views/plug/site_notices/edit.html.haml +5 -0
  26. data/app/views/plug/site_notices/index.html.haml +41 -0
  27. data/app/views/plug/site_notices/new.html.haml +7 -0
  28. data/config/routes.rb +11 -1
  29. data/db/migrate/20180403024712_create_plug_site_notices.rb +15 -0
  30. data/db/migrate/20180424015828_add_theme_to_plug_site_notice.rb +5 -0
  31. data/lib/generators/plug/templates/plug.rb +1 -0
  32. data/lib/plug/configuration.rb +3 -1
  33. data/lib/plug/version.rb +1 -1
  34. metadata +38 -8
@@ -0,0 +1,45 @@
1
+ require 'active_support/concern'
2
+
3
+ module Plug
4
+ module Concerns
5
+ module ModelHelpers
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ include AASM
10
+
11
+ # 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" }
15
+
16
+ # Callbacks
17
+ before_save { self.slug = name.parameterize }
18
+
19
+ # Scopes
20
+ scope :slug_and_name, ->(arg) { where('slug = ? OR name = ?', arg, arg) }
21
+
22
+ # States
23
+ aasm column: :state do
24
+ state :enabled, initial: true
25
+ state :disabled
26
+
27
+ event :enable do
28
+ transitions from: :disabled, to: :enabled
29
+ end
30
+
31
+ event :disable do
32
+ transitions from: :enabled, to: :disabled
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ module ClassMethods
39
+ def humanized_class_name
40
+ self.name.demodulize.underscore.humanize.capitalize
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,30 +1,6 @@
1
1
  module Plug
2
2
  class Feature < ApplicationRecord
3
3
  include AASM
4
-
5
- # Validations
6
- validates :name, presence: { message: 'Feature name is required' },
7
- uniqueness: { message: 'Feature name must be unique', case_sensitive: false }
8
- validates :state, presence: { message: 'Feature state is required' }
9
-
10
- # Callbacks
11
- before_save { self.slug = name.parameterize }
12
-
13
- # Scopes
14
- scope :slug_and_name, ->(arg) { where('slug = ? OR name = ?', arg, arg) }
15
-
16
- # States
17
- aasm column: :state do
18
- state :enabled, initial: true
19
- state :disabled
20
-
21
- event :enable do
22
- transitions from: :disabled, to: :enabled
23
- end
24
-
25
- event :disable do
26
- transitions from: :enabled, to: :disabled
27
- end
28
- end
4
+ include Plug::Concerns::ModelHelpers
29
5
  end
30
6
  end
@@ -0,0 +1,17 @@
1
+ module Plug
2
+ module Resources
3
+ class SiteNotice < ActiveResource::Base
4
+ include Plug::Concerns::Themeable
5
+
6
+ self.site = Plug.api_path
7
+
8
+ def enabled?
9
+ state == 'enabled'
10
+ end
11
+
12
+ def disabled?
13
+ state == 'disabled'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ module Plug
2
+ class SiteNotice < ApplicationRecord
3
+ include AASM
4
+ include Plug::Concerns::ModelHelpers
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ require 'rake'
2
+
3
+ module Plug
4
+ class TaskExecutionService
5
+ attr_reader :name
6
+
7
+ def initialize(name: nil)
8
+ raise 'Task name is required' if name.nil?
9
+
10
+ @name = name
11
+ end
12
+
13
+ def call
14
+ Rails.application.load_tasks
15
+ Rake::Task[name].execute
16
+ end
17
+ end
18
+ end
@@ -1,15 +1,15 @@
1
- .row
2
- .column
3
- - if notice
4
- %p.notice= sanitize(notice)
1
+ - if notice
2
+ %p.notice= sanitize(notice)
5
3
 
6
- - if alert
7
- %p.alert= sanitize(alert)
4
+ - if alert
5
+ %p.alert= sanitize(alert)
8
6
 
9
- .row
10
- .column
11
- = render partial: 'task', collection: Plug.buttons
7
+ .row
8
+ .column
9
+ = render partial: 'task', collection: Plug.buttons
12
10
 
11
+ .row
12
+ .column
13
13
  .clearfix
14
14
  .float-left
15
15
  %h4 Features
@@ -19,10 +19,13 @@
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
+
27
+ - if Plug.allow_delete
28
+ %th Actions
26
29
 
27
30
  %tbody
28
31
  - @features.each do |feature|
@@ -30,11 +33,11 @@
30
33
  %td= link_to feature.name, edit_feature_path(feature), class: 'strong'
31
34
  %td= feature.description
32
35
  %td= feature.slug
33
- %td
36
+ %td{ width: 150, align: 'center' }
34
37
  - if feature.state == 'enabled'
35
- %i.fas.fa-check-circle.fa-2x.state__enabled
38
+ %i.fas.fa-check-circle.fa-2x.state.state--enabled
36
39
  - else
37
- %i.fas.fa-times-circle.fa-2x.state__disabled
40
+ %i.fas.fa-times-circle.fa-2x.state.state--disabled
38
41
 
39
42
  - if Plug.allow_delete
40
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,6 +1,9 @@
1
1
  %nav.clearfix.nav
2
- .row
3
- .column
4
- %h3
5
- = link_to 'Plug', plug.root_path, class: 'nav__logo'
6
- %small /unplug features
2
+ .float-left
3
+ %h3
4
+ = link_to 'plug', plug.root_path, class: 'nav__logo'
5
+ %small /unplug features
6
+ .float-right
7
+ %ul.menu
8
+ %li= link_to 'Features', plug.root_path
9
+ %li= link_to 'Site Notices', plug.site_notices_path
@@ -0,0 +1,26 @@
1
+ = form_for @site_notice do |f|
2
+ - if @site_notice.errors.any?
3
+ #error_explanation
4
+ %h2= "#{pluralize(@site_notice.errors.count, "error")} prohibited this feature from being saved:"
5
+ %ul
6
+ - @site_notice.errors.full_messages.each do |message|
7
+ %li= message
8
+
9
+ .field
10
+ = f.label :name
11
+ = f.text_field :name
12
+ .field
13
+ = f.label :notice
14
+ = f.hidden_field :notice
15
+ %trix-editor{ input: 'site_notice_notice' }
16
+ .field
17
+ = f.label :state
18
+ = f.select :state, ['enabled', 'disabled']
19
+ .field
20
+ = f.label :theme
21
+ = f.select :theme, Plug.themes
22
+ .actions.clearfix
23
+ .float-left
24
+ = link_to 'Back', site_notices_path, class: 'button'
25
+ .float-right
26
+ = f.submit 'Save'
@@ -0,0 +1,5 @@
1
+ .row
2
+ .column
3
+ %h4 Editing site notice
4
+
5
+ = render 'form'
@@ -0,0 +1,41 @@
1
+ .row
2
+ .column
3
+ - if notice
4
+ %p.notice= sanitize(notice)
5
+
6
+ - if alert
7
+ %p.alert= sanitize(alert)
8
+
9
+ .clearfix
10
+ .float-left
11
+ %h4 Site Notices
12
+ .float-right
13
+ = link_to 'New Site Notice', new_site_notice_path, class: 'button'
14
+
15
+ %table
16
+ %thead
17
+ %tr
18
+ %th{ width: 200 } Name
19
+ %th Notice
20
+ %th{ width: 200 } Slug
21
+ %th{ width: 150, align: 'center' } State
22
+
23
+ - if Plug.allow_delete
24
+ %th Actions
25
+
26
+ %tbody
27
+ - @site_notices.each do |site_notice|
28
+ %tr
29
+ %td= link_to site_notice.name, edit_site_notice_path(site_notice), class: 'strong'
30
+ %td= site_notice.notice.html_safe
31
+ %td= site_notice.slug
32
+ %td{ width: 150, align: 'center' }
33
+ - if site_notice.state == 'enabled'
34
+ %i.fas.fa-check-circle.fa-2x.state.state--enabled
35
+ - else
36
+ %i.fas.fa-times-circle.fa-2x.state.state--disabled
37
+
38
+ - if Plug.allow_delete
39
+ %td= link_to 'Destroy', site_notice, method: :delete, data: { confirm: 'Are you sure?' }
40
+
41
+
@@ -0,0 +1,7 @@
1
+ .row
2
+ .column
3
+ .clearfix
4
+ .float-left
5
+ %h4 New site notice
6
+
7
+ = render 'form'
@@ -1,6 +1,16 @@
1
1
  Plug::Engine.routes.draw do
2
2
  root to: 'features#index'
3
3
 
4
- post '/task', to: 'features#task_execution', as: :task_execution
4
+ # Features
5
5
  resources :features, except: :show
6
+
7
+ # Site notices
8
+ resources :site_notices, except: :show
9
+
10
+ namespace :api, defaults: { format: :json } do
11
+ get '/site_notices/:slug', to: 'site_notices#show'
12
+ get '/site_notices', to: 'site_notices#index'
13
+ end
14
+
15
+ post '/task', to: 'features#task_execution', as: :task_execution
6
16
  end
@@ -0,0 +1,15 @@
1
+ class CreatePlugSiteNotices < ActiveRecord::Migration
2
+ def change
3
+ create_table :plug_site_notices do |t|
4
+ t.string :name
5
+ t.string :slug
6
+ t.text :notice
7
+ t.string :state
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :plug_site_notices, :name
13
+ add_index :plug_site_notices, :slug
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ class AddThemeToPlugSiteNotice < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :plug_site_notices, :theme, :string
4
+ end
5
+ end
@@ -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
@@ -8,7 +8,9 @@ module Plug
8
8
  :auth_user,
9
9
  :auth_password,
10
10
  :allow_delete,
11
- :buttons
11
+ :buttons,
12
+ :api_path,
13
+ :themes
12
14
  ].freeze
13
15
 
14
16
  attr_accessor *VALID_OPTIONS_KEYS
@@ -1,3 +1,3 @@
1
1
  module Plug
2
- VERSION = '0.1.14'
2
+ VERSION = '0.1.21'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-03-13 00:00:00.000000000 Z
12
+ date: 2020-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "<="
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 5.1.4
20
+ version: '0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "<="
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 5.1.4
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: sass-rails
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: activeresource
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: sqlite3
86
100
  requirement: !ruby/object:Gem::Requirement
@@ -194,9 +208,11 @@ files:
194
208
  - app/assets/images/favicon.png
195
209
  - app/assets/javascripts/plug/application.js
196
210
  - app/assets/javascripts/plug/features.js
211
+ - app/assets/javascripts/plug/trix-core.js
197
212
  - app/assets/stylesheets/plug/_settings.scss
198
213
  - app/assets/stylesheets/plug/application.scss
199
214
  - app/assets/stylesheets/plug/blocks/_alert.scss
215
+ - app/assets/stylesheets/plug/blocks/_menu.scss
200
216
  - app/assets/stylesheets/plug/blocks/_nav.scss
201
217
  - app/assets/stylesheets/plug/blocks/_notice.scss
202
218
  - app/assets/stylesheets/plug/blocks/_state.scss
@@ -207,14 +223,23 @@ files:
207
223
  - app/assets/stylesheets/plug/normalize.scss
208
224
  - app/assets/stylesheets/plug/partials/_main.scss
209
225
  - app/assets/stylesheets/plug/partials/_utils.scss
226
+ - app/assets/stylesheets/plug/trix-overrides.scss
227
+ - app/assets/stylesheets/plug/trix.scss
210
228
  - app/assets/stylesheets/plug/variables/_colors.scss
211
229
  - app/assets/stylesheets/plug/variables/_typography.scss
230
+ - app/controllers/plug/api/api_controller.rb
231
+ - app/controllers/plug/api/site_notices_controller.rb
212
232
  - app/controllers/plug/application_controller.rb
213
233
  - app/controllers/plug/features_controller.rb
234
+ - app/controllers/plug/site_notices_controller.rb
214
235
  - app/helpers/plug/application_helper.rb
215
236
  - app/mailers/plug/application_mailer.rb
216
237
  - app/models/plug/application_record.rb
238
+ - app/models/plug/concerns/model_helpers.rb
217
239
  - app/models/plug/feature.rb
240
+ - app/models/plug/resources/site_notice.rb
241
+ - app/models/plug/site_notice.rb
242
+ - app/services/plug/task_execution_service.rb
218
243
  - app/views/layouts/plug/application.html.haml
219
244
  - app/views/plug/features/_form.html.haml
220
245
  - app/views/plug/features/_task.html.haml
@@ -223,9 +248,15 @@ files:
223
248
  - app/views/plug/features/new.html.haml
224
249
  - app/views/plug/shared/_head.html.haml
225
250
  - app/views/plug/shared/_nav.html.haml
251
+ - app/views/plug/site_notices/_form.html.haml
252
+ - app/views/plug/site_notices/edit.html.haml
253
+ - app/views/plug/site_notices/index.html.haml
254
+ - app/views/plug/site_notices/new.html.haml
226
255
  - config/routes.rb
227
256
  - db/migrate/20171207020316_create_plug_features.rb
228
257
  - db/migrate/20180128202026_add_notice_to_plug_features.rb
258
+ - db/migrate/20180403024712_create_plug_site_notices.rb
259
+ - db/migrate/20180424015828_add_theme_to_plug_site_notice.rb
229
260
  - lib/generators/plug/install_generator.rb
230
261
  - lib/generators/plug/templates/plug.rb
231
262
  - lib/plug.rb
@@ -253,8 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
284
  - !ruby/object:Gem::Version
254
285
  version: '0'
255
286
  requirements: []
256
- rubyforge_project:
257
- rubygems_version: 2.6.11
287
+ rubygems_version: 3.0.3
258
288
  signing_key:
259
289
  specification_version: 4
260
290
  summary: Rails engine that can plug/unplug features