rack_konami 0.9.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/README.rdoc +1 -1
- data/Rakefile +2 -44
- data/lib/rack_konami.rb +40 -29
- data/lib/rack_konami/version.rb +5 -0
- data/rack_konami.gemspec +16 -47
- data/test/test_rack_konami.rb +1 -1
- metadata +49 -59
data/Gemfile
ADDED
data/README.rdoc
CHANGED
@@ -18,7 +18,7 @@ In config/environment.rb
|
|
18
18
|
config.middleware.use Rack::Konami, :html => '<img src="/images/rails.png" >', :delay => '1500'
|
19
19
|
Open your browser and type ↑ ↑ ↓ ↓ ← → ← → B A ↵
|
20
20
|
|
21
|
-
== Rails
|
21
|
+
== Rails 3.x / Sinatra
|
22
22
|
In your Gemfile
|
23
23
|
gem "rack_konami"
|
24
24
|
|
data/Rakefile
CHANGED
@@ -1,53 +1,11 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "rack_konami"
|
8
|
-
gem.summary = "Rack middlware that embeds the Konami code in your apps"
|
9
|
-
gem.description = "Mixes the Konami code + JQuery to add Konami code effects to your app"
|
10
|
-
gem.email = "mark@amerine.net"
|
11
|
-
gem.homepage = "http://github.com/amerine/rack_konami"
|
12
|
-
gem.authors = ["Mark Turner"]
|
13
|
-
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
-
end
|
16
|
-
Jeweler::GemcutterTasks.new
|
17
|
-
rescue LoadError
|
18
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
-
end
|
20
|
-
|
2
|
+
require "bundler/gem_tasks"
|
21
3
|
require 'rake/testtask'
|
4
|
+
|
22
5
|
Rake::TestTask.new(:test) do |test|
|
23
6
|
test.libs << 'lib' << 'test'
|
24
7
|
test.pattern = 'test/**/test_*.rb'
|
25
8
|
test.verbose = true
|
26
9
|
end
|
27
10
|
|
28
|
-
begin
|
29
|
-
require 'rcov/rcovtask'
|
30
|
-
Rcov::RcovTask.new do |test|
|
31
|
-
test.libs << 'test'
|
32
|
-
test.pattern = 'test/**/test_*.rb'
|
33
|
-
test.verbose = true
|
34
|
-
end
|
35
|
-
rescue LoadError
|
36
|
-
task :rcov do
|
37
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
task :test => :check_dependencies
|
42
|
-
|
43
11
|
task :default => :test
|
44
|
-
|
45
|
-
require 'rake/rdoctask'
|
46
|
-
Rake::RDocTask.new do |rdoc|
|
47
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
-
|
49
|
-
rdoc.rdoc_dir = 'rdoc'
|
50
|
-
rdoc.title = "rack_konami #{version}"
|
51
|
-
rdoc.rdoc_files.include('README*')
|
52
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
-
end
|
data/lib/rack_konami.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
|
1
|
+
require "rack_konami/version"
|
2
|
+
|
3
|
+
module Rack
|
2
4
|
class Konami
|
3
|
-
|
4
5
|
KONAMI_CODE = <<-EOTC
|
5
6
|
<div id="rack_konami" style="display:none;position:fixed;top:20%;right:50%;">
|
6
7
|
{{HTML}}
|
@@ -19,40 +20,50 @@ module Rack
|
|
19
20
|
konami.load()
|
20
21
|
</script>
|
21
22
|
EOTC
|
22
|
-
|
23
|
-
def initialize(app, options
|
23
|
+
|
24
|
+
def initialize(app, options={})
|
24
25
|
@app = app
|
25
|
-
@html = options[:html] || "
|
26
|
+
@html = options[:html] || "<!-- Konami Code -->"
|
26
27
|
@delay = options[:delay] || 1000
|
27
28
|
end
|
28
|
-
|
29
|
-
def call
|
30
|
-
dup._call
|
29
|
+
|
30
|
+
def call env
|
31
|
+
dup._call env
|
31
32
|
end
|
32
|
-
|
33
|
-
def _call
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
response = Rack::Response.new([], @status, @headers)
|
40
|
-
@response.each do |fragment|
|
41
|
-
response.write(inject_konami(fragment))
|
33
|
+
|
34
|
+
def _call env
|
35
|
+
status, headers, response = @app.call env
|
36
|
+
|
37
|
+
if should_inject_konami_code? status, headers, response
|
38
|
+
response = inject_konami_code response
|
39
|
+
fix_content_length(headers, response)
|
42
40
|
end
|
43
|
-
|
41
|
+
|
42
|
+
[status, headers, response]
|
44
43
|
end
|
45
|
-
|
46
|
-
def
|
47
|
-
|
44
|
+
|
45
|
+
def should_inject_konami_code? status, headers, response
|
46
|
+
status == 200 &&
|
47
|
+
headers["Content-Type"] &&
|
48
|
+
(headers["Content-Type"].include?("text/html") || headers["Content-Type"].include?("application/xhtml"))
|
48
49
|
end
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
|
51
|
+
def inject_konami_code response, body=""
|
52
|
+
response.each { |s| body << s.to_s }
|
53
|
+
body.gsub(/<\/body>/, "#{substitute_vars}\n</body>")
|
54
|
+
end
|
55
|
+
|
56
|
+
def fix_content_length headers, response
|
57
|
+
if headers["Content-Length"]
|
58
|
+
length = response.to_ary.inject(0) { |len, part| len + Rack::Utils.bytesize(part) }
|
59
|
+
headers['Content-Length'] = length.to_s
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
52
63
|
def substitute_vars
|
53
|
-
KONAMI_CODE.
|
64
|
+
code = KONAMI_CODE.gsub /\{\{HTML\}\}/, @html.to_s
|
65
|
+
code.gsub /\{\{DELAY\}\}/, @delay.to_s
|
54
66
|
end
|
55
|
-
|
67
|
+
private :substitute_vars
|
56
68
|
end
|
57
|
-
|
58
|
-
end
|
69
|
+
end
|
data/rack_konami.gemspec
CHANGED
@@ -1,54 +1,23 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rack_konami/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
9
|
-
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
6
|
+
s.name = "rack_konami"
|
7
|
+
s.version = Rack::Konami::VERSION
|
8
|
+
s.authors = ["Mark Turner"]
|
9
|
+
s.email = ["mark@amerine.net"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Rack middlware that embeds the Konami code in your apps}
|
13
12
|
s.description = %q{Mixes the Konami code + JQuery to add Konami code effects to your app}
|
14
|
-
s.email = %q{mark@amerine.net}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"lib/rack_konami.rb",
|
27
|
-
"rack_konami.gemspec",
|
28
|
-
"test/helper.rb",
|
29
|
-
"test/test_rack_konami.rb"
|
30
|
-
]
|
31
|
-
s.homepage = %q{http://github.com/amerine/rack_konami}
|
32
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
-
s.require_paths = ["lib"]
|
34
|
-
s.rubygems_version = %q{1.3.7}
|
35
|
-
s.summary = %q{Rack middlware that embeds the Konami code in your apps}
|
36
|
-
s.test_files = [
|
37
|
-
"test/helper.rb",
|
38
|
-
"test/test_rack_konami.rb"
|
39
|
-
]
|
40
13
|
|
41
|
-
|
42
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
-
s.specification_version = 3
|
14
|
+
s.rubyforge_project = "rack_konami"
|
44
15
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
else
|
51
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
52
|
-
end
|
53
|
-
end
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
54
20
|
|
21
|
+
s.add_development_dependency "shoulda"
|
22
|
+
s.add_runtime_dependency "rack"
|
23
|
+
end
|
data/test/test_rack_konami.rb
CHANGED
@@ -36,7 +36,7 @@ class TestRackKonami < Test::Unit::TestCase
|
|
36
36
|
|
37
37
|
EXPECTED_CODE = /<div\sid=.rack_konami.+konami\.load/m
|
38
38
|
HTML_INCLUDED = /images\/rails.png/
|
39
|
-
HTML_DEFAULT =
|
39
|
+
HTML_DEFAULT = /<!-- Konami Code -->/
|
40
40
|
DELAY_INCLUDED = /\.delay\(500\)/
|
41
41
|
DELAY_DEFAULT = /\.delay\(1000\)/
|
42
42
|
|
metadata
CHANGED
@@ -1,91 +1,81 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack_konami
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 9
|
9
|
-
- 1
|
10
|
-
version: 0.9.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Mark Turner
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
name: thoughtbot-shoulda
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2011-09-22 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: shoulda
|
16
|
+
requirement: &70228432443400 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :development
|
34
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70228432443400
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rack
|
27
|
+
requirement: &70228432442980 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70228432442980
|
35
36
|
description: Mixes the Konami code + JQuery to add Konami code effects to your app
|
36
|
-
email:
|
37
|
+
email:
|
38
|
+
- mark@amerine.net
|
37
39
|
executables: []
|
38
|
-
|
39
40
|
extensions: []
|
40
|
-
|
41
|
-
|
42
|
-
- LICENSE
|
43
|
-
- README.rdoc
|
44
|
-
files:
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
45
43
|
- .document
|
46
44
|
- .gitignore
|
45
|
+
- Gemfile
|
47
46
|
- LICENSE
|
48
47
|
- README.rdoc
|
49
48
|
- Rakefile
|
50
49
|
- VERSION
|
51
50
|
- lib/rack_konami.rb
|
51
|
+
- lib/rack_konami/version.rb
|
52
52
|
- rack_konami.gemspec
|
53
53
|
- test/helper.rb
|
54
54
|
- test/test_rack_konami.rb
|
55
|
-
|
56
|
-
homepage: http://github.com/amerine/rack_konami
|
55
|
+
homepage: ''
|
57
56
|
licenses: []
|
58
|
-
|
59
57
|
post_install_message:
|
60
|
-
rdoc_options:
|
61
|
-
|
62
|
-
require_paths:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
63
60
|
- lib
|
64
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
62
|
none: false
|
66
|
-
requirements:
|
67
|
-
- -
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
|
70
|
-
|
71
|
-
- 0
|
72
|
-
version: "0"
|
73
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
68
|
none: false
|
75
|
-
requirements:
|
76
|
-
- -
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
|
79
|
-
segments:
|
80
|
-
- 0
|
81
|
-
version: "0"
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
82
73
|
requirements: []
|
83
|
-
|
84
|
-
|
85
|
-
rubygems_version: 1.3.7
|
74
|
+
rubyforge_project: rack_konami
|
75
|
+
rubygems_version: 1.8.6
|
86
76
|
signing_key:
|
87
77
|
specification_version: 3
|
88
78
|
summary: Rack middlware that embeds the Konami code in your apps
|
89
|
-
test_files:
|
79
|
+
test_files:
|
90
80
|
- test/helper.rb
|
91
81
|
- test/test_rack_konami.rb
|