rack-typekit 0.1.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/LICENSE +19 -0
- data/README.rdoc +22 -0
- data/lib/rack/typekit.rb +36 -0
- metadata +69 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2011 Mattt Thompson (http://mattt.me)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
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.
|
data/lib/rack/typekit.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
module Rack #:nodoc:
|
4
|
+
class Typekit
|
5
|
+
|
6
|
+
VERSION = "0.1.0"
|
7
|
+
|
8
|
+
def initialize(app, options = {})
|
9
|
+
raise ArgumentError, "Typekit Kit ID Required" unless options[:kit] and !options[:kit].empty?
|
10
|
+
@app, @options = app, options
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env); dup._call(env); end
|
14
|
+
|
15
|
+
def _call(env)
|
16
|
+
@status, @headers, @response = @app.call(env)
|
17
|
+
return [@status, @headers, @response] unless html?
|
18
|
+
response = Rack::Response.new([], @status, @headers)
|
19
|
+
@response.each { |fragment| response.write inject(fragment) }
|
20
|
+
response.finish
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def html?; @headers['Content-Type'] =~ /html/; end
|
26
|
+
|
27
|
+
def inject(response)
|
28
|
+
script = <<-EOF
|
29
|
+
<script type="text/javascript" src="http://use.typekit.com/#{@options[:kit]}.js"></script>
|
30
|
+
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
|
31
|
+
EOF
|
32
|
+
|
33
|
+
response.gsub(%r{</head>}, script + "</head>")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-typekit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Mattt Thompson
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-19 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Rack middleware to automatically include your Typekit JavaScript files
|
22
|
+
email: m@mattt.me
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/rack/typekit.rb
|
31
|
+
- LICENSE
|
32
|
+
- README.rdoc
|
33
|
+
homepage: http://github.com/mattt/rack-typekit
|
34
|
+
licenses: []
|
35
|
+
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 3
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
version: "0"
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 23
|
56
|
+
segments:
|
57
|
+
- 1
|
58
|
+
- 3
|
59
|
+
- 6
|
60
|
+
version: 1.3.6
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.8.10
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: rack-typekit
|
68
|
+
test_files: []
|
69
|
+
|