rack_konami 0.9.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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +38 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/rack_konami.rb +58 -0
- data/rack_konami.gemspec +54 -0
- data/test/helper.rb +10 -0
- data/test/test_rack_konami.rb +82 -0
- metadata +91 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Mark Turner
|
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.rdoc
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
= Rack::Konami
|
2
|
+
|
3
|
+
Rack Middleware that embeds the Konami Code in your app and lets you fade in and out a snippet of html.
|
4
|
+
|
5
|
+
== Requirements
|
6
|
+
It requires JQuery 1.4.0 or greater.
|
7
|
+
|
8
|
+
== Usage
|
9
|
+
gem install rack_konami
|
10
|
+
require 'rack_konami'
|
11
|
+
use Rack::Konami, :html => "<img src='/images/rails.png'>"
|
12
|
+
app = lambda { |env| [200, { 'Content-Type' => 'text/html' }, '<html><body><p>Awesome Body</p></body></html>'] }
|
13
|
+
run app
|
14
|
+
|
15
|
+
== Usage in Rails 2.3.x
|
16
|
+
In config/environment.rb
|
17
|
+
config.gem 'rack_clicky'
|
18
|
+
config.middleware.use Rack::Konami, :html => '<img src="/images/rails.png" >', :delay => '1500'
|
19
|
+
|
20
|
+
Open your browser and type ↑ ↑ ↓ ↓ ← → ← → B A ↵
|
21
|
+
|
22
|
+
== TODO
|
23
|
+
* It probably wouldn't hurt to have more tests.
|
24
|
+
* Add support for embedding the asynchronous tracking code.
|
25
|
+
|
26
|
+
== Note on Patches/Pull Requests
|
27
|
+
|
28
|
+
* Fork the project.
|
29
|
+
* Make your feature addition or bug fix.
|
30
|
+
* Add tests for it. This is important so I don't break it in a
|
31
|
+
future version unintentionally.
|
32
|
+
* Commit, do not mess with rakefile, version, or history.
|
33
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
34
|
+
* Send me a pull request. Bonus points for topic branches.
|
35
|
+
|
36
|
+
== Copyright
|
37
|
+
|
38
|
+
Copyright (c) 2010 Mark Turner. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
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
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
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
|
+
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/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.9.0
|
data/lib/rack_konami.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
module Rack
|
2
|
+
class Konami
|
3
|
+
|
4
|
+
KONAMI_CODE = <<-EOTC
|
5
|
+
<div id="rack_konami" style="display:none;position:fixed;top:20%;right:50%;">
|
6
|
+
{{HTML}}
|
7
|
+
</div>
|
8
|
+
<script type="text/javascript">
|
9
|
+
var Konami=function(){var a={addEvent:function(b,c,d,e){if(b.addEventListener)b.addEventListener(c,d,false);else if(b.attachEvent){b["e"+c+d]=d;b[c+d]=function(){b["e"+c+d](window.event,e)};b.attachEvent("on"+c,b[c+d])}},input:"",pattern:"3838404037393739666513",load:function(b){this.addEvent(document,"keydown",function(c,d){if(d)a=d;a.input+=c?c.keyCode:event.keyCode;if(a.input.length>a.pattern.length)a.input=a.input.substr(a.input.length-a.pattern.length);if(a.input==a.pattern){a.code(b);a.input=
|
10
|
+
""}},this);this.iphone.load(b)},code:function(b){window.location=b},iphone:{start_x:0,start_y:0,stop_x:0,stop_y:0,tap:false,capture:false,orig_keys:"",keys:["UP","UP","DOWN","DOWN","LEFT","RIGHT","LEFT","RIGHT","TAP","TAP","TAP"],code:function(b){a.code(b)},load:function(b){orig_keys=this.keys;a.addEvent(document,"touchmove",function(c){if(c.touches.length==1&&a.iphone.capture==true){c=c.touches[0];a.iphone.stop_x=c.pageX;a.iphone.stop_y=c.pageY;a.iphone.tap=false;a.iphone.capture=false;a.iphone.check_direction()}});
|
11
|
+
a.addEvent(document,"touchend",function(){a.iphone.tap==true&&a.iphone.check_direction(b)},false);a.addEvent(document,"touchstart",function(c){a.iphone.start_x=c.changedTouches[0].pageX;a.iphone.start_y=c.changedTouches[0].pageY;a.iphone.tap=true;a.iphone.capture=true})},check_direction:function(b){x_magnitude=Math.abs(this.start_x-this.stop_x);y_magnitude=Math.abs(this.start_y-this.stop_y);x=this.start_x-this.stop_x<0?"RIGHT":"LEFT";y=this.start_y-this.stop_y<0?"DOWN":"UP";result=x_magnitude>y_magnitude?
|
12
|
+
x:y;result=this.tap==true?"TAP":result;if(result==this.keys[0])this.keys=this.keys.slice(1,this.keys.length);if(this.keys.length==0){this.keys=this.orig_keys;this.code(b)}}}};return a};
|
13
|
+
</script>
|
14
|
+
<script type="text/javascript">
|
15
|
+
konami = new Konami()
|
16
|
+
konami.code = function() {
|
17
|
+
$('#rack_konami').fadeIn('slow').delay({{DELAY}}).fadeOut('slow');
|
18
|
+
}
|
19
|
+
konami.load()
|
20
|
+
</script>
|
21
|
+
EOTC
|
22
|
+
|
23
|
+
def initialize(app, options = {})
|
24
|
+
@app = app
|
25
|
+
@html = options[:html] || "<h1>Konami Code</h1>"
|
26
|
+
@delay = options[:delay] || 1000
|
27
|
+
end
|
28
|
+
|
29
|
+
def call(env)
|
30
|
+
dup._call(env)
|
31
|
+
end
|
32
|
+
|
33
|
+
def _call(env)
|
34
|
+
|
35
|
+
@status, @headers, @response = @app.call(env)
|
36
|
+
return [@status, @headers, @response] unless @headers['Content-Type'] =~ /html/
|
37
|
+
|
38
|
+
@headers.delete('Content-Length')
|
39
|
+
response = Rack::Response.new([], @status, @headers)
|
40
|
+
@response.each do |fragment|
|
41
|
+
response.write(inject_konami(fragment))
|
42
|
+
end
|
43
|
+
response.finish
|
44
|
+
end
|
45
|
+
|
46
|
+
def inject_konami(response)
|
47
|
+
response.sub!(/<\/body>/, "#{substitute_vars}\n</body>")
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def substitute_vars
|
53
|
+
KONAMI_CODE.sub(/\{\{HTML\}\}/, @html).sub!(/\{\{DELAY\}\}/, @delay.to_s)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/rack_konami.gemspec
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rack_konami}
|
8
|
+
s.version = "0.9.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mark Turner"]
|
12
|
+
s.date = %q{2010-08-20}
|
13
|
+
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
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
49
|
+
end
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'rack/mock'
|
3
|
+
|
4
|
+
class TestRackKonami < Test::Unit::TestCase
|
5
|
+
context "Embedding Rack::Konami" do
|
6
|
+
should "place the konami code at the end of an HTML request" do
|
7
|
+
assert_match EXPECTED_CODE, request.body
|
8
|
+
end
|
9
|
+
|
10
|
+
should "place the konami code at the end of an XHTML request" do
|
11
|
+
assert_match EXPECTED_CODE, request(:content_type => 'application/xhtml+xml').body
|
12
|
+
end
|
13
|
+
|
14
|
+
should "not place the konami code in a non HTML request" do
|
15
|
+
assert_no_match EXPECTED_CODE, request(:content_type => 'application/xml', :body => [XML]).body
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "Passing Options to Rack::Konami" do
|
20
|
+
should "use the HTML you specified when using the app " do
|
21
|
+
assert_match HTML_INCLUDED, request(:html => "<img src='/images/rails.png'>").body
|
22
|
+
end
|
23
|
+
|
24
|
+
should "use the DELAY you specified when using the app" do
|
25
|
+
assert_match DELAY_INCLUDED, request(:delay => 500).body
|
26
|
+
end
|
27
|
+
|
28
|
+
should "use the defaults if you don't specifiy options" do
|
29
|
+
assert_match DELAY_DEFAULT, request.body
|
30
|
+
assert_match HTML_DEFAULT, request.body
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
EXPECTED_CODE = /<div\sid=.rack_konami.+konami\.load/m
|
38
|
+
HTML_INCLUDED = /images\/rails.png/
|
39
|
+
HTML_DEFAULT = /<h1>Konami Code<\/h1>/
|
40
|
+
DELAY_INCLUDED = /\.delay\(500\)/
|
41
|
+
DELAY_DEFAULT = /\.delay\(1000\)/
|
42
|
+
|
43
|
+
EMBED_HTML = "<img src='/images/rails.png'>"
|
44
|
+
|
45
|
+
HTML = <<-EOHTML
|
46
|
+
<html>
|
47
|
+
<head>
|
48
|
+
<title>Sample Page</title>
|
49
|
+
</head>
|
50
|
+
<body>
|
51
|
+
<h2>Rack::Konami Test</h2>
|
52
|
+
<p>This is more test html</p>
|
53
|
+
</body>
|
54
|
+
</html>
|
55
|
+
EOHTML
|
56
|
+
|
57
|
+
XML = <<-EOXML
|
58
|
+
<?xml version="1.0" encoding="ISO-8859-1"?>
|
59
|
+
<user>
|
60
|
+
<name>Mark Turner</name>
|
61
|
+
<age>Unknown</age>
|
62
|
+
</user>
|
63
|
+
EOXML
|
64
|
+
|
65
|
+
def request(options={})
|
66
|
+
@app = app(options)
|
67
|
+
request = Rack::MockRequest.new(@app).get('/')
|
68
|
+
yield(@app, request) if block_given?
|
69
|
+
request
|
70
|
+
end
|
71
|
+
|
72
|
+
def app(options={})
|
73
|
+
options = options.clone
|
74
|
+
options[:content_type] ||= "text/html"
|
75
|
+
options[:body] ||= [HTML]
|
76
|
+
options[:html] || nil
|
77
|
+
options[:delay] || nil
|
78
|
+
rack_app = lambda { |env| [200, { 'Content-Type' => options.delete(:content_type) }, options.delete(:body)] }
|
79
|
+
Rack::Konami.new(rack_app, :html => options[:html], :delay => options[:delay])
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack_konami
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 59
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
- 0
|
10
|
+
version: 0.9.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Mark Turner
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-20 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: thoughtbot-shoulda
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Mixes the Konami code + JQuery to add Konami code effects to your app
|
36
|
+
email: mark@amerine.net
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- lib/rack_konami.rb
|
52
|
+
- rack_konami.gemspec
|
53
|
+
- test/helper.rb
|
54
|
+
- test/test_rack_konami.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/amerine/rack_konami
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --charset=UTF-8
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.3.7
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Rack middlware that embeds the Konami code in your apps
|
89
|
+
test_files:
|
90
|
+
- test/helper.rb
|
91
|
+
- test/test_rack_konami.rb
|