plug 0.1.9 → 0.1.11

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65c4f54bdd1454243d715208b42cd5bc3b01e1c2
4
- data.tar.gz: 0d08310207a10fa05ebb95cc0972f6e47fe1c035
3
+ metadata.gz: e1f4d0ccf9b5a963bf47b5ad06b51a717dfe87b7
4
+ data.tar.gz: 32be30ca94c6d54a846f1d8fc312f94e4c2537cc
5
5
  SHA512:
6
- metadata.gz: e590d7750b5fc039237991a2f1a3d26c8cd95cf052ed0538d0be71632f26b344df5c2380606ada39f7524304790aa410dbe474032248e9e10678a837966ecee3
7
- data.tar.gz: eb75ff4a9548a455aefced4c477723638f2c29225783166a421759463258122c870c7d6dc4357ce977093c263327960117fee192b96e00b468f10737cfa119f6
6
+ metadata.gz: a0bd0322aef2ed5d88a4891fbc9b17e9a7f4fb8a337ae7ba67631e4a375df353f1eae3807a051f6432d9426f93a09f419beb058167a92687c3af372b24d8d9db
7
+ data.tar.gz: 66bcb2d3ef8cd2fd8352f4105ab54c89576b5eb8ab896578d530b5ef300667b7fc9aadb4c947a450d293bf29f7ca457a939ffffe37fde2c9efd8473ae099fcea
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # 🔌 Plug
1
+ # Plug [![Maintainability](https://api.codeclimate.com/v1/badges/6246b1cd8e42603c42f6/maintainability)](https://codeclimate.com/github/DigitalNZ/plug/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/6246b1cd8e42603c42f6/test_coverage)](https://codeclimate.com/github/DigitalNZ/plug/test_coverage) [![Build Status](https://travis-ci.org/DigitalNZ/plug.svg?branch=master)](https://travis-ci.org/DigitalNZ/plug)
2
2
 
3
3
  A Rails engine to turn on/off features (Feature flipper).
4
4
 
@@ -6,7 +6,7 @@ A Rails engine to turn on/off features (Feature flipper).
6
6
 
7
7
  - Supports Rails 3 and above
8
8
  - MySQL
9
- - Set notices (WIP)
9
+ - Set notices
10
10
 
11
11
  ### Prerequisites
12
12
 
@@ -55,6 +55,47 @@ Rails.application.routes.draw do
55
55
  end
