rack-gist 1.1.8 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +6 -0
- data/VERSION +1 -1
- data/lib/rack/gist.rb +22 -15
- data/rack-gist.gemspec +4 -2
- data/spec/body-private.html +8 -0
- data/spec/rack-gist_spec.rb +11 -1
- metadata +6 -4
data/.travis.yml
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.9
|
data/lib/rack/gist.rb
CHANGED
@@ -26,28 +26,35 @@ module Rack
|
|
26
26
|
|
27
27
|
def rewrite(status, headers, body)
|
28
28
|
if headers['Content-Type'].to_s.match('text/html')
|
29
|
-
|
30
|
-
body.each { |part| b << part }
|
31
|
-
body = Nokogiri(b).tap do |doc|
|
32
|
-
if swap_tags(doc)
|
33
|
-
doc.at('head').add_child(css_html)
|
34
|
-
doc.at('body').tap do |node|
|
35
|
-
node.add_child(jquery_link) if @options[:jquery]
|
36
|
-
node.add_child(jquery_helper)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end.to_html(:encoding => @options[:encoding])
|
40
|
-
body = [body]
|
29
|
+
body = [rewrite_body(body)]
|
41
30
|
headers['Content-Length'] = Rack::Utils.bytesize(body.first).to_s
|
42
31
|
end
|
43
32
|
[status, headers, body]
|
44
33
|
end
|
45
34
|
|
35
|
+
def rewrite_body(body)
|
36
|
+
Nokogiri(stringify_body(body)).tap do |doc|
|
37
|
+
if swap_tags(doc)
|
38
|
+
doc.at('head').add_child(css_html)
|
39
|
+
doc.at('body').tap do |node|
|
40
|
+
node.add_child(jquery_link) if @options[:jquery]
|
41
|
+
node.add_child(jquery_helper)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end.to_html(:encoding => @options[:encoding])
|
45
|
+
end
|
46
|
+
|
47
|
+
def stringify_body(body)
|
48
|
+
b = ''
|
49
|
+
body.each { |part| b << part }
|
50
|
+
b
|
51
|
+
end
|
52
|
+
|
46
53
|
def swap_tags(doc)
|
47
54
|
extras = false
|
48
55
|
doc.search('script[@src*="gist.github.com"]').each do |tag|
|
49
56
|
extras = true
|
50
|
-
tag['src'].match(%r{gist\.github\.com/(
|
57
|
+
tag['src'].match(%r{gist\.github\.com/([a-f0-9]+)\.js(?:\?file=(.*))?}).tap do |match|
|
51
58
|
id, file = match[1, 2]
|
52
59
|
suffix, extra = file ? ["#file_#{file}", "rack-gist-file='#{file}'"] : ['', '']
|
53
60
|
tag.swap("<p class='rack-gist' id='rack-gist-#{id}' gist-id='#{id}' #{extra}>Can't see this Gist? <a rel='nofollow' href='http://gist.github.com/#{id}#{suffix}'>View it on Github!</a></p>")
|
@@ -100,7 +107,7 @@ module Rack
|
|
100
107
|
end
|
101
108
|
|
102
109
|
def regex
|
103
|
-
@regex ||= %r{gist\.github\.com/(
|
110
|
+
@regex ||= %r{gist\.github\.com/([a-f0-9]+)(?:/(.*))?\.js}
|
104
111
|
end
|
105
112
|
|
106
113
|
def css_html
|
@@ -134,4 +141,4 @@ module Rack
|
|
134
141
|
EOJQ
|
135
142
|
end
|
136
143
|
end
|
137
|
-
end
|
144
|
+
end
|
data/rack-gist.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rack-gist}
|
8
|
-
s.version = "1.1.
|
8
|
+
s.version = "1.1.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Daniel Huckstep"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-10-30}
|
13
13
|
s.description = %q{Load gists in the background. KTHXBYE!}
|
14
14
|
s.email = %q{darkhelmet@darkhelmetlive.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".rvmrc",
|
22
|
+
".travis.yml",
|
22
23
|
"Gemfile",
|
23
24
|
"Gemfile.lock",
|
24
25
|
"LICENSE",
|
@@ -31,6 +32,7 @@ Gem::Specification.new do |s|
|
|
31
32
|
"spec/body-multiple.html",
|
32
33
|
"spec/body-none.html",
|
33
34
|
"spec/body-partial.html",
|
35
|
+
"spec/body-private.html",
|
34
36
|
"spec/full-gist.js",
|
35
37
|
"spec/partial-gist.js",
|
36
38
|
"spec/rack-gist_spec.rb",
|
data/spec/rack-gist_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
describe "Rack::Gist" do
|
4
4
|
before(:all) do
|
5
5
|
@gist_id = 348301
|
6
|
+
@private_gist_id = '12452a5d2e9938f98da2'
|
6
7
|
end
|
7
8
|
|
8
9
|
def pbody(body)
|
@@ -42,6 +43,15 @@ describe "Rack::Gist" do
|
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
46
|
+
it 'should rewrite private gist embed tags for full gists' do
|
47
|
+
middleware.tap do |a|
|
48
|
+
status, headers, body = a.call(mock_env('/private'))
|
49
|
+
status.should == 200
|
50
|
+
headers['Content-Type'].should == 'text/html'
|
51
|
+
pbody(body).should have_html_tag('p').with('id' => "rack-gist-#{@private_gist_id}", 'gist-id' => @private_gist_id, 'class' => 'rack-gist')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
45
55
|
it 'should rewrite gist embed tags for full gists when content_type includes other things' do
|
46
56
|
middleware({}, { 'Content-Type' => 'text/html; charset=utf-8' }).tap do |a|
|
47
57
|
status, headers, body = a.call(mock_env)
|
@@ -217,4 +227,4 @@ describe "Rack::Gist" do
|
|
217
227
|
pbody(body).should match('US-ASCII')
|
218
228
|
end
|
219
229
|
end
|
220
|
-
end
|
230
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-gist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 9
|
10
|
+
version: 1.1.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Huckstep
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-30 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -155,6 +155,7 @@ extra_rdoc_files:
|
|
155
155
|
files:
|
156
156
|
- .document
|
157
157
|
- .rvmrc
|
158
|
+
- .travis.yml
|
158
159
|
- Gemfile
|
159
160
|
- Gemfile.lock
|
160
161
|
- LICENSE
|
@@ -167,6 +168,7 @@ files:
|
|
167
168
|
- spec/body-multiple.html
|
168
169
|
- spec/body-none.html
|
169
170
|
- spec/body-partial.html
|
171
|
+
- spec/body-private.html
|
170
172
|
- spec/full-gist.js
|
171
173
|
- spec/partial-gist.js
|
172
174
|
- spec/rack-gist_spec.rb
|