rack-nojs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 67169efc36b11b1edc19d62b2105a426778a6d05
4
+ data.tar.gz: 05c9cfc0da9499c735e4ac3044157391bdf5535c
5
+ SHA512:
6
+ metadata.gz: c00397ce4bba10ab08b9e8e7c1e544fb6323fee5fe415ccae8dee8e68cc9062a286bfe8c9869b0ecc467a2be8d78c9407a35db9530827ec24e4104f2bcc98e9c
7
+ data.tar.gz: e33d7ccce5ae5ce2205f41d27636a2a6c63b9972dd2f5a6dc83528eaf676916fde4fb5b09dd733e2b7f4d5e399b768f338ca1681fe584d2c709cbf9a80b01126
@@ -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,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 SHIBATA Hiroshi
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.
@@ -0,0 +1,38 @@
1
+ # Rack::Nojs
2
+
3
+ treat script tag in response.body when access with old mobile phone.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rack-nojs'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rack-nojs
18
+
19
+ ## Usage
20
+
21
+ ### Rails2
22
+
23
+ Insert follow code into your config/environment.rb
24
+
25
+ require 'rack-nojs'
26
+ config.middleware.use ::Rack::Nojs
27
+
28
+ ### Rails3
29
+
30
+ You don't need this gem :)
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ require 'rack/nojs'
@@ -0,0 +1,36 @@
1
+ require 'rack'
2
+ require 'jpmobile'
3
+
4
+ module Rack
5
+ class Request
6
+ include Jpmobile::RequestWithMobile
7
+ end
8
+
9
+ class Nojs
10
+ def initialize(app)
11
+ @app = app
12
+ end
13
+
14
+ def call(env); dup._call(env); end
15
+
16
+ def _call(env)
17
+ @env = env
18
+ req = Rack::Request.new(env)
19
+ @status, @headers, @body = @app.call(env)
20
+ return [@status, @headers, @body] if !html? || !req.mobile?
21
+ response = Rack::Response.new([], @status, @headers)
22
+ @body.each { |fragment| response.write inject(fragment) }
23
+ @body.close if @body.respond_to?(:close)
24
+
25
+ response.finish
26
+ end
27
+
28
+ private
29
+
30
+ def html?; @headers['Content-Type'] =~ /html/; end
31
+
32
+ def inject(response)
33
+ response.gsub(/<script type="text\/javascript"[\w\W]*?<\/script>/, '')
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class Nojs
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack/nojs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rack-nojs"
8
+ spec.version = Rack::Nojs::VERSION
9
+ spec.authors = ["SHIBATA Hiroshi"]
10
+ spec.email = ["shibata.hiroshi@gmail.com"]
11
+ spec.description = %q{treat script tag in response.body when access with old mobile phone.}
12
+ spec.summary = %q{treat script tag in response.body when access with old mobile phone.}
13
+ spec.homepage = "https://github.com/paperboy-30days/rack-nojs"
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 "jpmobile", "0.0.8"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency 'rack-test'
26
+ end
@@ -0,0 +1,67 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test/unit'
3
+ require 'rack/test'
4
+ require 'rack-nojs'
5
+
6
+ class Test::Unit::TestCase
7
+ include Rack::Test::Methods
8
+ end
9
+
10
+ class TestApp
11
+ def call(env)
12
+ [
13
+ 200,
14
+ { 'Content-Type' => 'text/html' },
15
+ ['<html><head></head><body><script type="text/javascript" src="//castanet.kiban.paperboy.co.jp/castanet.js"></script></body></html>']
16
+ ]
17
+ end
18
+ end
19
+
20
+ class NojsTest < Test::Unit::TestCase
21
+ def app
22
+ Rack::Builder.new {
23
+ map "/" do
24
+ use ::Rack::Nojs
25
+ run TestApp.new
26
+ end
27
+ }.to_app
28
+ end
29
+
30
+ def test_castanet
31
+ get '/'
32
+ assert last_response.body.include? "castanet"
33
+ end
34
+
35
+ def test_castanet_with_mobile
36
+ get '/', {}, {'HTTP_USER_AGENT' => 'DoCoMo/2.0 P903i'}
37
+ assert !last_response.body.include?("castanet")
38
+ assert last_response.body.include? "<body></body>"
39
+ end
40
+ end
41
+
42
+ class TestAppReal
43
+ def call(env)
44
+ [
45
+ 200,
46
+ { 'Content-Type' => 'text/html' },
47
+ ["<html>", "<head>", "</head>", "<body>", '<script type="text/javascript" src="//castanet.kiban.paperboy.co.jp/castanet.js"></script>', "<div>", "</div>", "<script type=\"text/javascript\">\nCastanet.setService('foo');\nCastanet.dispatchPageRequest();\n</script>", "</body>", "</html>"]
48
+ ]
49
+ end
50
+ end
51
+
52
+ class NojsTestReal < Test::Unit::TestCase
53
+ def app
54
+ Rack::Builder.new {
55
+ map "/" do
56
+ use ::Rack::Nojs
57
+ run TestAppReal.new
58
+ end
59
+ }.to_app
60
+ end
61
+
62
+ def test_castanet_with_mobile
63
+ get '/', {}, {'HTTP_USER_AGENT' => 'DoCoMo/2.0 P903i'}
64
+ assert !last_response.body.include?("castanet")
65
+ assert last_response.body.include? "<body><div></div></body>"
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-nojs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - SHIBATA Hiroshi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jpmobile
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.8
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.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
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
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: treat script tag in response.body when access with old mobile phone.
70
+ email:
71
+ - shibata.hiroshi@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/rack-nojs.rb
82
+ - lib/rack/nojs.rb
83
+ - lib/rack/nojs/version.rb
84
+ - rack-nojs.gemspec
85
+ - test/nojs_test.rb
86
+ homepage: https://github.com/paperboy-30days/rack-nojs
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.0.3
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: treat script tag in response.body when access with old mobile phone.
110
+ test_files:
111
+ - test/nojs_test.rb
112
+ has_rdoc: