peek-alt-routes 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8ed9b128d4408a50aaa11406a0036f4f9b4983d0
4
+ data.tar.gz: f7b03c7969dfbd0182cc572467606363764f3fd2
5
+ SHA512:
6
+ metadata.gz: 01140f38b2c4664823c49f0e0c6dee7de5f3359ff024f558ec021114063507930b4001d58240fe4920fda0bd32b2cd8f69ec6e1e12e286d0e29c9381e4beadd6
7
+ data.tar.gz: b5835862b728e95c535f593702b78dfb96e1bdec4ca91567890937f09a3ffaf461a37abb0b64d3d06804d36080a45b0def1b81591bf83da7e696175877e95e73
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 1.0
2
+
3
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in peek-git.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Chris Ewald
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # Peek::AltRoutes
2
+
3
+ Easily toggle alternate controllers and routes.
4
+
5
+ ![screen shot 2016-01-15 at 11 33 56 pm](https://cloud.githubusercontent.com/assets/283496/12372401/67358846-bc23-11e5-83eb-20778411ff0d.png)
6
+
7
+
8
+ Things this peek view provides:
9
+
10
+ - A ready to go route constraint for switching controllers/views or routes
11
+ - A toggle button to quickly enable and disable the alternate routes
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'peek-alt-routes
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install peek-alt-routes
26
+
27
+ ## Usage
28
+
29
+ Add the following to your `config/initializers/peek.rb`:
30
+
31
+ ```ruby
32
+ Peek.into Peek::Views::AltRoutes
33
+ ```
34
+
35
+ You may provide a `name` option to the Peek view to set the button display text:
36
+
37
+ ```ruby
38
+ Peek.into Peek::Views::AltRoutes, name: 'Site Redesign'
39
+ ```
40
+
41
+ Add the following to your `app/assets/javascripts/application.js`:
42
+
43
+ ```javascript
44
+ //= require peek/views/alt_routes
45
+ ```
46
+
47
+ Add the following to your `app/assets/javascripts/application.css`:
48
+
49
+ ```css
50
+ /*
51
+ *= require peek/views/alt_routes
52
+ */
53
+ ```
54
+
55
+ Use the `peek_alt_routes?` route constraint as you see fit. In `config/routes.rb`:
56
+
57
+ ```ruby
58
+ # Remember that Rails matches the first route it finds (top to bottom) so
59
+ # be sure to put any constrained routes before the open routes.
60
+
61
+ # Route group example:
62
+ constraints peek_alt_routes?: true do
63
+ get '/about', to: 'next_site#about'
64
+ get '/contact', to: 'next_site#contact'
65
+ end
66
+ get '/about', to: 'site#about'
67
+ get '/contact', to: 'site#contact'
68
+
69
+ # Single case example:
70
+ get 'new-site-only' to: 'new_site#only', constraints: { peek_alt_routes?: true }
71
+
72
+ # DRY routes using routing concerns ( >= Rails 4.0 ) example:
73
+ concern :static_pages do
74
+ get '/about, action: 'about'
75
+ get '/contact, action: 'contact'
76
+ end
77
+ scope controller: 'next_site', constraints: { peek_alt_routes?: true } do
78
+ concerns :static_pages
79
+ get '/help', action: 'help'
80
+ end
81
+ scope controller: 'site' do
82
+ concerns :static_pages
83
+ end
84
+
85
+ ```
86
+
87
+ ## When to use this vs Flipper
88
+
89
+ * [Flipper](https://github.com/jnunemaker/flipper) is a full featured gem that
90
+ is supplementary to this gem.
91
+ * Prefer this gem only for cases when a full visual redesign is wanted. This
92
+ gem only does quick user facing feature toggling better than flipper.
93
+ * Use flipper for multiple or non-visual feature toggles or when advanced roll
94
+ out procedures are needed.
95
+
96
+ ## Notes
97
+
98
+ * Be sure to render the Peek bar in your alternate views so it may be disabled.
99
+ * Be sure to implement user security into your alternate controllers. Peek-alt-routes
100
+ simply sets and checks a cookie for determining which routes to use.
101
+ * The `peek_alt_routes?` method is available in controllers as well should you need it.
102
+
103
+ ## Contributing
104
+
105
+ 1. Fork it
106
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
107
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
108
+ 4. Push to the branch (`git push origin my-new-feature`)
109
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ class PeekAltRoutes
2
+ checkboxEl: '.peek-alt-routes input'
3
+ tipsyEl: '.peek-alt-routes .peek-alt-routes-btn'
4
+
5
+ render: ->
6
+ $(@checkboxEl).on 'change', @checkboxClicked
7
+ $(@tipsyEl).attr('title', @tipsyMessage())
8
+ $(@tipsyEl).tipsy gravity: $.fn.tipsy.autoNS
9
+
10
+ checkboxClicked: (event) ->
11
+ document.cookie = "peek-alt-routes=#{event.target.checked}; path=/"
12
+ document.location.reload(true)
13
+
14
+ altRoutesEnabled: ->
15
+ $(@checkboxEl)[0].checked
16
+
17
+ altRoutesDisplayName: ->
18
+ $(@checkboxEl).siblings('label').text()
19
+
20
+ tipsyMessage: ->
21
+ msg = "\'#{@altRoutesDisplayName()}\' is currently "
22
+ if @altRoutesEnabled()
23
+ msg += 'enabled.'
24
+ else
25
+ msg += 'disabled.'
26
+
27
+ $(document).ready ->
28
+ (new PeekAltRoutes).render()
@@ -0,0 +1,36 @@
1
+ .peek-alt-routes .peek-alt-routes-btn {
2
+ position: relative;
3
+
4
+ input {
5
+ left: 8px;
6
+ position: absolute;
7
+ top: 12px;
8
+ z-index: 3;
9
+ }
10
+
11
+ label {
12
+ border: 1px solid rgba(0, 0, 0, .8);
13
+ border-radius: 3px;
14
+ box-shadow: inset 1px 1px 0 rgba(255, 255, 255, .2), 1px 1px 2px rgba(0, 0, 0, .25);
15
+ color: #fff;
16
+ letter-spacing: 0.8px;
17
+ padding: 5px 8px 5px 25px;
18
+ position: relative;
19
+ top: 1px;
20
+ z-index: 1;
21
+
22
+ &:hover {
23
+ box-shadow: 0 0 4px rgba(255, 255, 255, .85);
24
+ background-color: rgba(0, 0, 0, .2);
25
+ }
26
+ }
27
+
28
+ &.active label {
29
+ background-color: rgba(0, 0, 0, .2);
30
+ box-shadow: 0 1px 0 rgba(255, 255, 255, .2), inset 0 2px 2px rgba(0, 0, 0, .25);
31
+
32
+ &:hover {
33
+ box-shadow: 0 0 4px rgba(255, 255, 255, .85);
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,6 @@
1
+ <div class="peek-alt-routes">
2
+ <div class="peek-alt-routes-btn <%= 'active' if request.peek_alt_routes? %>">
3
+ <%= check_box_tag 'peek-alt-routes', '1', request.peek_alt_routes? %>
4
+ <label for="peek-alt-routes"><%= view.name %></label>
5
+ </div>
6
+ </div>
@@ -0,0 +1,3 @@
1
+ require 'peek/views/alt_routes'
2
+ require 'peek-alt-routes/version'
3
+ require 'peek-alt-routes/railtie'
@@ -0,0 +1,14 @@
1
+ require 'peek/alt-routes/request_extensions'
2
+
3
+ module Peek
4
+ module AltRoutes
5
+ class Railtie < ::Rails::Engine
6
+ initializer 'peek.alt_routes.include_request_extensions' do
7
+ ActiveSupport.on_load(:action_controller) do
8
+ ActionDispatch::Request.send(:include, Peek::AltRoutes::RequestExtensions)
9
+ delegate :peek_alt_routes?, to: :request
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Peek
2
+ module AltRoutes
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module Peek
2
+ module AltRoutes
3
+ module RequestExtensions
4
+ def peek_alt_routes?
5
+ cookies['peek-alt-routes'] == 'true'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ module Peek
2
+ module Views
3
+ class AltRoutes < View
4
+ attr_reader :name
5
+ # A view that allows for quick toggling of alternative routes.
6
+ #
7
+ # name - Text that will be displayed in the peek bar. The name
8
+ # of the feature or pages that will be toggled.
9
+ #
10
+ # Returns Peek::Views::AltRoutes
11
+ def initialize(options = {})
12
+ @name = options.fetch(:name, 'Alternate Routes')
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'peek-alt-routes/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'peek-alt-routes'
8
+ gem.version = Peek::AltRoutes::VERSION
9
+ gem.authors = ['Chris Ewald']
10
+ gem.email = ['chrisewald@gmail.com']
11
+ gem.description = %q{Easily toggle alternate controllers and routes with peek.}
12
+ gem.summary = %q{Easily toggle alternate controllers and routes with peek.}
13
+ gem.homepage = 'https://github.com/mkcode/peek-alt-routes'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency 'peek'
21
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peek-alt-routes
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Ewald
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: peek
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Easily toggle alternate controllers and routes with peek.
28
+ email:
29
+ - chrisewald@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - CHANGELOG.md
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - app/assets/javascripts/peek/views/alt_routes.js.coffee
41
+ - app/assets/stylesheets/peek/views/alt_routes.css.scss
42
+ - app/views/peek/views/_alt_routes.html.erb
43
+ - lib/peek-alt-routes.rb
44
+ - lib/peek-alt-routes/railtie.rb
45
+ - lib/peek-alt-routes/version.rb
46
+ - lib/peek/alt-routes/request_extensions.rb
47
+ - lib/peek/views/alt_routes.rb
48
+ - peek-alt-routes.gemspec
49
+ homepage: https://github.com/mkcode/peek-alt-routes
50
+ licenses: []
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.4.5.1
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Easily toggle alternate controllers and routes with peek.
72
+ test_files: []