rack-lettering 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +41 -0
- data/.rspec +3 -0
- data/.yardopts +1 -0
- data/Gemfile +4 -0
- data/README.md +49 -0
- data/Rakefile +18 -0
- data/lib/rack/lettering/version.rb +5 -0
- data/lib/rack/lettering.rb +87 -0
- data/rack-lettering.gemspec +26 -0
- data/spec/fixtures/atlantis.html +286 -0
- data/spec/rack_lettering_spec.rb +65 -0
- data/spec/spec_helper.rb +36 -0
- metadata +146 -0
data/.gemtest
ADDED
File without changes
|
data/.gitignore
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
!.gitignore
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
*.sw[a-p]
|
5
|
+
*.tmproj
|
6
|
+
*.tmproject
|
7
|
+
*.un~
|
8
|
+
*~
|
9
|
+
.DS_Store
|
10
|
+
.Spotlight-V100
|
11
|
+
.Trashes
|
12
|
+
._*
|
13
|
+
.bundle
|
14
|
+
.config
|
15
|
+
.directory
|
16
|
+
.elc
|
17
|
+
.redcar
|
18
|
+
.yardoc
|
19
|
+
/.emacs.desktop
|
20
|
+
/.emacs.desktop.lock
|
21
|
+
Desktop.ini
|
22
|
+
Gemfile.lock
|
23
|
+
Icon?
|
24
|
+
InstalledFiles
|
25
|
+
Session.vim
|
26
|
+
Thumbs.db
|
27
|
+
\#*\#
|
28
|
+
_yardoc
|
29
|
+
auto-save-list
|
30
|
+
coverage
|
31
|
+
doc/
|
32
|
+
lib/bundler/man
|
33
|
+
pkg
|
34
|
+
pkg/*
|
35
|
+
rdoc
|
36
|
+
spec/reports
|
37
|
+
test/tmp
|
38
|
+
test/version_tmp
|
39
|
+
tmp
|
40
|
+
tmtags
|
41
|
+
tramp
|
data/.rspec
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
Rack::Lettering
|
2
|
+
===============
|
3
|
+
|
4
|
+
Rack::Lettering is a Rack Middleware for inserting [Lettering.js](http://letteringjs.com/) style syntax into a response body.
|
5
|
+
|
6
|
+
It was built during [ConvergeSE](http://convergese.com/) 2011 and was inspired by a talk given by [Trent Walton](http://trentwalton.com/) about CSS Typography.
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
(sudo) gem install rack-lettering
|
12
|
+
|
13
|
+
Usage
|
14
|
+
-----
|
15
|
+
|
16
|
+
Rack::Lettering accepts an options hash that allows you to define the lettering treatment (letters, words, or lines) you'd like for a given selector. Any CSS selector may be used.
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require 'rack/lettering'
|
20
|
+
use Rack:Lettering, :letters => ['#letter_selector'], :words => ['.word_selector'], :lines => ['#line_selector']
|
21
|
+
```
|
22
|
+
|
23
|
+
Caveat
|
24
|
+
------
|
25
|
+
|
26
|
+
I haven't actually compared the results with those from lettering.js. The project has tests, but there may be edge cases I've missed. Please feel free to fork and send pull requests if you find anything that's broken.
|
27
|
+
|
28
|
+
License
|
29
|
+
-------
|
30
|
+
Copyright (c) 2011 Steve Agalloco
|
31
|
+
|
32
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
33
|
+
a copy of this software and associated documentation files (the
|
34
|
+
"Software"), to deal in the Software without restriction, including
|
35
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
36
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
37
|
+
permit persons to whom the Software is furnished to do so, subject to
|
38
|
+
the following conditions:
|
39
|
+
|
40
|
+
The above copyright notice and this permission notice shall be
|
41
|
+
included in all copies or substantial portions of the Software.
|
42
|
+
|
43
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
44
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
45
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
46
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
47
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
48
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
49
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
task :default => :spec
|
10
|
+
task :test => :spec
|
11
|
+
|
12
|
+
require 'yard'
|
13
|
+
namespace :doc do
|
14
|
+
YARD::Rake::YardocTask.new do |task|
|
15
|
+
task.files = ['LICENSE.md', 'lib/**/*.rb']
|
16
|
+
task.options = ['--markup', 'markdown']
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
class Lettering
|
6
|
+
|
7
|
+
def initialize(app, options = {})
|
8
|
+
@app = app
|
9
|
+
@words = options[:words] || []
|
10
|
+
@letters = options[:letters] || []
|
11
|
+
@lines = options[:lines] || []
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
status, @headers, @body = @app.call(env)
|
16
|
+
|
17
|
+
if html?
|
18
|
+
apply_lettering
|
19
|
+
update_content_length
|
20
|
+
end
|
21
|
+
|
22
|
+
[status, @headers, @body]
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def apply_lettering
|
28
|
+
apply_word_rules
|
29
|
+
apply_letter_rules
|
30
|
+
apply_line_rules
|
31
|
+
|
32
|
+
@body = document.to_html
|
33
|
+
end
|
34
|
+
|
35
|
+
def apply_word_rules
|
36
|
+
@words.each do |word|
|
37
|
+
document.css(word.strip).each do |node|
|
38
|
+
content = []
|
39
|
+
node.inner_html.split(' ').each_with_index do |text, index|
|
40
|
+
content << span(text, 'word', index+1)
|
41
|
+
end
|
42
|
+
node.inner_html = content.join(' ')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def apply_letter_rules
|
48
|
+
@letters.each do |letter|
|
49
|
+
document.css(letter.strip).each do |node|
|
50
|
+
content = ''
|
51
|
+
node.content.chars.each_with_index do |text, index|
|
52
|
+
content << span(text, 'char', index+1)
|
53
|
+
end
|
54
|
+
node.inner_html = content
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def apply_line_rules
|
60
|
+
@lines.each do |line|
|
61
|
+
document.css(line.strip).each do |node|
|
62
|
+
content = ''
|
63
|
+
node.inner_html.split(/\n/).reject { |t| t.empty? }.each_with_index do |text, index|
|
64
|
+
content << span(text, 'line', index+1)
|
65
|
+
end
|
66
|
+
node.inner_html = content
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def span(content, classname, count)
|
72
|
+
"<span class=\"#{classname}#{count}\">#{content}</span>"
|
73
|
+
end
|
74
|
+
|
75
|
+
def document
|
76
|
+
@doc ||= Nokogiri::HTML.parse(@body)
|
77
|
+
end
|
78
|
+
|
79
|
+
def html?
|
80
|
+
@headers["Content-Type"] && @headers["Content-Type"].include?("text/html")
|
81
|
+
end
|
82
|
+
|
83
|
+
def update_content_length
|
84
|
+
@headers['Content-Length'] = Rack::Utils.bytesize(@body).to_s
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rack/lettering/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'rack-lettering'
|
6
|
+
gem.version = Rack::Lettering::VERSION
|
7
|
+
gem.author = "Steve Agalloco"
|
8
|
+
gem.email = 'steve.agalloco@gmail.com'
|
9
|
+
gem.homepage = 'https://github.com/spagalloco/rack-lettering'
|
10
|
+
gem.summary = %q{Rack Middleware for inserting Lettering.js style syntax into a response body}
|
11
|
+
gem.description = gem.summary
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split("\n")
|
14
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
|
18
|
+
gem.add_dependency 'rack'
|
19
|
+
gem.add_dependency 'nokogiri', '~> 1.4.6'
|
20
|
+
|
21
|
+
gem.add_development_dependency 'maruku', '~> 0.6'
|
22
|
+
gem.add_development_dependency 'rake', '~> 0.9'
|
23
|
+
gem.add_development_dependency 'rspec', '~> 2.6'
|
24
|
+
gem.add_development_dependency 'simplecov', '~> 0.4'
|
25
|
+
gem.add_development_dependency 'yard', '~> 0.7'
|
26
|
+
end
|
@@ -0,0 +1,286 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html lang="en" class="no-js">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
7
|
+
|
8
|
+
<title>Atlantis World's Fair</title>
|
9
|
+
<meta name="Author" content="Friends of Mighty">
|
10
|
+
<!-- � 2010 by Friends of Mighty -->
|
11
|
+
|
12
|
+
<link rel="stylesheet" href="css/all.min.css">
|
13
|
+
<script type="text/javascript" src="http://use.typekit.com/ips3zdt.js"></script>
|
14
|
+
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
|
15
|
+
<script src="../js/modernizr-1.5.min.js"></script>
|
16
|
+
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
|
17
|
+
<script src="../js/lettering.min.js"></script>
|
18
|
+
<script>
|
19
|
+
$(document).ready(function() {
|
20
|
+
$("#txt_below, #txt_date, #txt_worldsfair, #txt_welcomesignvert").lettering();
|
21
|
+
$("#txt_imaginationflag, #txt_countdown, #txt_worldsfaircircle, #txt_gowiththeflow, #youarehere").lettering('words');
|
22
|
+
$("#txt_gillsorlungs, #txt_sealand, #txt_bubbles, #subwaymap, #txt_adspace, #txt_attnatlantesians, .corner").lettering('lines');
|
23
|
+
goBig();
|
24
|
+
$(window).resize(function() { goBig(); });
|
25
|
+
|
26
|
+
});
|
27
|
+
|
28
|
+
function goBig() {
|
29
|
+
if($(window).height() > 800) {
|
30
|
+
$('#footer').height(950);
|
31
|
+
$('#morefooter').height(500);
|
32
|
+
$('#depthscale').height(17910);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
|
37
|
+
</script>
|
38
|
+
|
39
|
+
|
40
|
+
</head>
|
41
|
+
|
42
|
+
<body>
|
43
|
+
|
44
|
+
<div id="back_to"><a href="http://lostworldsfairs.com">Lost World's Fairs</a></div>
|
45
|
+
<div id="header">
|
46
|
+
<div id="img_doc"></div>
|
47
|
+
<div id="img_ship"></div>
|
48
|
+
|
49
|
+
|
50
|
+
<div class="container">
|
51
|
+
<p id="txt_below">Below</p>
|
52
|
+
</div>
|
53
|
+
|
54
|
+
<div id="backwave"></div>
|
55
|
+
<div id="frontwave"></div>
|
56
|
+
|
57
|
+
</div>
|
58
|
+
|
59
|
+
<div id="tube">
|
60
|
+
<div class="tube_container">
|
61
|
+
<div id="tube_dude" class="tube_container"></div>
|
62
|
+
</div>
|
63
|
+
<div class="tube_container">
|
64
|
+
<div id="tube_overlay"></div>
|
65
|
+
<div id="tube_backtop"></div>
|
66
|
+
<div id="tube_back"></div>
|
67
|
+
<div id="tube_fronttop"></div>
|
68
|
+
<div id="tube_frontbottom"></div>
|
69
|
+
<div id="tube_front"></div>
|
70
|
+
</div>
|
71
|
+
</div>
|
72
|
+
|
73
|
+
<div id="depthfinder"><span id="depth-o-meter">0</span><span id="txt_k">k</span> Leagues</div>
|
74
|
+
<div id="depthscale"></div>
|
75
|
+
|
76
|
+
|
77
|
+
<div id="content">
|
78
|
+
|
79
|
+
<section id="depth1">
|
80
|
+
<div class="container">
|
81
|
+
<div id="welcomesign" class="bringFront">
|
82
|
+
<header>
|
83
|
+
<h1><span id="txt_date">1962</span> <span id="txt_atlantis">Atlantis</span> <span id="txt_worldsfair">Worlds Fair</span></h1>
|
84
|
+
<p id="txt_taglines"><span id="txt_worldsfaircircle">The World's Fair</span> <span id="txt_imaginationflag">The Depths Of Imagination</span></p>
|
85
|
+
</header>
|
86
|
+
|
87
|
+
</div>
|
88
|
+
|
89
|
+
<aside id="info_1" class="dyk-right">
|
90
|
+
<div class="didyouknow">
|
91
|
+
<img src="img/dyk-info.png" alt="info" height="30" width="30"/>
|
92
|
+
<h4>Did You Know</h4>
|
93
|
+
<p>Atlantis was<br/> originally built on<br/> the floor of the<br/> sea in 722 BCE<br/> by amphibious<br/> herbivores</p>
|
94
|
+
</div>
|
95
|
+
</aside>
|
96
|
+
|
97
|
+
</div>
|
98
|
+
</section>
|
99
|
+
|
100
|
+
<section id="depth2">
|
101
|
+
<div class="container">
|
102
|
+
|
103
|
+
<div id="welcometerrarians" class="bringFront">
|
104
|
+
<h1 id="txt_terrarians">Welcome Terrarians!</h1>
|
105
|
+
<p id="txt_gillsorlungs">
|
106
|
+
Hello!<br/>
|
107
|
+
Gills or<br/>
|
108
|
+
Lungs<br/>
|
109
|
+
Come as you are!<br/>
|
110
|
+
All welcome
|
111
|
+
</p>
|
112
|
+
|
113
|
+
<p id="txt_sealand">
|
114
|
+
Sea<br/>
|
115
|
+
Land
|
116
|
+
</p>
|
117
|
+
|
118
|
+
<p id="txt_bubbles">
|
119
|
+
All New!<br/>
|
120
|
+
Bi-oxy<br/>
|
121
|
+
Bubbles<br/>
|
122
|
+
For your breathing<br/>
|
123
|
+
pleasure!
|
124
|
+
</p>
|
125
|
+
</div>
|
126
|
+
|
127
|
+
|
128
|
+
<aside id="info_2" class="dyk-left">
|
129
|
+
<div class="didyouknow">
|
130
|
+
<img src="img/dyk-info.png" alt="info" height="30" width="30"/>
|
131
|
+
<h4>Did You Know</h4>
|
132
|
+
<p>The national bird of<br/> Atlantis is the<br/> sting ray.</p>
|
133
|
+
</div>
|
134
|
+
</aside>
|
135
|
+
|
136
|
+
<aside id="info_3" class="dyk-right">
|
137
|
+
<div class="didyouknow">
|
138
|
+
<img src="img/dyk-info.png" alt="info" height="30" width="30"/>
|
139
|
+
<h4>Did You Know</h4>
|
140
|
+
<p>In 1432, Atlantis<br/> burnt down in a<br/> wildfire. Few of the<br/> city's original<br/> buildings remain,<br/> but those that do<br/> are preserved as<br/> historical sites in the<br/> Smolder District.</p>
|
141
|
+
</div>
|
142
|
+
</aside>
|
143
|
+
</div>
|
144
|
+
</section>
|
145
|
+
|
146
|
+
<section id="depth3">
|
147
|
+
<div class="container">
|
148
|
+
|
149
|
+
<div id="biwaymap" class="bringFront">
|
150
|
+
<h1 id="txt_welcomesignvert">Welcome</h1>
|
151
|
+
<p id="subwaymap">
|
152
|
+
Biway Map<br/>
|
153
|
+
Surface<br/>
|
154
|
+
<span id="youarehere">You Are Here</span><br/>
|
155
|
+
Atlantis<br/>
|
156
|
+
</p>
|
157
|
+
</div>
|
158
|
+
|
159
|
+
<div id="flow" class="bringFront">
|
160
|
+
<h2 id="txt_gowiththeflow">Go With The Flow</h2>
|
161
|
+
|
162
|
+
<p id="txt_attnatlantesians">
|
163
|
+
Attn<br/>
|
164
|
+
Atlantesians<br/>
|
165
|
+
Turn Off<br/>
|
166
|
+
All<br/>
|
167
|
+
Electronics<br/>
|
168
|
+
Please<br/>
|
169
|
+
Thank You
|
170
|
+
</p>
|
171
|
+
|
172
|
+
</div>
|
173
|
+
|
174
|
+
<aside id="info_4" class="dyk-right">
|
175
|
+
<div class="didyouknow">
|
176
|
+
<img src="img/dyk-info.png" alt="info" height="30" width="30"/>
|
177
|
+
<h4>Did You Know</h4>
|
178
|
+
<p>Now entering The<br/> Dark Zone. Be<br/> prepared to lose<br/> signal for a duration of<br/> 3 minutes.</p>
|
179
|
+
</div>
|
180
|
+
</aside>
|
181
|
+
|
182
|
+
</div>
|
183
|
+
</section>
|
184
|
+
|
185
|
+
<section id="depth4"><!-- DARK ZONE -->
|
186
|
+
<div class="container">
|
187
|
+
<div class="bringFront">
|
188
|
+
|
189
|
+
<aside id="adspace" class="dyk-right">
|
190
|
+
<p id="txt_adspace">
|
191
|
+
Available:<br/>
|
192
|
+
Ad<br/>
|
193
|
+
Space<br/>
|
194
|
+
For more details:<br/>
|
195
|
+
+417-781-1616
|
196
|
+
</p>
|
197
|
+
</aside>
|
198
|
+
|
199
|
+
</div>
|
200
|
+
|
201
|
+
|
202
|
+
</div>
|
203
|
+
</section>
|
204
|
+
|
205
|
+
<section id="depth5">
|
206
|
+
<div class="container">
|
207
|
+
<aside id="info_5" class="dyk-right">
|
208
|
+
<div class="didyouknow">
|
209
|
+
<img src="img/dyk-info.png" alt="info" height="30" width="30"/>
|
210
|
+
<h4>Did You Know</h4>
|
211
|
+
<p>The easiest way to<br/> spot a native<br/> Atlantesian is by<br/> their gills,<br/> bluish-green skin,<br/> webbed feet, and<br/> friendly disposition.</p>
|
212
|
+
</div>
|
213
|
+
</aside>
|
214
|
+
|
215
|
+
<div id="sign_4square" class="bringFront">
|
216
|
+
<h1>
|
217
|
+
<span class="line1">At</span><span class="line2">lan</span><span class="line3">tis</span>
|
218
|
+
</h1>
|
219
|
+
|
220
|
+
<p class="corner1 corner">
|
221
|
+
You're<br/>
|
222
|
+
Almost<br/>
|
223
|
+
There<br/>
|
224
|
+
</p>
|
225
|
+
|
226
|
+
<p class="corner2 corner">
|
227
|
+
The Most<br/>
|
228
|
+
Magical<br/>
|
229
|
+
Place In Water<br/>
|
230
|
+
</p>
|
231
|
+
|
232
|
+
|
233
|
+
<p class="corner3 corner">
|
234
|
+
Enchantment<br/>
|
235
|
+
Under<br/>
|
236
|
+
The Sea<br/>
|
237
|
+
</p>
|
238
|
+
|
239
|
+
<p class="corner4 corner">
|
240
|
+
The Ultimate<br/>
|
241
|
+
Water<br/>
|
242
|
+
Destination<br/>
|
243
|
+
</p>
|
244
|
+
</div>
|
245
|
+
|
246
|
+
<div id="countdown">
|
247
|
+
<p id="txt_countdown">10 9 8 7 6 5 4 3 2 1</p>
|
248
|
+
</div>
|
249
|
+
</div>
|
250
|
+
</section>
|
251
|
+
|
252
|
+
<footer id="footer">
|
253
|
+
<div class="container">
|
254
|
+
<div class="bringFront">
|
255
|
+
</div>
|
256
|
+
<p>Hi.</p>
|
257
|
+
</div>
|
258
|
+
<div id="morefooter"></div>
|
259
|
+
</footer>
|
260
|
+
</div>
|
261
|
+
|
262
|
+
<script type="text/javascript">
|
263
|
+
$(document).ready(function() {
|
264
|
+
$(window).scroll(function() {
|
265
|
+
var d = $("#depth-o-meter");
|
266
|
+
d.text(Math.floor($(window).scrollTop()/850));
|
267
|
+
});
|
268
|
+
});
|
269
|
+
</script>
|
270
|
+
|
271
|
+
<script type="text/javascript">
|
272
|
+
|
273
|
+
var _gaq = _gaq || [];
|
274
|
+
_gaq.push(['_setAccount', 'UA-3299532-42']);
|
275
|
+
_gaq.push(['_trackPageview']);
|
276
|
+
|
277
|
+
(function() {
|
278
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
279
|
+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
280
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
281
|
+
})();
|
282
|
+
|
283
|
+
</script>
|
284
|
+
|
285
|
+
</body>
|
286
|
+
</html>
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rack::Lettering do
|
4
|
+
|
5
|
+
context 'text/html requests' do
|
6
|
+
before(:each) do
|
7
|
+
body = fixture('atlantis.html')
|
8
|
+
|
9
|
+
@letter_selectors = ["#txt_below", "#txt_date", "#txt_worldsfair", "#txt_welcomesignvert"]
|
10
|
+
@word_selectors = ["#txt_imaginationflag", "#txt_countdown", "#txt_worldsfaircircle", "#txt_gowiththeflow", "#youarehere"]
|
11
|
+
@line_selectors = ["#txt_gillsorlungs", "#txt_sealand", "#txt_bubbles", "#subwaymap", "#txt_adspace", "#txt_attnatlantesians", ".corner"]
|
12
|
+
|
13
|
+
options = {
|
14
|
+
:letters => @letter_selectors,
|
15
|
+
:words => @word_selectors,
|
16
|
+
:lines => @line_selectors
|
17
|
+
}
|
18
|
+
|
19
|
+
@app = lambda { |env| [200, {'Content-Type' => 'text/html', 'Content-Length'=> '123'}, body] }
|
20
|
+
@request = Rack::MockRequest.env_for("/")
|
21
|
+
@response = Rack::Lettering.new(@app, options).call(@request)
|
22
|
+
|
23
|
+
@response_headers = @response[1]
|
24
|
+
@response_body = @response[2]
|
25
|
+
|
26
|
+
@document = Nokogiri::HTML.parse(@response_body)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should wrap letters inside letter spans' do
|
30
|
+
@letter_selectors.each do |selector|
|
31
|
+
@document.css(selector).should have_css_selector('.char1')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should wrap words inside word spans' do
|
36
|
+
@word_selectors.each do |selector|
|
37
|
+
@document.css(selector).should have_css_selector('.word1')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should wrap lines inside line spans' do
|
42
|
+
@line_selectors.each do |selector|
|
43
|
+
@document.css(selector).should have_css_selector('.line1')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should update the content_length header' do
|
48
|
+
@response_headers['Content-Length'].should_not eq('123')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'non text/html requests' do
|
53
|
+
before(:all) do
|
54
|
+
@body = "{'foo':'bar'}"
|
55
|
+
@app = lambda { |env| [200, {'Content-Type' => 'application/json'}, @body] }
|
56
|
+
@request = Rack::MockRequest.env_for("/")
|
57
|
+
@response_body = Rack::Lettering.new(@app).call(@request).last
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should not modify the response body" do
|
61
|
+
@response_body.should eq(@body)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
require 'rack'
|
6
|
+
require 'rack/lettering'
|
7
|
+
require 'rspec'
|
8
|
+
require 'nokogiri'
|
9
|
+
|
10
|
+
def fixture_path
|
11
|
+
File.expand_path("../fixtures", __FILE__)
|
12
|
+
end
|
13
|
+
|
14
|
+
def fixture(file)
|
15
|
+
File.read(fixture_path + '/' + file)
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec::Matchers.define :have_css_selector do |selector|
|
19
|
+
|
20
|
+
match do |document|
|
21
|
+
@doc = document
|
22
|
+
@doc.css(selector).size > 0
|
23
|
+
end
|
24
|
+
|
25
|
+
description do
|
26
|
+
"have_css_selector :#{selector}"
|
27
|
+
end
|
28
|
+
|
29
|
+
failure_message_for_should do |text|
|
30
|
+
"have_css_selector expected #{@doc} to have selector: #{selector}"
|
31
|
+
end
|
32
|
+
|
33
|
+
failure_message_for_should_not do |text|
|
34
|
+
"have_css_selector expected #{@doc} not to have selector: #{selector}"
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-lettering
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Steve Agalloco
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-26 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rack
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 1.4.6
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: maruku
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0.6"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rake
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0.9"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: rspec
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "2.6"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: simplecov
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0.4"
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id006
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: yard
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ~>
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0.7"
|
91
|
+
type: :development
|
92
|
+
version_requirements: *id007
|
93
|
+
description: Rack Middleware for inserting Lettering.js style syntax into a response body
|
94
|
+
email: steve.agalloco@gmail.com
|
95
|
+
executables: []
|
96
|
+
|
97
|
+
extensions: []
|
98
|
+
|
99
|
+
extra_rdoc_files: []
|
100
|
+
|
101
|
+
files:
|
102
|
+
- .gemtest
|
103
|
+
- .gitignore
|
104
|
+
- .rspec
|
105
|
+
- .yardopts
|
106
|
+
- Gemfile
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lib/rack/lettering.rb
|
110
|
+
- lib/rack/lettering/version.rb
|
111
|
+
- rack-lettering.gemspec
|
112
|
+
- spec/fixtures/atlantis.html
|
113
|
+
- spec/rack_lettering_spec.rb
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
has_rdoc: true
|
116
|
+
homepage: https://github.com/spagalloco/rack-lettering
|
117
|
+
licenses: []
|
118
|
+
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: "0"
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: "0"
|
136
|
+
requirements: []
|
137
|
+
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 1.6.1
|
140
|
+
signing_key:
|
141
|
+
specification_version: 3
|
142
|
+
summary: Rack Middleware for inserting Lettering.js style syntax into a response body
|
143
|
+
test_files:
|
144
|
+
- spec/fixtures/atlantis.html
|
145
|
+
- spec/rack_lettering_spec.rb
|
146
|
+
- spec/spec_helper.rb
|