browser_stack_button 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e95e01bcae6177e12748ee24e89f8adf9cead5ab
4
+ data.tar.gz: d4b690069c79623c901f54c8175cf0a2368c34b1
5
+ SHA512:
6
+ metadata.gz: f853b824ac9bd0c6475c4702bb0388d213f15fb0c03f456ad8a2ae0d1d37074647d96a7623ced42edd8955e467de320a3c6cefb43eaf817348fa1e472e046692
7
+ data.tar.gz: 3f6e428579906d77b82558e1cc0a1fc54bc23069893490caa2a719a57b1b7fc2d04c280bf86c46433de4ac8d30f2bb5c86a97139a5efaa2bf607f7728a5845e4
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in browser_stack_button.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Aaron Jensen
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,117 @@
1
+ # BrowserStackButton
2
+
3
+ BrowserStackButton adds a button to your page to allow you to quickly and
4
+ easily view the page you are looking at in BrowserStack. It is currently set up
5
+ to work on a Rails project but could probably be used in Sinatra or the like.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'browser_stack_button'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install browser_stack_button
20
+
21
+ ## Configuration
22
+
23
+ Put your configuration in an initializer:
24
+
25
+ `config/initializers/browser_stack_button.rb`
26
+
27
+ ```ruby
28
+ BrowserStackButton.configure do |config|
29
+ # ...
30
+ end
31
+ ```
32
+
33
+ ### Browser configuration
34
+
35
+ By default BrowserStackButton will not render any buttons for any browsers.
36
+ You need to set them up as described below.
37
+ TODO: NEED LINK
38
+ Refer to the [Browser Stack API documentation]() for what each setting means.
39
+
40
+ #### Default options
41
+
42
+ These options are applied to all browsers, but can be overridden by the
43
+ individual browser settings.
44
+
45
+ ```ruby
46
+ config.default_options = {
47
+ os: "Windows",
48
+ start: "true",
49
+ speed: "2",
50
+ zoom_to_fit: "false",
51
+ resolution: "1024x768",
52
+ full_screen: "true",
53
+ }
54
+ ```
55
+
56
+ #### Configuring browsers
57
+
58
+ ```ruby
59
+ config.browsers["IE8"] = { browser: "IE", browser_version: "8.0", os_version: "7" }
60
+ config.browsers["IE9"] = { browser: "IE", browser_version: "9.0", os_version: "7" }
61
+ config.browsers["IE10"] = { browser: "IE", browser_version: "10.0+Desktop", os_version: "8" }
62
+ config.browsers["Firefox"] = { browser: "Firefox", browser_version: "22.0", os_version: "7" }
63
+ config.browsers["Safari"] = { browser: "Safari", browser_version: "6.0", os: "OS X", os_version: "Mountain Lion" }
64
+ config.browsers["Chrome"] = { browser: "Chrome", browser_version: "28.0", os_version: "7" }
65
+ ```
66
+
67
+ ## Usage
68
+
69
+ Add the following just after your opening `<body>` tag:
70
+
71
+ ```erb
72
+ <%= browser_stack_button %>
73
+ ```
74
+
75
+ If you want to enable it, likely only on a staging server, you can call
76
+ call `BrowserStackButton.enable!` in a `before_filter` or in your controller
77
+ action if you want to enable it in the current Rails environment.
78
+
79
+ You could enable it on production for just admin users or whatever you like. We
80
+ only use it on our staging server.
81
+
82
+ Sometimes you need to add additional parameters to your site url that is
83
+ visited by BrowserStack. We use this for a login backdoor on our staging server
84
+ which allows us to view the page as the same user we are currently logged in
85
+ as. To do this, pass an additional hash to `enable!`:
86
+
87
+ ```ruby
88
+ BrowserStackButton.enable! do |button|
89
+ # Add additional params to the url
90
+ if user_signed_in?
91
+ button.url_params[:backdoor] = current_user.email
92
+ else
93
+ button.url_params[:backdoor] = "anonymous"
94
+ end
95
+
96
+ # OR override the URL entirely
97
+ browser.url = "http://example.com"
98
+ end
99
+ ```
100
+
101
+ Once enabled, you should see a BrowserStack logo in the top left of the page.
102
+ Click it to reveal a dropdown and select a browser. You will need to enable
103
+ popups. When changing browsers, it is best to close the previous browser window
104
+ before clicking the next one.
105
+
106
+ ## Todo
107
+
108
+ * Localhost/Tunnel support
109
+ * Extract more to javascript so it is usable outside of a Rails project.
110
+
111
+ ## Contributing
112
+
113
+ 1. Fork it ( http://github.com/substantial/browser_stack_button/fork )
114
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
115
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
116
+ 4. Push to the branch (`git push origin my-new-feature`)
117
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ #= require jquery
2
+
3
+ $ ->
4
+ $(document).click (evt) ->
5
+ return if $(evt.target).hasClass('browser-stack-button-button')
6
+ $('.browser-stack-button-list').hide()
7
+
8
+ $('.browser-stack-button-button').click ->
9
+ $('.browser-stack-button-list').show()
10
+
11
+ $('.browser-stack-button-close').click ->
12
+ $('.browser-stack-button-list').hide()
13
+
14
+ $('.browser-stack-button-link').click (evt) ->
15
+ evt.preventDefault()
16
+ $(this).addClass('browser-stack-button-done')
17
+ $('.browser-stack-button-list').hide()
18
+
19
+ $('.browser-stack-button-button').addClass('browser-stack-button-loading')
20
+ $stopImg = $('<img>')
21
+ $stopImg.error ->
22
+ $('.browser-stack-button-button').removeClass('browser-stack-button-loading')
23
+ window.open evt.target.href
24
+
25
+ $stopImg.attr 'src', 'http://www.browserstack.com/terminal/stop'
26
+
@@ -0,0 +1,65 @@
1
+ .browser-stack-button
2
+ position: absolute
3
+ top: 0
4
+ left: 0
5
+ z-index: 9999999
6
+
7
+ .browser-stack-button-button
8
+ width: 42px
9
+ height: 41px
10
+ opacity: 0.5
11
+ cursor: pointer
12
+ background: image-url('browser_stack.png') no-repeat no-repeat
13
+ -webkit-transition: all 0.2s
14
+ -moz-transition: all 0.2s
15
+ -o-transition: all 0.2s
16
+ transition: all 0.2s
17
+ -webkit-backface-visibility: hidden
18
+
19
+ &:hover
20
+ opacity: 1.0
21
+
22
+ .browser-stack-button-loading
23
+ -webkit-animation: browser-stack-loading 1s infinite linear
24
+
25
+ @-webkit-keyframes browser-stack-loading
26
+ 0%
27
+ opacity: 0.5
28
+ -webkit-transform: rotate(0deg)
29
+ 50%
30
+ opacity: 1
31
+ 100%
32
+ opacity: 0.5
33
+ -webkit-transform: rotate(359deg)
34
+
35
+ .browser-stack-button-list
36
+ display: none
37
+ position: absolute
38
+ top: 0
39
+ left: 0
40
+ border: 4px solid #333
41
+
42
+ .browser-stack-button-link
43
+ text-align: left
44
+ border: 0
45
+ width: 180px
46
+ display: block
47
+ background: #EEE
48
+ padding: 10px
49
+ cursor: pointer
50
+ &:hover
51
+ background: #CCC
52
+
53
+ .browser-stack-button-done:after
54
+ float: right
55
+ content: '\2713'
56
+
57
+ .browser-stack-button-close
58
+ @extend .browser-stack-button-link
59
+ border-bottom: 1px solid #BBB
60
+ &:after
61
+ float: right
62
+ content: '\00d7'
63
+
64
+ .browser-stack-button-link-current
65
+ color: white
@@ -0,0 +1,17 @@
1
+ <%= stylesheet_link_tag "browser_stack_button" %>
2
+ <%= javascript_include_tag "browser_stack_button" %>
3
+ <div class="browser-stack-button">
4
+ <div class="browser-stack-button-menu">
5
+ <div class="browser-stack-button-button"></div>
6
+ <ul class="browser-stack-button-list">
7
+ <li>
8
+ <button class="browser-stack-button-close">Close</button>
9
+ </li>
10
+ <%- button.each_browser_and_url do |browser, url| -%>
11
+ <li>
12
+ <%= link_to "View in #{browser}", url, class: "browser-stack-button-link" %>
13
+ </li>
14
+ <%- end -%>
15
+ </ul>
16
+ </div>
17
+ </div>
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'browser_stack_button/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "browser_stack_button"
8
+ spec.version = BrowserStackButton::VERSION
9
+ spec.authors = ["Aaron Jensen"]
10
+ spec.email = ["aaron@bustantial.com"]
11
+ spec.summary = %q{Add a button to your page to make testing with browser stack even easier.}
12
+ spec.description = %q{BrowserStack makes it really easy to test with different browsers, but this makes it even easier by adding a button to ever page and allowing you to quickly go through the browsers you need to test on.}
13
+ spec.homepage = "https://github.com/substantial/browser_stack_button"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rails", ">= 3.2 "
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,35 @@
1
+ require_relative "browser_stack_button/version"
2
+ require_relative "browser_stack_button/railtie"
3
+ require_relative "browser_stack_button/engine"
4
+ require_relative "browser_stack_button/configuration"
5
+ require_relative "browser_stack_button/disabled_renderer"
6
+ require_relative "browser_stack_button/enabled_renderer"
7
+
8
+ module BrowserStackButton
9
+ class << self
10
+ def renderer
11
+ Thread.current[:browser_stack_button_renderer] ||= DisabledRenderer.new
12
+ end
13
+
14
+ def configuration
15
+ @configuration ||= Configuration.new
16
+ end
17
+
18
+ def configure
19
+ yield configuration
20
+ end
21
+
22
+ def disable!
23
+ self.renderer = DisabledRenderer.new
24
+ end
25
+
26
+ def enable!(&block)
27
+ self.renderer = EnabledRenderer.new(configuration, &block)
28
+ end
29
+
30
+ private
31
+ def renderer=(renderer)
32
+ Thread.current[:browser_stack_button_renderer] = renderer
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,33 @@
1
+ require_relative "url"
2
+
3
+ module BrowserStackButton
4
+ class Button
5
+ attr_reader :configuration, :context, :url_params
6
+ attr_accessor :url
7
+
8
+ def initialize(configuration, context)
9
+ @configuration = configuration
10
+ @context = context
11
+ @url_params = {}
12
+ end
13
+
14
+ def each_browser_and_url
15
+ configuration.browsers.each do |name, options|
16
+ options = configuration.default_options.merge options
17
+ options[:url] = browser_stack_current_url
18
+ yield name, BrowserStackButton::Url.new(options).to_s
19
+ end
20
+ end
21
+
22
+ private
23
+ def browser_stack_current_url
24
+ return url if url
25
+
26
+ url_options = context.params.merge(
27
+ only_path: false,
28
+ ).merge(url_params)
29
+
30
+ context.url_for(url_options)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,13 @@
1
+ module BrowserStackButton
2
+ class Configuration
3
+ attr_writer :default_options, :browsers
4
+
5
+ def default_options
6
+ @default_options ||= {}
7
+ end
8
+
9
+ def browsers
10
+ @browsers ||= {}
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module BrowserStackButton
2
+ class DisabledRenderer
3
+ def render_to(context)
4
+ # do nothing
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'button'
2
+
3
+ module BrowserStackButton
4
+ class EnabledRenderer
5
+ attr_reader :configuration, :button_block
6
+
7
+ def initialize(configuration, &block)
8
+ @configuration = configuration
9
+ @button_block = block
10
+ end
11
+
12
+ def render_to(context)
13
+ context.render "browser_stack_button/button", button: create_button(context)
14
+ end
15
+
16
+ private
17
+ def create_button(context)
18
+ button = BrowserStackButton::Button.new(configuration, context)
19
+ button_block.call button
20
+ button
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails'
2
+
3
+ module BrowserStackButton #:nodoc:
4
+ class Engine < ::Rails::Engine #:nodoc:
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module BrowserStackButton
2
+ module Helpers
3
+ def browser_stack_button
4
+ BrowserStackButton.renderer.render_to(self)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module BrowserStackButton
2
+ class Rack
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ BrowserStackButton.disable!
9
+ @app.call(env)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ require "rails"
2
+ require_relative "helpers"
3
+ require_relative "rack"
4
+
5
+ module BrowserStackButton
6
+ class Railtie < ::Rails::Railtie
7
+ initializer 'browser_stack_button' do |app|
8
+ ActiveSupport.on_load(:action_view) do
9
+ ::ActionView::Base.send :include, BrowserStackButton::Helpers
10
+ end
11
+
12
+ app.middleware.insert(0, BrowserStackButton::Rack)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require "cgi"
2
+
3
+ module BrowserStackButton
4
+ class Url
5
+ def initialize(options={})
6
+ params = options.map {|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"}.join("&")
7
+
8
+ @url = "http://www.browserstack.com/start##{params}"
9
+ end
10
+
11
+ def to_s
12
+ @url
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module BrowserStackButton
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: browser_stack_button
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Jensen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: BrowserStack makes it really easy to test with different browsers, but
56
+ this makes it even easier by adding a button to ever page and allowing you to quickly
57
+ go through the browsers you need to test on.
58
+ email:
59
+ - aaron@bustantial.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - .gitignore
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - app/assets/javascripts/browser_stack_button.js.coffee
70
+ - app/assets/stylesheets/browser_stack_button.css.sass
71
+ - app/views/browser_stack_button/_button.html.erb
72
+ - browser_stack_button.gemspec
73
+ - lib/browser_stack_button.rb
74
+ - lib/browser_stack_button/button.rb
75
+ - lib/browser_stack_button/configuration.rb
76
+ - lib/browser_stack_button/disabled_renderer.rb
77
+ - lib/browser_stack_button/enabled_renderer.rb
78
+ - lib/browser_stack_button/engine.rb
79
+ - lib/browser_stack_button/helpers.rb
80
+ - lib/browser_stack_button/rack.rb
81
+ - lib/browser_stack_button/railtie.rb
82
+ - lib/browser_stack_button/url.rb
83
+ - lib/browser_stack_button/version.rb
84
+ homepage: https://github.com/substantial/browser_stack_button
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.1.11
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Add a button to your page to make testing with browser stack even easier.
108
+ test_files: []