56
56
  ```
57
57
 
58
+ Notices can be displayed using the `Plug.notice` method.
59
+
60
+ ```erb
61
+ <%= Plug.notice('my-awesome-feature-slug') %>
62
+ ```
63
+
64
+ If you have custom HTML for notice, you can pass a block.
65
+
66
+
67
+ ```erb
68
+ <% Plug.notice('my-awesome-feature-slug') do |notice| %>
69
+ <div class="alert">
70
+ <p><%= notice %></p>
71
+ </div>
72
+ <% end %>
73
+ ```
74
+
75
+ ### Running the tests
76
+
77
+ ```bash
78
+ → bundle exec rspec spec
79
+ ```
80
+
81
+ ### Publishing to `rubygems.org`
82
+
83
+ Make sure to bump the version. Rubygems don't accept version overrides.
84
+
85
+ ```bash
86
+ → gem build plug.gemspec
87
+ → gem push plug-<version>.gem
88
+ ```
89
+
90
+ ### TODOs
91
+
92
+ - Ability to disable all features using one button
93
+ - Add screenshot
94
+ - Allow block parameters for `enabled?` method
95
+ - Versioning of features
96
+ - History of feature activities
97
+
98
+
58
99
  ### Questions/Issues?
59
100
 
60
101
  File a new [issue](https://github.com/boost/plug/issues/new) if you have questions or issues.
@@ -34,4 +34,5 @@
34
34
 
35
35
  // Blocks
36
36
  @import 'blocks/nav';
37
- @import 'blocks/plugs';
37
+ @import 'blocks/notice';
38
+ @import 'blocks/state';
@@ -1,4 +1,7 @@
1
1
  .nav {
2
+ border-bottom: 1px solid $gallery;
3
+ margin-bottom: 2rem;
4
+
2
5
  @include element('logo') {
3
6
  color: $studio;
4
7
  font-weight: 700;
@@ -0,0 +1,4 @@
1
+ .notice {
2
+ background: $gallery;
3
+ padding: 2rem;
4
+ }
@@ -0,0 +1,9 @@
1
+ .state {
2
+ @include element('enabled') {
3
+ color: $jungle-green;
4
+ }
5
+
6
+ @include element('disabled') {
7
+ color: $tall-poppy;
8
+ }
9
+ }
@@ -1,5 +1,7 @@
1
- $white: #ffffff;
2
- $studio: #3F46AD;
3
- $pale-sky: #637381;
4
- $alabaster: #f7f7f7;
5
- $gallery: #ebebeb;
1
+ $white: #ffffff;
2
+ $studio: #3F46AD;
3
+ $pale-sky: #637381;
4
+ $alabaster: #f7f7f7;
5
+ $gallery: #ebebeb;
6
+ $tall-poppy: #c0392b;
7
+ $jungle-green: #27ae60;
@@ -1 +1,5 @@
1
- @import url('https://fonts.googleapis.com/css?family=Roboto');
1
+ @import url('https://fonts.googleapis.com/css?family=Roboto');
2
+
3
+ .strong {
4
+ font-weight: 700;
5
+ }
@@ -3,9 +3,9 @@ require_dependency 'plug/application_controller'
3
3
  module Plug
4
4
  class FeaturesController < ApplicationController
5
5
  if Rails.version.to_i < 5
6
- before_filter :set_feature, only: [:show, :edit, :update, :destroy]
6
+ before_filter :set_feature, only: [:edit, :update, :destroy]
7
7
  else
8
- before_action :set_feature, only: [:show, :edit, :update, :destroy]
8
+ before_action :set_feature, only: [:edit, :update, :destroy]
9
9
  end
10
10
 
11
11
  # GET /features
@@ -14,8 +14,7 @@ module Plug
14
14
  end
15
15
 
16
16
  # GET /features/1
17
- def show
18
- end
17
+ # def show; end
19
18
 
20
19
  # GET /features/new
21
20
  def new
@@ -23,15 +22,14 @@ module Plug
23
22
  end
24
23
 
25
24
  # GET /features/1/edit
26
- def edit
27
- end
25
+ def edit; end
28
26
 
29
27
  # POST /features
30
28
  def create
31
29
  @feature = Feature.new(feature_params)
32
30
 
33
31
  if @feature.save
34
- redirect_to @feature, notice: 'Feature was successfully created.'
32
+ redirect_to features_path, notice: 'Feature was successfully created.'
35
33
  else
36
34
  render :new
37
35
  end
@@ -40,7 +38,7 @@ module Plug
40
38
  # PATCH/PUT /features/1
41
39
  def update
42
40
  if @feature.update_attributes(feature_params)
43
- redirect_to @feature, notice: 'Feature was successfully updated.'
41
+ redirect_to features_path, notice: 'Feature was successfully updated.'
44
42
  else
45
43
  render :edit
46
44
  end
@@ -12,8 +12,14 @@
12
12
  .field
13
13
  = f.label :description
14
14
  = f.text_area :description, rows: 5
15
+ .field
16
+ = f.label :notice
17
+ = f.text_area :notice, rows: 10
15
18
  .field
16
19
  = f.label :state
17
20
  = f.select :state, ['enabled', 'disabled']
18
- .actions
19
- = f.submit 'Save'
21
+ .actions.clearfix
22
+ .float-left
23
+ = link_to 'Back', features_path, class: 'button'
24
+ .float-right
25
+ = f.submit 'Save'
@@ -2,8 +2,4 @@
2
2
  .column
3
3
  %h4 Editing feature
4
4
 
5
- = render 'form'
6
-
7
- = link_to 'Show', @feature, class: 'button'
8
- \|
9
- = link_to 'Back', features_path, class: 'button'
5
+ = render 'form'
@@ -1,6 +1,13 @@
1
1
  .row
2
2
  .column
3
- %h4 Features
3
+ - if notice
4
+ %p.notice= notice
5
+
6
+ .clearfix
7
+ .float-left
8
+ %h4 Features
9
+ .float-right
10
+ = link_to 'New Feature', new_feature_path, class: 'button'
4
11
 
5
12
  %table
6
13
  %thead
@@ -9,21 +16,20 @@
9
16
  %th Description
10
17
  %th Slug
11
18
  %th State
12
- %th
13
- %th
14
- %th
15
19
 
16
20
  %tbody
17
21
  - @features.each do |feature|
18
22
  %tr
19
- %td= feature.name
23
+ %td= link_to feature.name, edit_feature_path(feature), class: 'strong'
20
24
  %td= feature.description
21
25
  %td= feature.slug
22
- %td= feature.state
23
- %td= link_to 'Show', feature
24
- %td= link_to 'Edit', edit_feature_path(feature)
26
+ %td
27
+ - if feature.state == 'enabled'
28
+ %i.fas.fa-check-circle.fa-2x.state__enabled
29
+ - else
30
+ %i.fas.fa-times-circle.fa-2x.state__disabled
25
31
 
26
32
  - if Plug.allow_delete
27
33
  %td= link_to 'Destroy', feature, method: :delete, data: { confirm: 'Are you sure?' }
28
34
 
29
- = link_to 'New Feature', new_feature_path, class: 'button'
35
+
@@ -1,7 +1,7 @@
1
1
  .row
2
2
  .column
3
- %h4 New feature
3
+ .clearfix
4
+ .float-left
5
+ %h4 New feature
4
6
 
5
7
  = render 'form'
6
-
7
- = link_to 'Back', features_path, class: 'button'
@@ -5,4 +5,6 @@
5
5
 
6
6
  = stylesheet_link_tag 'plug/application', media: 'all'
7
7
  = javascript_include_tag 'plug/application'
8
- = csrf_meta_tags
8
+ = csrf_meta_tags
9
+
10
+ %script{ defer: '', src: 'https://use.fontawesome.com/releases/v5.0.4/js/all.js' }
@@ -3,4 +3,4 @@
3
3
  .column
4
4
  %h3
5
5
  = link_to 'Plug', plug.root_path, class: 'nav__logo'
6
- %small /Unplug features
6
+ %small /unplug features
@@ -1,5 +1,5 @@
1
1
  Plug::Engine.routes.draw do
2
2
  root to: 'features#index'
3
3
 
4
- resources :features
4
+ resources :features, except: :show
5
5
  end
@@ -0,0 +1,5 @@
1
+ class AddNoticeToPlugFeatures < ActiveRecord::Migration
2
+ def change
3
+ add_column :plug_features, :notice, :text
4
+ end
5
+ end
@@ -1,13 +1,13 @@
1
1
  module Plug
2
2
  class InstallGenerator < Rails::Generators::Base
3
- source_root File.expand_path("../templates", __FILE__)
3
+ source_root File.expand_path('../templates', __FILE__)
4
4
 
5
5
  def copy_initializer_file
6
6
  copy_file 'plug.rb', 'config/initializers/plug.rb'
7
7
  end
8
8
 
9
9
  def mount_engine
10
- inject_into_file('config/routes.rb', "\n mount Plug::Engine => '/plug', as: 'plug'\n\n", :before => /^end/)
10
+ inject_into_file('config/routes.rb', "\n mount Plug::Engine => '/plug', as: 'plug'\n\n", before: /^end/)
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -6,18 +6,42 @@ module Plug
6
6
  extend self
7
7
  extend Configuration
8
8
 
9
- #
9
+ #
10
10
  # [enabled? returns true of false]
11
11
  # @param arg [String, Symbol] The slug or name of the Feature
12
- #
13
- # @return [Boolean] true - feature found and enabled | true - feature not found (We don't want to block) | false - feature was set to disabled
12
+ #
13
+ # @return [Boolean] true - Feature found and enabled | true - Feature not found (We don't want to block) | false - Feature was set to disabled
14
14
  def enabled?(arg)
15
- arg = arg.to_s if arg.is_a? Symbol
16
- feature = Plug::Feature.slug_and_name(arg).first
17
-
18
- return true unless feature
19
- return feature.enabled?
15
+ return get_feature(arg).enabled?
20
16
  rescue
21
17
  return true
22
18
  end
19
+
20
+ #
21
+ # Returns the notice of a given Feature
22
+ # @param arg [String] The slug or name of the Feature
23
+ # @param &block [Proc] The block of HTML/String for the notice
24
+ #
25
+ # @return [String] The block of HTML/String with notice
26
+ def notice(arg, &block)
27
+ feature = get_feature(arg)
28
+
29
+ render_notice(feature.notice, &block) unless feature.enabled? || feature.notice.blank?
30
+ rescue
31
+ return nil
32
+ end
33
+
34
+ private
35
+
36
+ def get_feature(arg)
37
+ arg = arg.to_s if arg.is_a? Symbol
38
+
39
+ return Plug::Feature.slug_and_name(arg).first
40
+ end
41
+
42
+ def render_notice(notice, &block)
43
+ return notice unless block_given?
44
+
45
+ yield(notice)
46
+ end
23
47
  end
@@ -20,4 +20,4 @@ module Plug
20
20
  Hash[ * VALID_OPTIONS_KEYS.map { |key| [key, send(key)] }.flatten ]
21
21
  end
22
22
  end
23
- end
23
+ end
@@ -10,4 +10,4 @@ module Plug
10
10
  true
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Plug
2
- VERSION = '0.1.9'
2
+ VERSION = '0.1.11'
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.9
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-12-21 00:00:00.000000000 Z
12
+ date: 2018-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -196,8 +196,8 @@ files:
196
196
  - app/assets/stylesheets/plug/_settings.scss
197
197
  - app/assets/stylesheets/plug/application.scss
198
198
  - app/assets/stylesheets/plug/blocks/_nav.scss
199
- - app/assets/stylesheets/plug/blocks/_plugs.scss
200
- - app/assets/stylesheets/plug/features.scss
199
+ - app/assets/stylesheets/plug/blocks/_notice.scss
200
+ - app/assets/stylesheets/plug/blocks/_state.scss
201
201
  - app/assets/stylesheets/plug/foundation_and_overrides.scss
202
202
  - app/assets/stylesheets/plug/milligram.scss
203
203
  - app/assets/stylesheets/plug/mixins/_bem.scss
@@ -217,11 +217,11 @@ files:
217
217
  - app/views/plug/features/edit.html.haml
218
218
  - app/views/plug/features/index.html.haml
219
219
  - app/views/plug/features/new.html.haml
220
- - app/views/plug/features/show.html.haml
221
220
  - app/views/plug/shared/_head.html.haml
222
221
  - app/views/plug/shared/_nav.html.haml
223
222
  - config/routes.rb
224
223
  - db/migrate/20171207020316_create_plug_features.rb
224
+ - db/migrate/20180128202026_add_notice_to_plug_features.rb
225
225
  - lib/generators/plug/install_generator.rb
226
226
  - lib/generators/plug/templates/plug.rb
227
227
  - lib/plug.rb
@@ -1,17 +0,0 @@
1
- .plugs {
2
- margin-top: 2rem;
3
-
4
- @include element('content') {
5
- background: $white;
6
- border: 1px solid $gallery;
7
-
8
- @include element('item') {
9
- padding: .5rem;
10
- border-bottom: 1px solid $gallery;
11
-
12
- &:last-of-type {
13
- border-bottom: none;
14
- }
15
- }
16
- }
17
- }
@@ -1,3 +0,0 @@
1
- // Place all the styles related to the Features controller here.
2
- // They will automatically be included in application.css.
3
- // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -1,20 +0,0 @@
1
- .row
2
- .column
3
- %p#notice= notice
4
-
5
- %p
6
- %b Name:
7
- = @feature.name
8
- %p
9
- %b Description:
10
- = @feature.description
11
- %p
12
- %b Slug:
13
- = @feature.slug
14
- %p
15
- %b State:
16
- = @feature.state
17
-
18
- = link_to 'Edit', edit_feature_path(@feature), class: 'button'
19
- \|
20
- = link_to 'Back', features_path, class: 'button'