rack-weinre 1.0.0

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.
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-weinre.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rack-weinre (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ capybara (1.1.2)
10
+ mime-types (>= 1.16)
11
+ nokogiri (>= 1.3.3)
12
+ rack (>= 1.0.0)
13
+ rack-test (>= 0.5.4)
14
+ selenium-webdriver (~> 2.0)
15
+ xpath (~> 0.1.4)
16
+ childprocess (0.3.1)
17
+ ffi (~> 1.0.6)
18
+ diff-lcs (1.1.3)
19
+ ffi (1.0.11)
20
+ mime-types (1.17.2)
21
+ multi_json (1.0.4)
22
+ nokogiri (1.5.0)
23
+ rack (1.4.1)
24
+ rack-test (0.6.1)
25
+ rack (>= 1.0)
26
+ rspec (2.9.0)
27
+ rspec-core (~> 2.9.0)
28
+ rspec-expectations (~> 2.9.0)
29
+ rspec-mocks (~> 2.9.0)
30
+ rspec-core (2.9.0)
31
+ rspec-expectations (2.9.0)
32
+ diff-lcs (~> 1.1.3)
33
+ rspec-mocks (2.9.0)
34
+ rubyzip (0.9.6.1)
35
+ selenium-webdriver (2.19.0)
36
+ childprocess (>= 0.2.5)
37
+ ffi (~> 1.0.9)
38
+ multi_json (~> 1.0.4)
39
+ rubyzip
40
+ xpath (0.1.4)
41
+ nokogiri (~> 1.3)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ capybara (~> 1.1.2)
48
+ rack-weinre!
49
+ rspec (~> 2.9.0)
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Hiroki Yoshioka
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ rack-weinre
2
+ ========
3
+ rack-weinre is a rack middleware, which inserts a script tag that loads [weinre](http://phonegap.github.com/weinre/) target script file into your text/html pages.
4
+
5
+ Setup
6
+ --------
7
+ First, add to your Gemfile:
8
+
9
+ gem 'rack-weinre'
10
+
11
+ then <code>bundle</code> as usual.
12
+
13
+ ### with Rails
14
+
15
+ in <code>config/environments/development.rb</code>:
16
+
17
+ MyApp::Application.configure do
18
+ ...
19
+ config.middleware.use 'Rack::Weinre'
20
+ end
21
+
22
+ ### with config.ru
23
+
24
+ use Rack::Weinre
25
+
26
+ How it works
27
+ ------------------
28
+ Once enabled (see below), it inserts a <code>script</code> tag just before the closing <code>head</code> tag of your html pages. the tag is something like:
29
+
30
+ <script src="http://localhost:8080/target/target-script-min.js#anonymous"></script>
31
+
32
+ but the host name depends on to which host the request was made.
33
+
34
+ Options
35
+ -----------
36
+ ### port
37
+ you may use a port number other than 8080, say, 9090. <code>:port</code> option will come in handy then.
38
+
39
+ use Rack::Weinre, :port => 9090
40
+
41
+ ### Toggle tag
42
+
43
+ if you give a <code>:switch</code> option, it is considered as a file name in a relative path from the working rack application. in that case, rake-weinre is active only when the file exists at the exact path.
44
+
45
+ use Rack::Weinre, :switch => 'file' # inserts tag if the file exists (relative)
46
+
47
+ it is always active when no <code>:switch</code> option is given.
48
+
49
+ Copyright
50
+ --------------
51
+ Copyright &copy; 2012 Hiroki Yoshioka. See MIT-LICENSE for further details.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class Weinre
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+ module Rack
2
+ class Weinre
3
+ def initialize(app, options = {})
4
+ @app, @options = app, options
5
+ end
6
+
7
+ def call(env)
8
+ res = @app.call(env)
9
+ if res[1]['Content-Type'] =~ /text\/html/ && enabled
10
+ res.tap do |res|
11
+ orig = res[2]
12
+ res[2] = [].tap do |body|
13
+ orig.each do |line|
14
+ body << line.sub(/(?=<\/head>)/, tag(env))
15
+ end
16
+ orig.close if orig.respond_to?(:close)
17
+ end
18
+ end
19
+ else
20
+ res
21
+ end
22
+ end
23
+
24
+ def enabled
25
+ @options[:switch].nil? || ::File.exist?(Pathname.pwd + @options[:switch])
26
+ end
27
+
28
+ def port
29
+ @options[:port] || 8080
30
+ end
31
+
32
+ def tag(env)
33
+ %{<script src="http://#{env['SERVER_NAME']}:#{port}/target/target-script-min.js#anonymous"></script>\n}
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,2 @@
1
+ require "rack/weinre/version"
2
+ require "rack/weinre"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rack/weinre/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Hiroki Yoshioka"]
6
+ gem.email = ["irohiroki@gmail.com"]
7
+ gem.description = %q{rack-weinre inserts a script tag that loads a weinre target js into html files.}
8
+ gem.summary = %q{A rack middleware for Weinre remote debugger.}
9
+ gem.homepage = "https://github.com/irohiroki/rack-weinre"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "rack-weinre"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Rack::Weinre::VERSION
17
+ gem.add_development_dependency "capybara", "~> 1.1.2"
18
+ gem.add_development_dependency "rspec", "~> 2.9.0"
19
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rack::Weinre do
4
+ before do
5
+ rackup app, options
6
+ visit '/'
7
+ end
8
+
9
+ subject { page }
10
+
11
+ let(:app){ stub_app }
12
+ let(:options){ {} }
13
+
14
+ context "when response type is text/html" do
15
+ it { should have_css 'head script[src="http://www.example.com:8080/target/target-script-min.js#anonymous"]' }
16
+ end
17
+
18
+ context "when response type is not text/html" do
19
+ let(:app){ stub_app(:headers => {'Content-Type' => 'text/plain'}) }
20
+ it { should_not have_css 'head script'}
21
+ end
22
+
23
+ context "with content type with charset" do
24
+ let(:app){ stub_app(:headers => {'Content-Type' => 'text/html; charset=utf-8'}) }
25
+ it { should have_css 'head script'}
26
+ end
27
+
28
+ context "with a :port option" do
29
+ let(:options){ {:port => '8765'} }
30
+ its(:source) { should match 'www.example.com:8765' }
31
+ end
32
+
33
+ context "with a :switch option" do
34
+ context "refering a non-existent file" do
35
+ let(:options){ {:switch => 'bogus'} }
36
+ it { should_not have_css 'head script'}
37
+ end
38
+
39
+ context "refering a existent file" do
40
+ let(:options){ {:switch => 'Gemfile'} }
41
+ it { should have_css 'head script'}
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ require 'capybara/rspec'
2
+ require 'rack'
3
+ require 'rack/weinre'
4
+
5
+ module RackWeinreHelpers
6
+ def rackup(*args)
7
+ app, options =
8
+ case args.first
9
+ when Hash then [stub_app, args.first]
10
+ when nil then [stub_app, {}]
11
+ else [args.first, args.last || {}]
12
+ end
13
+
14
+ Capybara.app = Rack::Builder.app do
15
+ use Rack::Lint
16
+ use Rack::Weinre, options
17
+ run app
18
+ end
19
+ end
20
+
21
+ def stub_app(options = {})
22
+ lambda do |env|
23
+ [
24
+ options[:status] || 200,
25
+ {'Content-Type' => 'text/html'}.merge(options[:headers] || {}),
26
+ options[:body] || ['<html><head></head></html>']
27
+ ]
28
+ end
29
+ end
30
+ end
31
+
32
+ RSpec.configure do |config|
33
+ config.include Capybara::DSL
34
+ config.include RackWeinreHelpers
35
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-weinre
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Hiroki Yoshioka
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capybara
16
+ requirement: &70156904912900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.2
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70156904912900
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70156904912400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.9.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70156904912400
36
+ description: rack-weinre inserts a script tag that loads a weinre target js into html
37
+ files.
38
+ email:
39
+ - irohiroki@gmail.com
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - Gemfile.lock
47
+ - MIT-LICENSE
48
+ - README.md
49
+ - Rakefile
50
+ - lib/rack-weinre.rb
51
+ - lib/rack/weinre.rb
52
+ - lib/rack/weinre/version.rb
53
+ - rack-weinre.gemspec
54
+ - spec/rack/weinre_spec.rb
55
+ - spec/spec_helper.rb
56
+ homepage: https://github.com/irohiroki/rack-weinre
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 1.8.11
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: A rack middleware for Weinre remote debugger.
80
+ test_files:
81
+ - spec/rack/weinre_spec.rb
82
+ - spec/spec_helper.rb