rack-gist 1.0.5 → 1.0.6
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/VERSION +1 -1
- data/lib/rack/gist.rb +4 -5
- data/rack-gist.gemspec +2 -2
- data/spec/rack-gist_spec.rb +10 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.6
|
data/lib/rack/gist.rb
CHANGED
@@ -5,14 +5,13 @@ module Rack
|
|
5
5
|
class Gist
|
6
6
|
def initialize(app, options = {})
|
7
7
|
@app = app
|
8
|
-
@gist_path =
|
9
8
|
@options = {
|
10
9
|
:jquery => true
|
11
10
|
}.merge(options)
|
12
11
|
end
|
13
12
|
|
14
13
|
def call(env)
|
15
|
-
if path(env).match(
|
14
|
+
if path(env).match(regex)
|
16
15
|
serve_gist(env)
|
17
16
|
else
|
18
17
|
status, headers, body = @app.call(env)
|
@@ -30,7 +29,7 @@ module Rack
|
|
30
29
|
extras = false
|
31
30
|
doc.search('script[@src*="gist.github.com"]').each do |tag|
|
32
31
|
extras = true
|
33
|
-
tag['src'].match(
|
32
|
+
tag['src'].match(%r{gist\.github\.com/(\d+)\.js(?:\?file=(.*))?}).tap do |match|
|
34
33
|
id, file = match[1, 2]
|
35
34
|
suffix, extra = file ? ["#file_#{file}", "rack-gist-file='#{file}'"] : ['', '']
|
36
35
|
tag.swap("<div 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></div>")
|
@@ -52,7 +51,7 @@ module Rack
|
|
52
51
|
end
|
53
52
|
|
54
53
|
def serve_gist(env)
|
55
|
-
gist_id, file = path(env).match(
|
54
|
+
gist_id, file = path(env).match(regex)[1,2]
|
56
55
|
cache = @options[:cache]
|
57
56
|
gist = (cache ? cache.fetch(cache_key(gist_id, file), :expires_in => 3600) { get_gist(gist_id, file) } : get_gist(gist_id, file)).to_s
|
58
57
|
[
|
@@ -92,7 +91,7 @@ module Rack
|
|
92
91
|
end
|
93
92
|
|
94
93
|
def regex
|
95
|
-
@regex ||= %r{gist\.github\.com/(\d+)
|
94
|
+
@regex ||= %r{gist\.github\.com/(\d+)(?:/(.*))?\.js}
|
96
95
|
end
|
97
96
|
|
98
97
|
def css_html
|
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.0.
|
8
|
+
s.version = "1.0.6"
|
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{2010-
|
12
|
+
s.date = %q{2010-08-08}
|
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 = [
|
data/spec/rack-gist_spec.rb
CHANGED
@@ -5,8 +5,9 @@ describe "Rack::Gist" do
|
|
5
5
|
@gist_id = 348301
|
6
6
|
@app = lambda do |env|
|
7
7
|
headers = { 'Content-Type' => 'text/html' }
|
8
|
-
body =
|
9
|
-
|
8
|
+
body = File.read(File.join(File.dirname(__FILE__), "body-#{env['PATH_INFO'].gsub(/[^\w]/, '')}.html")) rescue ''
|
9
|
+
status = 404 if body.empty?
|
10
|
+
[status || 200, headers, body]
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
@@ -139,4 +140,11 @@ describe "Rack::Gist" do
|
|
139
140
|
body.should == body2
|
140
141
|
end
|
141
142
|
end
|
143
|
+
|
144
|
+
it 'should not explode if not given a gist' do
|
145
|
+
middleware.tap do |a|
|
146
|
+
status, headers, body = a.call(mock_env('/gist.github.com'))
|
147
|
+
status.should == 404
|
148
|
+
end
|
149
|
+
end
|
142
150
|
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: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 6
|
10
|
+
version: 1.0.6
|
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: 2010-
|
18
|
+
date: 2010-08-08 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|