plug 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6555955e0bb24af43ac0baf3d82f1c59c36a2701
4
- data.tar.gz: ecb6287ba37b466b037297ee40fb2f7123409eb1
3
+ metadata.gz: e17ce17b82f86550c238b434a1524e79de09d603
4
+ data.tar.gz: 484c4c279b9a86e58b1297581cbd1e2a8537d2b2
5
5
  SHA512:
6
- metadata.gz: 2f38acfd264f4e10bf41bd3c7556b3ba23149c2b5a58f789086258320a6e3839110c08dc29499b144e33265a42390684af2f72e6317088a259d87c512a33327b
7
- data.tar.gz: 780aebfebb76e2dfd0b20866e62765e06d6aa57e656146c560f8259ef1d5d8f3409881576da6cc55f4f42ba44c72e8a2c4f57f9560b629279d0d3616b70bfdca
6
+ metadata.gz: 736df38bac871297d9680d4a00ba0647cdffc5dfe91f2e2b7a10953bc6d7e18d7f2cb59fa87670fda467b9ef735657aea2fb111b2ac5c22b899cd5c9a0c1cb0c
7
+ data.tar.gz: f90d239f21f388e90c02b6b780da25ff987c347a86bbbe51854707ce306cd3866c90d207e58881adce76f5a50de238c993f9530e2248477cf049c385791852db
data/README.md CHANGED
@@ -32,6 +32,7 @@ And run the install generator:
32
32
  ```bash
33
33
  → rails g plug:install
34
34
  → rails g plug:install:migrations
35
+ → rake plug:install:migrations # For Rails <= 3.x
35
36
  → rails db:migrate # Newer version of Rails
36
37
  → rake db:migrate # Older version of Rails
37
38
  → rails s
@@ -81,6 +82,15 @@ Add buttons to the config block to perform rake tasks from the plug dashboard
81
82
  ]
82
83
  ```
83
84
 
85
+ ### Creating new migrations
86
+
87
+ ```bash
88
+ → rails g migration MyAwesomeMigration
89
+ → rails g model MyModel name:string slug:string:index
90
+ → rails db:migrate
91
+ → rails db:migrate RAILS_ENV=test
92
+ ```
93
+
84
94
  ### Running the tests
85
95
 
