rack-typekit 0.1.0 → 0.2.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/Gemfile +4 -0
- data/Gemfile.lock +23 -0
- data/README.md +22 -0
- data/Rakefile +11 -0
- data/lib/rack/typekit.rb +14 -15
- data/rack-typekit.gemspec +25 -0
- data/spec/fixtures/test.html +10 -0
- data/spec/rack_typekit_spec.rb +44 -0
- metadata +83 -44
- data/README.rdoc +0 -22
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rack-typekit (0.2.0)
|
5
|
+
rack (>= 1.2.0, <= 2.0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
minitest (2.11.4)
|
11
|
+
rack (1.4.1)
|
12
|
+
rack-test (0.6.1)
|
13
|
+
rack (>= 1.0)
|
14
|
+
rake (0.9.2)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
minitest (~> 2.11.4)
|
21
|
+
rack-test (~> 0.6.1)
|
22
|
+
rack-typekit!
|
23
|
+
rake (~> 0.9.2)
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# rack-typekit
|
2
|
+
|
3
|
+
Rack middleware to automatically include your Typekit JavaScript files
|
4
|
+
|
5
|
+
## Example
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require "rack/typekit"
|
9
|
+
|
10
|
+
use Rack::Typekit, :kit => "lng5bpe"
|
11
|
+
```
|
12
|
+
|
13
|
+
Including this in the `config.ru` file of your Rack application will automatically inject the corresponding JavaScript into the `<head>` of your HTML:
|
14
|
+
|
15
|
+
```html
|
16
|
+
<script src="//use.typekit.com/lng5bpe.js"></script>
|
17
|
+
<script>try{Typekit.load();}catch(e){}</script>
|
18
|
+
```
|
19
|
+
|
20
|
+
## License
|
21
|
+
|
22
|
+
rack-typekit is available under the MIT license. See the LICENSE file for more info.
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
gemspec = eval(File.read("rack-typekit.gemspec"))
|
5
|
+
|
6
|
+
task :build => "#{gemspec.full_name}.gem"
|
7
|
+
|
8
|
+
file "#{gemspec.full_name}.gem" => gemspec.files + ["rack-typekit.gemspec"] do
|
9
|
+
system "gem build rack-typekit.gemspec"
|
10
|
+
system "gem install rack-typekit-#{Rack::Typekit::VERSION}.gem"
|
11
|
+
end
|
data/lib/rack/typekit.rb
CHANGED
@@ -1,36 +1,35 @@
|
|
1
|
-
require 'rack'
|
2
|
-
|
3
1
|
module Rack #:nodoc:
|
4
2
|
class Typekit
|
5
|
-
|
6
|
-
VERSION = "0.
|
3
|
+
|
4
|
+
VERSION = "0.2.0"
|
7
5
|
|
8
6
|
def initialize(app, options = {})
|
9
|
-
raise ArgumentError, "Typekit Kit ID Required" unless options[:kit]
|
7
|
+
raise ArgumentError, "Typekit Kit ID Required" unless options[:kit] &&
|
8
|
+
!options[:kit].empty?
|
10
9
|
@app, @options = app, options
|
11
10
|
end
|
12
11
|
|
13
|
-
def call(env)
|
14
|
-
|
15
|
-
def _call(env)
|
12
|
+
def call(env)
|
16
13
|
@status, @headers, @response = @app.call(env)
|
17
14
|
return [@status, @headers, @response] unless html?
|
18
15
|
response = Rack::Response.new([], @status, @headers)
|
19
|
-
@response.
|
16
|
+
if @response.respond_to?(:to_ary)
|
17
|
+
@response.each { |fragment| response.write inject_typekit(fragment) }
|
18
|
+
end
|
20
19
|
response.finish
|
21
20
|
end
|
22
21
|
|
23
|
-
|
22
|
+
private
|
24
23
|
|
25
|
-
def html?; @headers[
|
24
|
+
def html?; @headers["Content-Type"] =~ /html/; end
|
26
25
|
|
27
|
-
def
|
26
|
+
def inject_typekit(response)
|
28
27
|
script = <<-EOF
|
29
|
-
<script
|
30
|
-
<script
|
28
|
+
<script src="//use.typekit.com/#{@options[:kit]}.js"></script>
|
29
|
+
<script>try{Typekit.load();}catch(e){}</script>
|
31
30
|
EOF
|
32
31
|
|
33
32
|
response.gsub(%r{</head>}, script + "</head>")
|
34
33
|
end
|
35
34
|
end
|
36
|
-
end
|
35
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rack/typekit"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rack-typekit"
|
7
|
+
s.authors = ["Mattt Thompson"]
|
8
|
+
s.email = "m@mattt.me"
|
9
|
+
s.homepage = "http://github.com/mattt/rack-typekit"
|
10
|
+
s.version = Rack::Typekit::VERSION
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
s.summary = "rack-typekit"
|
13
|
+
s.description = "Rack middleware to automatically include your Typekit JavaScript files"
|
14
|
+
|
15
|
+
s.add_runtime_dependency "rack", ">= 1.2.0", "<= 2.0.0"
|
16
|
+
|
17
|
+
s.add_development_dependency "minitest", "~> 2.11.4"
|
18
|
+
s.add_development_dependency "rack-test", "~> 0.6.1"
|
19
|
+
s.add_development_dependency "rake", "~> 0.9.2"
|
20
|
+
|
21
|
+
s.files = Dir["./**/*"].reject { |file| file =~ /\.\/(bin|log|pkg|script|spec|test|vendor)/ }
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "minitest/pride"
|
3
|
+
require "rack"
|
4
|
+
require "rack/lint"
|
5
|
+
require "rack/mock"
|
6
|
+
require "rack/typekit"
|
7
|
+
|
8
|
+
describe Rack::Typekit do
|
9
|
+
let(:html_file) do
|
10
|
+
File.read(File.expand_path("../fixtures/test.html", __FILE__))
|
11
|
+
end
|
12
|
+
let(:html_app) { proc{[200,{"Content-Type"=>"text/html"},[html_file]]} }
|
13
|
+
let(:text_app) { proc{[200,{"Content-Type"=>"text/plain"},["FOO"]]} }
|
14
|
+
let(:typekit_html) { Rack::Typekit.new(html_app, :kit => "123") }
|
15
|
+
let(:typekit_text) { Rack::Typekit.new(text_app, :kit => "123") }
|
16
|
+
|
17
|
+
it { proc{ Rack::Typekit.new(nil) }.must_raise(ArgumentError) }
|
18
|
+
|
19
|
+
it { typekit_html.must_be_kind_of(Rack::Typekit) }
|
20
|
+
it { typekit_text.must_be_kind_of(Rack::Typekit) }
|
21
|
+
|
22
|
+
describe "script injection" do
|
23
|
+
describe "html" do
|
24
|
+
let(:request) { Rack::MockRequest.new(Rack::Lint.new(typekit_html)) }
|
25
|
+
let(:response) { request.get("/") }
|
26
|
+
|
27
|
+
it { response.status.must_equal 200 }
|
28
|
+
it { response.body.must_match %(<script src="//use.typekit.com/123.js"></script>) }
|
29
|
+
it { response.body.must_match "<script>try{Typekit.load();}catch(e){}</script>" }
|
30
|
+
it { response.body.must_match "<title>Rack::Typekit Test</title>" }
|
31
|
+
it { response.body.must_match "<p>Test file.</p>" }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "text" do
|
35
|
+
let(:request) { Rack::MockRequest.new(Rack::Lint.new(typekit_text)) }
|
36
|
+
let(:response) { request.get("/") }
|
37
|
+
|
38
|
+
it { response.status.must_equal 200 }
|
39
|
+
it { response.body.wont_match %(<script src="//use.typekit.com/123.js"></script>) }
|
40
|
+
it { response.body.wont_match "<script>try{Typekit.load();}catch(e){}</script>" }
|
41
|
+
it { response.body.must_match "FOO" }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,69 +1,108 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-typekit
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Mattt Thompson
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
date: 2012-04-09 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: &70315536822540 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.2.0
|
22
|
+
- - <=
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.0.0
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: *70315536822540
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: minitest
|
30
|
+
requirement: &70315536820060 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.11.4
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: *70315536820060
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: rack-test
|
41
|
+
requirement: &70315536818780 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.6.1
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *70315536818780
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rake
|
52
|
+
requirement: &70315536814060 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 0.9.2
|
58
|
+
type: :development
|
59
|
+
prerelease: false
|
60
|
+
version_requirements: *70315536814060
|
21
61
|
description: Rack middleware to automatically include your Typekit JavaScript files
|
22
62
|
email: m@mattt.me
|
23
63
|
executables: []
|
24
|
-
|
25
64
|
extensions: []
|
26
|
-
|
27
65
|
extra_rdoc_files: []
|
28
|
-
|
29
|
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
-
|
66
|
+
files:
|
67
|
+
- ./Gemfile
|
68
|
+
- ./Gemfile.lock
|
69
|
+
- ./lib/rack/typekit.rb
|
70
|
+
- ./LICENSE
|
71
|
+
- ./rack-typekit.gemspec
|
72
|
+
- ./Rakefile
|
73
|
+
- ./README.md
|
74
|
+
- spec/fixtures/test.html
|
75
|
+
- spec/rack_typekit_spec.rb
|
33
76
|
homepage: http://github.com/mattt/rack-typekit
|
34
77
|
licenses: []
|
35
|
-
|
36
78
|
post_install_message:
|
37
79
|
rdoc_options: []
|
38
|
-
|
39
|
-
require_paths:
|
80
|
+
require_paths:
|
40
81
|
- lib
|
41
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
83
|
none: false
|
43
|
-
requirements:
|
44
|
-
- -
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
|
47
|
-
segments:
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
segments:
|
48
89
|
- 0
|
49
|
-
|
50
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
hash: 2753315264514289189
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
92
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
|
56
|
-
segments:
|
57
|
-
-
|
58
|
-
|
59
|
-
- 6
|
60
|
-
version: 1.3.6
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
hash: 2753315264514289189
|
61
100
|
requirements: []
|
62
|
-
|
63
101
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.8.
|
102
|
+
rubygems_version: 1.8.15
|
65
103
|
signing_key:
|
66
104
|
specification_version: 3
|
67
105
|
summary: rack-typekit
|
68
|
-
test_files:
|
69
|
-
|
106
|
+
test_files:
|
107
|
+
- spec/fixtures/test.html
|
108
|
+
- spec/rack_typekit_spec.rb
|
data/README.rdoc
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
= rack-typekit
|
2
|
-
|
3
|
-
Rack middleware to automatically include your Typekit JavaScript files
|
4
|
-
|
5
|
-
== Example
|
6
|
-
|
7
|
-
require 'rack/typekit'
|
8
|
-
|
9
|
-
use Rack::TypeKit, :kit => 'lng5bpe'
|
10
|
-
|
11
|
-
Including this in the <tt>config.ru</tt> file of your Rack application will automatically inject the corresponding JavaScript into the <tt><head></tt> of your HTML:
|
12
|
-
|
13
|
-
<script src="http://use.typekit.com/lng5bpe.js" type="text/javascript"></script><script type="text/javascript">
|
14
|
-
//<![CDATA[
|
15
|
-
try{Typekit.load();}catch(e){}
|
16
|
-
//]]>
|
17
|
-
</script>
|
18
|
-
<script type="text/javascript">
|
19
|
-
|
20
|
-
== License
|
21
|
-
|
22
|
-
rack-typekit is available under the MIT license. See the LICENSE file for more info.
|