86
96
  ```bash
@@ -34,7 +34,8 @@
34
34
 
35
35
  // Blocks
36
36
  @import 'blocks/nav';
37
+ @import 'blocks/menu';
37
38
  @import 'blocks/notice';
38
39
  @import 'blocks/alert';
39
40
  @import 'blocks/state';
40
- @import 'blocks/task-button'
41
+ @import 'blocks/task-button';
@@ -0,0 +1,11 @@
1
+ .menu {
2
+ list-style-type: none;
3
+
4
+ li {
5
+ display: inline-block;
6
+ margin-bottom: 0;
7
+ margin-top: 1rem;
8
+ margin-left: 2rem;
9
+ font-weight: bold;
10
+ }
11
+ }
@@ -0,0 +1,7 @@
1
+ module Plug
2
+ module Api
3
+ class ApiController < ActionController::Base
4
+ protect_from_forgery with: :exception
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ require_dependency 'plug/application_controller'
2
+
3
+ module Plug
4
+ module Api
5
+ class SiteNoticesController < ApiController
6
+ # GET /site_notices.json
7
+ def index
8
+ @site_notices = SiteNotice.all
9
+
10
+ render json: @site_notices
11
+ end
12
+
13
+ # GET /site_notices/slug.json
14
+ def show
15
+ @site_notice = SiteNotice.slug_and_name(params[:slug]).first
16
+
17
+ render json: @site_notice
18
+ end
19
+ end
20
+ end
21
+ end
@@ -51,6 +51,7 @@ module Plug
51
51
  end
52
52
 
53
53
  # POST /task
54
+ # TODO: Move this to a separate controller e.g. `tasks_controller.rb`
54
55
  def task_execution
55
56
  begin
56
57
  require 'rake'
@@ -0,0 +1,69 @@
1
+ require_dependency 'plug/application_controller'
2
+
3
+ module Plug
4
+ 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
10
+
11
+ # GET /site_notices
12
+ def index
13
+ @site_notices = SiteNotice.all
14
+ end
15
+
16
+ # GET /site_notices/1
17
+ # def show; end
18
+
19
+ # GET /site_notices/new
20
+ def new
21
+ @site_notice = SiteNotice.new
22
+ end
23
+
24
+ # GET /site_notices/1/edit
25
+ def edit; end
26
+
27
+ # POST /site_notices
28
+ def create
29
+ @site_notice = SiteNotice.new(site_notice_params)
30
+
31
+ if @site_notice.save
32
+ redirect_to site_notices_path, notice: 'Site Notice was successfully created.'
33
+ else
34
+ render :new
35
+ end
36
+ end
37
+
38
+ # PATCH/PUT /site_notices/1
39
+ def update
40
+ if @site_notice.update_attributes(site_notice_params)
41
+ redirect_to site_notices_path, notice: 'Site Notice was successfully updated.'
42
+ else
43
+ render :edit
44
+ end
45
+ end
46
+
47
+ # DELETE /site_notices/1
48
+ def destroy
49
+ @site_notice.destroy
50
+ redirect_to site_notices_url, notice: 'Site Notice was successfully destroyed.'
51
+ end
52
+
53
+ 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
+
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)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -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,15 @@
1
+ module Plug
2
+ module Resources
3
+ class SiteNotice < 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
@@ -0,0 +1,6 @@
1
+ module Plug
2
+ class SiteNotice < ApplicationRecord
3
+ include AASM
4
+ include Plug::Concerns::ModelHelpers
5
+ end
6
+ 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
@@ -23,6 +23,9 @@
23
23
  %th Description
24
24
  %th Slug
25
25
  %th State
26
+
27
+ - if Plug.allow_delete
28
+ %th Actions
26
29
 
27
30
  %tbody
28
31
  - @features.each do |feature|
@@ -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,22 @@
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.text_area :notice, rows: 10
15
+ .field
16
+ = f.label :state
17
+ = f.select :state, ['enabled', 'disabled']
18
+ .actions.clearfix
19
+ .float-left
20
+ = link_to 'Back', site_notices_path, class: 'button'
21
+ .float-right
22
+ = 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 Name
19
+ %th Notice
20
+ %th Slug
21
+ %th 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
31
+ %td= site_notice.slug
32
+ %td
33
+ - if site_notice.state == 'enabled'
34
+ %i.fas.fa-check-circle.fa-2x.state__enabled
35
+ - else
36
+ %i.fas.fa-times-circle.fa-2x.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
@@ -8,7 +8,8 @@ module Plug
8
8
  :auth_user,
9
9
  :auth_password,
10
10
  :allow_delete,
11
- :buttons
11
+ :buttons,
12
+ :api_path
12
13
  ].freeze
13
14
 
14
15
  attr_accessor *VALID_OPTIONS_KEYS
@@ -1,3 +1,3 @@
1
1
  module Plug
2
- VERSION = '0.1.14'
2
+ VERSION = '0.1.15'
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.15
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: 2018-04-06 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
@@ -197,6 +211,7 @@ files:
197
211
  - app/assets/stylesheets/plug/_settings.scss
198
212
  - app/assets/stylesheets/plug/application.scss
199
213
  - app/assets/stylesheets/plug/blocks/_alert.scss
214
+ - app/assets/stylesheets/plug/blocks/_menu.scss
200
215
  - app/assets/stylesheets/plug/blocks/_nav.scss
201
216
  - app/assets/stylesheets/plug/blocks/_notice.scss
202
217
  - app/assets/stylesheets/plug/blocks/_state.scss
@@ -209,12 +224,18 @@ files:
209
224
  - app/assets/stylesheets/plug/partials/_utils.scss
210
225
  - app/assets/stylesheets/plug/variables/_colors.scss
211
226
  - app/assets/stylesheets/plug/variables/_typography.scss
227
+ - app/controllers/plug/api/api_controller.rb
228
+ - app/controllers/plug/api/site_notices_controller.rb
212
229
  - app/controllers/plug/application_controller.rb
213
230
  - app/controllers/plug/features_controller.rb
231
+ - app/controllers/plug/site_notices_controller.rb
214
232
  - app/helpers/plug/application_helper.rb
215
233
  - app/mailers/plug/application_mailer.rb
216
234
  - app/models/plug/application_record.rb
235
+ - app/models/plug/concerns/model_helpers.rb
217
236
  - app/models/plug/feature.rb
237
+ - app/models/plug/resources/site_notice.rb
238
+ - app/models/plug/site_notice.rb
218
239
  - app/views/layouts/plug/application.html.haml
219
240
  - app/views/plug/features/_form.html.haml
220
241
  - app/views/plug/features/_task.html.haml
@@ -223,9 +244,14 @@ files:
223
244
  - app/views/plug/features/new.html.haml
224
245
  - app/views/plug/shared/_head.html.haml
225
246
  - app/views/plug/shared/_nav.html.haml
247
+ - app/views/plug/site_notices/_form.html.haml
248
+ - app/views/plug/site_notices/edit.html.haml
249
+ - app/views/plug/site_notices/index.html.haml
250
+ - app/views/plug/site_notices/new.html.haml
226
251
  - config/routes.rb
227
252
  - db/migrate/20171207020316_create_plug_features.rb
228
253
  - db/migrate/20180128202026_add_notice_to_plug_features.rb
254
+ - db/migrate/20180403024712_create_plug_site_notices.rb
229
255
  - lib/generators/plug/install_generator.rb
230
256
  - lib/generators/plug/templates/plug.rb
231
257
  - lib/plug.rb
@@ -254,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
280
  version: '0'
255
281
  requirements: []
256
282
  rubyforge_project:
257
- rubygems_version: 2.6.11
283
+ rubygems_version: 2.6.13
258
284
  signing_key:
259
285
  specification_version: 4
260
286
  summary: Rails engine that can plug/unplug features