rack-gist 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +10 -1
- data/Gemfile.lock +34 -0
- data/VERSION +1 -1
- data/lib/rack/gist.rb +2 -1
- data/rack-gist.gemspec +6 -5
- data/spec/body-full.html +1 -0
- data/spec/body-multiple.html +1 -0
- data/spec/body-none.html +1 -0
- data/spec/body-partial.html +1 -0
- data/spec/rack-gist_spec.rb +23 -17
- data/spec/spec_helper.rb +1 -3
- metadata +45 -53
data/Gemfile
CHANGED
@@ -4,10 +4,19 @@ gem 'nokogiri', '~> 1.4.3.1'
|
|
4
4
|
gem 'rest-client', '~> 1.6.0'
|
5
5
|
|
6
6
|
group :development do
|
7
|
+
gem 'jeweler', '~> 1.4.0'
|
7
8
|
gem 'fakeweb', '~> 1.2.8'
|
8
9
|
gem 'rspec', '~> 1.3.0'
|
9
10
|
gem 'yard', '~> 0.5.8'
|
10
11
|
gem 'rack', '~> 1.2.1'
|
11
12
|
gem 'activesupport', '~> 2.3.8'
|
12
|
-
|
13
|
+
|
14
|
+
# Platforms doesn't work :(
|
15
|
+
# platforms :ruby_18 do
|
16
|
+
# gem 'ruby-debug'
|
17
|
+
# end
|
18
|
+
|
19
|
+
# platforms :ruby_19 do
|
20
|
+
# gem 'ruby-debug19'
|
21
|
+
# end
|
13
22
|
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (2.3.9)
|
5
|
+
fakeweb (1.2.8)
|
6
|
+
gemcutter (0.6.1)
|
7
|
+
git (1.2.5)
|
8
|
+
jeweler (1.4.0)
|
9
|
+
gemcutter (>= 0.1.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rubyforge (>= 2.0.0)
|
12
|
+
json_pure (1.4.6)
|
13
|
+
mime-types (1.16)
|
14
|
+
nokogiri (1.4.3.1)
|
15
|
+
rack (1.2.1)
|
16
|
+
rest-client (1.6.1)
|
17
|
+
mime-types (>= 1.16)
|
18
|
+
rspec (1.3.0)
|
19
|
+
rubyforge (2.0.4)
|
20
|
+
json_pure (>= 1.1.7)
|
21
|
+
yard (0.5.8)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
activesupport (~> 2.3.8)
|
28
|
+
fakeweb (~> 1.2.8)
|
29
|
+
jeweler (~> 1.4.0)
|
30
|
+
nokogiri (~> 1.4.3.1)
|
31
|
+
rack (~> 1.2.1)
|
32
|
+
rest-client (~> 1.6.0)
|
33
|
+
rspec (~> 1.3.0)
|
34
|
+
yard (~> 0.5.8)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.1
|
data/lib/rack/gist.rb
CHANGED
@@ -26,7 +26,7 @@ module Rack
|
|
26
26
|
def rewrite(status, headers, body)
|
27
27
|
if headers['Content-Type'].to_s.match('text/html')
|
28
28
|
b = ''
|
29
|
-
body.each { |part| b << part
|
29
|
+
body.each { |part| b << part }
|
30
30
|
body = Nokogiri(b).tap do |doc|
|
31
31
|
if swap_tags(doc)
|
32
32
|
doc.at('head').add_child(css_html)
|
@@ -36,6 +36,7 @@ module Rack
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end.to_s
|
39
|
+
body = [body]
|
39
40
|
headers['Content-Length'] = body.map { |part| Rack::Utils.bytesize(part) }.inject(0) { |sum, size| sum + size }.to_s
|
40
41
|
end
|
41
42
|
[status, headers, body]
|
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.1"
|
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-09-
|
12
|
+
s.date = %q{2010-09-10}
|
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 = [
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
".document",
|
21
21
|
".gitignore",
|
22
22
|
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
23
24
|
"LICENSE",
|
24
25
|
"README.rdoc",
|
25
26
|
"Rakefile",
|
@@ -53,31 +54,31 @@ Gem::Specification.new do |s|
|
|
53
54
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
55
|
s.add_runtime_dependency(%q<nokogiri>, ["~> 1.4.3.1"])
|
55
56
|
s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.0"])
|
57
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.4.0"])
|
56
58
|
s.add_development_dependency(%q<fakeweb>, ["~> 1.2.8"])
|
57
59
|
s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
|
58
60
|
s.add_development_dependency(%q<yard>, ["~> 0.5.8"])
|
59
61
|
s.add_development_dependency(%q<rack>, ["~> 1.2.1"])
|
60
62
|
s.add_development_dependency(%q<activesupport>, ["~> 2.3.8"])
|
61
|
-
s.add_development_dependency(%q<ruby-debug>, [">= 0"])
|
62
63
|
else
|
63
64
|
s.add_dependency(%q<nokogiri>, ["~> 1.4.3.1"])
|
64
65
|
s.add_dependency(%q<rest-client>, ["~> 1.6.0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 1.4.0"])
|
65
67
|
s.add_dependency(%q<fakeweb>, ["~> 1.2.8"])
|
66
68
|
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
67
69
|
s.add_dependency(%q<yard>, ["~> 0.5.8"])
|
68
70
|
s.add_dependency(%q<rack>, ["~> 1.2.1"])
|
69
71
|
s.add_dependency(%q<activesupport>, ["~> 2.3.8"])
|
70
|
-
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
71
72
|
end
|
72
73
|
else
|
73
74
|
s.add_dependency(%q<nokogiri>, ["~> 1.4.3.1"])
|
74
75
|
s.add_dependency(%q<rest-client>, ["~> 1.6.0"])
|
76
|
+
s.add_dependency(%q<jeweler>, ["~> 1.4.0"])
|
75
77
|
s.add_dependency(%q<fakeweb>, ["~> 1.2.8"])
|
76
78
|
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
77
79
|
s.add_dependency(%q<yard>, ["~> 0.5.8"])
|
78
80
|
s.add_dependency(%q<rack>, ["~> 1.2.1"])
|
79
81
|
s.add_dependency(%q<activesupport>, ["~> 2.3.8"])
|
80
|
-
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
81
82
|
end
|
82
83
|
end
|
83
84
|
|
data/spec/body-full.html
CHANGED
data/spec/body-multiple.html
CHANGED
data/spec/body-none.html
CHANGED
data/spec/body-partial.html
CHANGED
data/spec/rack-gist_spec.rb
CHANGED
@@ -5,11 +5,17 @@ describe "Rack::Gist" do
|
|
5
5
|
@gist_id = 348301
|
6
6
|
end
|
7
7
|
|
8
|
+
def pbody(body)
|
9
|
+
''.tap do |b|
|
10
|
+
body.each { |part| b << part.to_s } # For giggles
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
8
14
|
def app(headers)
|
9
15
|
lambda do |env|
|
10
16
|
body = File.read(File.join(File.dirname(__FILE__), "body-#{env['PATH_INFO'].gsub(/[^\w]/, '')}.html")) rescue ''
|
11
17
|
status = 404 if body.empty?
|
12
|
-
[status || 200, headers, body]
|
18
|
+
[status || 200, headers, [body]]
|
13
19
|
end
|
14
20
|
end
|
15
21
|
|
@@ -32,7 +38,7 @@ describe "Rack::Gist" do
|
|
32
38
|
status, headers, body = a.call(mock_env)
|
33
39
|
status.should == 200
|
34
40
|
headers['Content-Type'].should == 'text/html'
|
35
|
-
body.
|
41
|
+
pbody(body).should have_html_tag('p').with('id' => "rack-gist-#{@gist_id}", 'gist-id' => @gist_id, 'class' => 'rack-gist')
|
36
42
|
end
|
37
43
|
end
|
38
44
|
|
@@ -41,7 +47,7 @@ describe "Rack::Gist" do
|
|
41
47
|
status, headers, body = a.call(mock_env)
|
42
48
|
status.should == 200
|
43
49
|
headers['Content-Type'].should == 'text/html; charset=utf-8'
|
44
|
-
body.
|
50
|
+
pbody(body).should have_html_tag('p').with('id' => "rack-gist-#{@gist_id}", 'gist-id' => @gist_id, 'class' => 'rack-gist')
|
45
51
|
end
|
46
52
|
end
|
47
53
|
|
@@ -50,7 +56,7 @@ describe "Rack::Gist" do
|
|
50
56
|
status, headers, body = a.call(mock_env('/partial'))
|
51
57
|
status.should == 200
|
52
58
|
headers['Content-Type'].should == 'text/html'
|
53
|
-
body.
|
59
|
+
pbody(body).should have_html_tag('p').with('id' => "rack-gist-#{@gist_id}", 'gist-id' => @gist_id, 'class' => 'rack-gist', 'rack-gist-file' => 'example.pig')
|
54
60
|
end
|
55
61
|
end
|
56
62
|
|
@@ -59,7 +65,7 @@ describe "Rack::Gist" do
|
|
59
65
|
status, headers, body = a.call(mock_env('/none'))
|
60
66
|
status.should == 200
|
61
67
|
headers['Content-Type'].should == 'text/html'
|
62
|
-
body.
|
68
|
+
pbody(body).should_not have_html_tag('link').with('rel' => 'stylesheet', 'href' => 'http://gist.github.com/stylesheets/gist/embed.css')
|
63
69
|
end
|
64
70
|
end
|
65
71
|
|
@@ -68,7 +74,7 @@ describe "Rack::Gist" do
|
|
68
74
|
status, headers, body = a.call(mock_env('/multiple'))
|
69
75
|
status.should == 200
|
70
76
|
headers['Content-Type'].should == 'text/html'
|
71
|
-
body.
|
77
|
+
pbody(body).should have_html_tag('link').with('rel' => 'stylesheet', 'href' => 'http://gist.github.com/stylesheets/gist/embed.css')
|
72
78
|
end
|
73
79
|
end
|
74
80
|
|
@@ -77,7 +83,7 @@ describe "Rack::Gist" do
|
|
77
83
|
status, headers, body = a.call(mock_env)
|
78
84
|
status.should == 200
|
79
85
|
headers['Content-Type'].should == 'text/html'
|
80
|
-
body.
|
86
|
+
pbody(body).should have_html_tag('script[@src*="jquery"]')
|
81
87
|
end
|
82
88
|
end
|
83
89
|
|
@@ -86,7 +92,7 @@ describe "Rack::Gist" do
|
|
86
92
|
status, headers, body = a.call(mock_env)
|
87
93
|
status.should == 200
|
88
94
|
headers['Content-Type'].should == 'text/html'
|
89
|
-
body.
|
95
|
+
pbody(body).should_not have_html_tag('script[@src*="jquery"]')
|
90
96
|
end
|
91
97
|
end
|
92
98
|
|
@@ -95,7 +101,7 @@ describe "Rack::Gist" do
|
|
95
101
|
status, headers, body = a.call(mock_env)
|
96
102
|
status.should == 200
|
97
103
|
headers['Content-Type'].should == 'text/html'
|
98
|
-
body.
|
104
|
+
pbody(body).should have_html_tag('script').containing('CDATA')
|
99
105
|
end
|
100
106
|
end
|
101
107
|
|
@@ -104,7 +110,7 @@ describe "Rack::Gist" do
|
|
104
110
|
status, headers, body = a.call(mock_env)
|
105
111
|
status.should == 200
|
106
112
|
headers['Content-Type'].should == 'text/html'
|
107
|
-
body.
|
113
|
+
pbody(body).should_not have_html_tag('script')
|
108
114
|
end
|
109
115
|
end
|
110
116
|
|
@@ -113,7 +119,7 @@ describe "Rack::Gist" do
|
|
113
119
|
status, headers, body = a.call(mock_env)
|
114
120
|
status.should == 200
|
115
121
|
headers['Content-Type'].should == 'text/html'
|
116
|
-
headers['Content-Length'].should == '
|
122
|
+
headers['Content-Length'].should == '1069'
|
117
123
|
end
|
118
124
|
end
|
119
125
|
|
@@ -122,7 +128,7 @@ describe "Rack::Gist" do
|
|
122
128
|
status, headers, body = a.call(mock_env("/gist.github.com/#{@gist_id}/example.pig.js"))
|
123
129
|
status.should == 200
|
124
130
|
headers['Content-Type'].should == 'application/javascript'
|
125
|
-
body.
|
131
|
+
pbody(body).should == %q{$('#rack-gist-%s[rack-gist-file="example.pig"]').replaceWith('<div id=\"gist-348301\" class=\"gist\">\n \n \n \n \n\n <div class=\"gist-file\">\n <div class=\"gist-data gist-syntax\">\n \n \n \n <div class=\"gist-highlight\"><pre><div class=\'line\' id=\'LC1\'>REGISTER com.darkhax.blog.pig.jar;<\/div><div class=\'line\' id=\'LC2\'>DEFINE Parser com.darkhax.blog.pig.LogParser();<\/div><div class=\'line\' id=\'LC3\'><br/><\/div><div class=\'line\' id=\'LC4\'>logs = LOAD \'apache.log.bz2\' USING TextLoader AS (line: chararray);<\/div><div class=\'line\' id=\'LC5\'>log_events = FOREACH logs GENERATE FLATTEN(Parser(line));<\/div><div class=\'line\' id=\'LC6\'><br/><\/div><div class=\'line\' id=\'LC7\'>by_action = GROUP log_events BY action;<\/div><div class=\'line\' id=\'LC8\'>counts = FOREACH by_action GENERATE group, COUNT(log_events);<\/div><div class=\'line\' id=\'LC9\'>STORE counts INTO \'count_summary\';<\/div><\/pre><\/div>\n \n <\/div>\n\n <div class=\"gist-meta\">\n <a href=\"http://gist.github.com/raw/348301/07d20a92ce5e56bde493066a0154f200da37c953/example.pig\" style=\"float:right;\">view raw<\/a>\n <a href=\"http://gist.github.com/348301#file_example.pig\" style=\"float:right;margin-right:10px;color:#666\">example.pig<\/a>\n <a href=\"http://gist.github.com/348301\">This Gist<\/a> brought to you by <a href=\"http://github.com\">GitHub<\/a>.\n <\/div>\n <\/div>\n \n \n \n<\/div>\n')} % @gist_id
|
126
132
|
end
|
127
133
|
end
|
128
134
|
|
@@ -131,7 +137,7 @@ describe "Rack::Gist" do
|
|
131
137
|
status, headers, body = a.call(mock_env("/gist.github.com/#{@gist_id}.js"))
|
132
138
|
status.should == 200
|
133
139
|
headers['Content-Type'].should == 'application/javascript'
|
134
|
-
body.to_s.should == %q{$('#rack-gist-%s').replaceWith('<div id=\"gist-348301\" class=\"gist\">\n \n \n \n \n\n <div class=\"gist-file\">\n <div class=\"gist-data gist-syntax\">\n \n \n \n <div class=\"gist-highlight\"><pre><div class=\'line\' id=\'LC1\'>REGISTER com.darkhax.blog.pig.jar;<\/div><div class=\'line\' id=\'LC2\'>DEFINE Parser com.darkhax.blog.pig.LogParser();<\/div><div class=\'line\' id=\'LC3\'><br/><\/div><div class=\'line\' id=\'LC4\'>logs = LOAD \'apache.log.bz2\' USING TextLoader AS (line: chararray);<\/div><div class=\'line\' id=\'LC5\'>log_events = FOREACH logs GENERATE FLATTEN(Parser(line));<\/div><div class=\'line\' id=\'LC6\'><br/><\/div><div class=\'line\' id=\'LC7\'>by_action = GROUP log_events BY action;<\/div><div class=\'line\' id=\'LC8\'>counts = FOREACH by_action GENERATE group, COUNT(log_events);<\/div><div class=\'line\' id=\'LC9\'>STORE counts INTO \'count_summary\';<\/div><\/pre><\/div>\n \n <\/div>\n\n <div class=\"gist-meta\">\n <a href=\"http://gist.github.com/raw/348301/07d20a92ce5e56bde493066a0154f200da37c953/example.pig\" style=\"float:right;\">view raw<\/a>\n <a href=\"http://gist.github.com/348301#file_example.pig\" style=\"float:right;margin-right:10px;color:#666\">example.pig<\/a>\n <a href=\"http://gist.github.com/348301\">This Gist<\/a> brought to you by <a href=\"http://github.com\">GitHub<\/a>.\n <\/div>\n <\/div>\n \n \n\n <div class=\"gist-file\">\n <div class=\"gist-data gist-syntax\">\n \n \n \n <div class=\"gist-highlight\"><pre><div class=\'line\' id=\'LC1\'><span class=\"kn\">package<\/span> <span class=\"n\">com<\/span><span class=\"o\">.<\/span><span class=\"na\">codebaby<\/span><span class=\"o\">.<\/span><span class=\"na\">monitor<\/span><span class=\"o\">.<\/span><span class=\"na\">pig<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC2\'><br/><\/div><div class=\'line\' id=\'LC3\'><span class=\"kn\">import<\/span> <span class=\"nn\">java.io.IOException<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC4\'><br/><\/div><div class=\'line\' id=\'LC5\'><span class=\"kn\">import<\/span> <span class=\"nn\">org.apache.pig.EvalFunc<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC6\'><span class=\"kn\">import<\/span> <span class=\"nn\">org.apache.pig.data.DataType<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC7\'><span class=\"kn\">import<\/span> <span class=\"nn\">org.apache.pig.data.Tuple<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC8\'><span class=\"kn\">import<\/span> <span class=\"nn\">org.apache.pig.data.TupleFactory<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC9\'><span class=\"kn\">import<\/span> <span class=\"nn\">org.apache.pig.impl.logicalLayer.schema.Schema<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC10\'><br/><\/div><div class=\'line\' id=\'LC11\'><span class=\"c1\">// Inherit from EvalFunc<Tuple> to implement a EvalFunc that returns a Tuple<\/span><\/div><div class=\'line\' id=\'LC12\'><span class=\"kd\">public<\/span> <span class=\"kd\">class<\/span> <span class=\"nc\">LogParser<\/span> <span class=\"kd\">extends<\/span> <span class=\"n\">EvalFunc<\/span><span class=\"o\"><<\/span><span class=\"n\">Tuple<\/span><span class=\"o\">><\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC13\'><br/><\/div><div class=\'line\' id=\'LC14\'> <span class=\"c1\">// The main method in question. Gets run for every 'thing' that gets sent to<\/span><\/div><div class=\'line\' id=\'LC15\'> <span class=\"c1\">// this UDF<\/span><\/div><div class=\'line\' id=\'LC16\'> <span class=\"kd\">public<\/span> <span class=\"n\">Tuple<\/span> <span class=\"nf\">exec<\/span><span class=\"o\">(<\/span><span class=\"n\">Tuple<\/span> <span class=\"n\">input<\/span><span class=\"o\">)<\/span> <span class=\"kd\">throws<\/span> <span class=\"n\">IOException<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC17\'> <span class=\"k\">if<\/span> <span class=\"o\">(<\/span><span class=\"kc\">null<\/span> <span class=\"o\">==<\/span> <span class=\"n\">input<\/span> <span class=\"o\">||<\/span> <span class=\"n\">input<\/span><span class=\"o\">.<\/span><span class=\"na\">size<\/span><span class=\"o\">()<\/span> <span class=\"o\">!=<\/span> <span class=\"mi\">1<\/span><span class=\"o\">)<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC18\'> <span class=\"k\">return<\/span> <span class=\"kc\">null<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC19\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC20\'> <\/div><div class=\'line\' id=\'LC21\'> <span class=\"n\">String<\/span> <span class=\"n\">line<\/span> <span class=\"o\">=<\/span> <span class=\"o\">(<\/span><span class=\"n\">String<\/span><span class=\"o\">)<\/span> <span class=\"n\">input<\/span><span class=\"o\">.<\/span><span class=\"na\">get<\/span><span class=\"o\">(<\/span><span class=\"mi\">0<\/span><span class=\"o\">);<\/span><\/div><div class=\'line\' id=\'LC22\'> <span class=\"k\">try<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC23\'> <span class=\"c1\">// In Soviet Russia, factory builds you!<\/span><\/div><div class=\'line\' id=\'LC24\'> <span class=\"n\">TupleFactory<\/span> <span class=\"n\">tf<\/span> <span class=\"o\">=<\/span> <span class=\"n\">TupleFactory<\/span><span class=\"o\">.<\/span><span class=\"na\">getInstance<\/span><span class=\"o\">();<\/span><\/div><div class=\'line\' id=\'LC25\'> <span class=\"n\">Tuple<\/span> <span class=\"n\">t<\/span> <span class=\"o\">=<\/span> <span class=\"n\">tf<\/span><span class=\"o\">.<\/span><span class=\"na\">newTuple<\/span><span class=\"o\">();<\/span><\/div><div class=\'line\' id=\'LC26\'><br/><\/div><div class=\'line\' id=\'LC27\'> <span class=\"n\">t<\/span><span class=\"o\">.<\/span><span class=\"na\">append<\/span><span class=\"o\">(<\/span><span class=\"n\">getHttpMethod<\/span><span class=\"o\">());<\/span><\/div><div class=\'line\' id=\'LC28\'> <span class=\"n\">t<\/span><span class=\"o\">.<\/span><span class=\"na\">append<\/span><span class=\"o\">(<\/span><span class=\"n\">getIP<\/span><span class=\"o\">());<\/span><\/div><div class=\'line\' id=\'LC29\'> <span class=\"n\">t<\/span><span class=\"o\">.<\/span><span class=\"na\">append<\/span><span class=\"o\">(<\/span><span class=\"n\">getDate<\/span><span class=\"o\">());<\/span><\/div><div class=\'line\' id=\'LC30\'><br/><\/div><div class=\'line\' id=\'LC31\'> <span class=\"c1\">// The tuple we are returning now has 3 elements, all strings.<\/span><\/div><div class=\'line\' id=\'LC32\'> <span class=\"c1\">// In order, they are the HTTP method, the IP address, and the date.<\/span><\/div><div class=\'line\' id=\'LC33\'><br/><\/div><div class=\'line\' id=\'LC34\'> <span class=\"k\">return<\/span> <span class=\"n\">t<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC35\'> <span class=\"o\">}<\/span> <span class=\"k\">catch<\/span> <span class=\"o\">(<\/span><span class=\"n\">Exception<\/span> <span class=\"n\">e<\/span><span class=\"o\">)<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC36\'> <span class=\"c1\">// Any problems? Just return null and this one doesn't get<\/span><\/div><div class=\'line\' id=\'LC37\'> <span class=\"c1\">// 'generated' by pig<\/span><\/div><div class=\'line\' id=\'LC38\'> <span class=\"k\">return<\/span> <span class=\"kc\">null<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC39\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC40\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC41\'><br/><\/div><div class=\'line\' id=\'LC42\'> <span class=\"kd\">public<\/span> <span class=\"n\">Schema<\/span> <span class=\"nf\">outputSchema<\/span><span class=\"o\">(<\/span><span class=\"n\">Schema<\/span> <span class=\"n\">input<\/span><span class=\"o\">)<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC43\'> <span class=\"k\">try<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC44\'> <span class=\"n\">Schema<\/span> <span class=\"n\">s<\/span> <span class=\"o\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">Schema<\/span><span class=\"o\">();<\/span><\/div><div class=\'line\' id=\'LC45\'><br/><\/div><div class=\'line\' id=\'LC46\'> <span class=\"n\">s<\/span><span class=\"o\">.<\/span><span class=\"na\">add<\/span><span class=\"o\">(<\/span><span class=\"k\">new<\/span> <span class=\"n\">Schema<\/span><span class=\"o\">.<\/span><span class=\"na\">FieldSchema<\/span><span class=\"o\">(<\/span><span class=\"s\">\"action\"<\/span><span class=\"o\">,<\/span> <span class=\"n\">DataType<\/span><span class=\"o\">.<\/span><span class=\"na\">CHARARRAY<\/span><span class=\"o\">));<\/span><\/div><div class=\'line\' id=\'LC47\'> <span class=\"n\">s<\/span><span class=\"o\">.<\/span><span class=\"na\">add<\/span><span class=\"o\">(<\/span><span class=\"k\">new<\/span> <span class=\"n\">Schema<\/span><span class=\"o\">.<\/span><span class=\"na\">FieldSchema<\/span><span class=\"o\">(<\/span><span class=\"s\">\"ip\"<\/span><span class=\"o\">,<\/span> <span class=\"n\">DataType<\/span><span class=\"o\">.<\/span><span class=\"na\">CHARARRAY<\/span><span class=\"o\">));<\/span><\/div><div class=\'line\' id=\'LC48\'> <span class=\"n\">s<\/span><span class=\"o\">.<\/span><span class=\"na\">add<\/span><span class=\"o\">(<\/span><span class=\"k\">new<\/span> <span class=\"n\">Schema<\/span><span class=\"o\">.<\/span><span class=\"na\">FieldSchema<\/span><span class=\"o\">(<\/span><span class=\"s\">\"date\"<\/span><span class=\"o\">,<\/span> <span class=\"n\">DataType<\/span><span class=\"o\">.<\/span><span class=\"na\">CHARARRAY<\/span><span class=\"o\">));<\/span><\/div><div class=\'line\' id=\'LC49\'><br/><\/div><div class=\'line\' id=\'LC50\'> <span class=\"k\">return<\/span> <span class=\"n\">s<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC51\'> <span class=\"o\">}<\/span> <span class=\"k\">catch<\/span> <span class=\"o\">(<\/span><span class=\"n\">Exception<\/span> <span class=\"n\">e<\/span><span class=\"o\">)<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC52\'> <span class=\"c1\">// Any problems? Just return null...there probably won't be any<\/span><\/div><div class=\'line\' id=\'LC53\'> <span class=\"c1\">// problems though.<\/span><\/div><div class=\'line\' id=\'LC54\'> <span class=\"k\">return<\/span> <span class=\"kc\">null<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC55\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC56\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC57\'><br/><\/div><div class=\'line\' id=\'LC58\'> <span class=\"kd\">public<\/span> <span class=\"n\">String<\/span> <span class=\"nf\">getHttpMethod<\/span><span class=\"o\">()<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC59\'> <span class=\"k\">return<\/span> <span class=\"s\">\"\"<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC60\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC61\'><br/><\/div><div class=\'line\' id=\'LC62\'> <span class=\"kd\">public<\/span> <span class=\"n\">String<\/span> <span class=\"nf\">getIP<\/span><span class=\"o\">()<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC63\'> <span class=\"k\">return<\/span> <span class=\"s\">\"\"<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC64\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC65\'><br/><\/div><div class=\'line\' id=\'LC66\'> <span class=\"kd\">public<\/span> <span class=\"n\">String<\/span> <span class=\"nf\">getDate<\/span><span class=\"o\">()<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC67\'> <span class=\"k\">return<\/span> <span class=\"s\">\"\"<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC68\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC69\'><span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC70\'><br/><\/div><\/pre><\/div>\n \n <\/div>\n\n <div class=\"gist-meta\">\n <a href=\"http://gist.github.com/raw/348301/f249e58fe0fc9897e8d575764ecabf153d2da683/LogParser.java\" style=\"float:right;\">view raw<\/a>\n <a href=\"http://gist.github.com/348301#file_log_parser.java\" style=\"float:right;margin-right:10px;color:#666\">LogParser.java<\/a>\n <a href=\"http://gist.github.com/348301\">This Gist<\/a> brought to you by <a href=\"http://github.com\">GitHub<\/a>.\n <\/div>\n <\/div>\n \n \n<\/div>\n')} % @gist_id
|
140
|
+
pbody(body).should == %q{$('#rack-gist-%s').replaceWith('<div id=\"gist-348301\" class=\"gist\">\n \n \n \n \n\n <div class=\"gist-file\">\n <div class=\"gist-data gist-syntax\">\n \n \n \n <div class=\"gist-highlight\"><pre><div class=\'line\' id=\'LC1\'>REGISTER com.darkhax.blog.pig.jar;<\/div><div class=\'line\' id=\'LC2\'>DEFINE Parser com.darkhax.blog.pig.LogParser();<\/div><div class=\'line\' id=\'LC3\'><br/><\/div><div class=\'line\' id=\'LC4\'>logs = LOAD \'apache.log.bz2\' USING TextLoader AS (line: chararray);<\/div><div class=\'line\' id=\'LC5\'>log_events = FOREACH logs GENERATE FLATTEN(Parser(line));<\/div><div class=\'line\' id=\'LC6\'><br/><\/div><div class=\'line\' id=\'LC7\'>by_action = GROUP log_events BY action;<\/div><div class=\'line\' id=\'LC8\'>counts = FOREACH by_action GENERATE group, COUNT(log_events);<\/div><div class=\'line\' id=\'LC9\'>STORE counts INTO \'count_summary\';<\/div><\/pre><\/div>\n \n <\/div>\n\n <div class=\"gist-meta\">\n <a href=\"http://gist.github.com/raw/348301/07d20a92ce5e56bde493066a0154f200da37c953/example.pig\" style=\"float:right;\">view raw<\/a>\n <a href=\"http://gist.github.com/348301#file_example.pig\" style=\"float:right;margin-right:10px;color:#666\">example.pig<\/a>\n <a href=\"http://gist.github.com/348301\">This Gist<\/a> brought to you by <a href=\"http://github.com\">GitHub<\/a>.\n <\/div>\n <\/div>\n \n \n\n <div class=\"gist-file\">\n <div class=\"gist-data gist-syntax\">\n \n \n \n <div class=\"gist-highlight\"><pre><div class=\'line\' id=\'LC1\'><span class=\"kn\">package<\/span> <span class=\"n\">com<\/span><span class=\"o\">.<\/span><span class=\"na\">codebaby<\/span><span class=\"o\">.<\/span><span class=\"na\">monitor<\/span><span class=\"o\">.<\/span><span class=\"na\">pig<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC2\'><br/><\/div><div class=\'line\' id=\'LC3\'><span class=\"kn\">import<\/span> <span class=\"nn\">java.io.IOException<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC4\'><br/><\/div><div class=\'line\' id=\'LC5\'><span class=\"kn\">import<\/span> <span class=\"nn\">org.apache.pig.EvalFunc<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC6\'><span class=\"kn\">import<\/span> <span class=\"nn\">org.apache.pig.data.DataType<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC7\'><span class=\"kn\">import<\/span> <span class=\"nn\">org.apache.pig.data.Tuple<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC8\'><span class=\"kn\">import<\/span> <span class=\"nn\">org.apache.pig.data.TupleFactory<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC9\'><span class=\"kn\">import<\/span> <span class=\"nn\">org.apache.pig.impl.logicalLayer.schema.Schema<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC10\'><br/><\/div><div class=\'line\' id=\'LC11\'><span class=\"c1\">// Inherit from EvalFunc<Tuple> to implement a EvalFunc that returns a Tuple<\/span><\/div><div class=\'line\' id=\'LC12\'><span class=\"kd\">public<\/span> <span class=\"kd\">class<\/span> <span class=\"nc\">LogParser<\/span> <span class=\"kd\">extends<\/span> <span class=\"n\">EvalFunc<\/span><span class=\"o\"><<\/span><span class=\"n\">Tuple<\/span><span class=\"o\">><\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC13\'><br/><\/div><div class=\'line\' id=\'LC14\'> <span class=\"c1\">// The main method in question. Gets run for every 'thing' that gets sent to<\/span><\/div><div class=\'line\' id=\'LC15\'> <span class=\"c1\">// this UDF<\/span><\/div><div class=\'line\' id=\'LC16\'> <span class=\"kd\">public<\/span> <span class=\"n\">Tuple<\/span> <span class=\"nf\">exec<\/span><span class=\"o\">(<\/span><span class=\"n\">Tuple<\/span> <span class=\"n\">input<\/span><span class=\"o\">)<\/span> <span class=\"kd\">throws<\/span> <span class=\"n\">IOException<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC17\'> <span class=\"k\">if<\/span> <span class=\"o\">(<\/span><span class=\"kc\">null<\/span> <span class=\"o\">==<\/span> <span class=\"n\">input<\/span> <span class=\"o\">||<\/span> <span class=\"n\">input<\/span><span class=\"o\">.<\/span><span class=\"na\">size<\/span><span class=\"o\">()<\/span> <span class=\"o\">!=<\/span> <span class=\"mi\">1<\/span><span class=\"o\">)<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC18\'> <span class=\"k\">return<\/span> <span class=\"kc\">null<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC19\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC20\'> <\/div><div class=\'line\' id=\'LC21\'> <span class=\"n\">String<\/span> <span class=\"n\">line<\/span> <span class=\"o\">=<\/span> <span class=\"o\">(<\/span><span class=\"n\">String<\/span><span class=\"o\">)<\/span> <span class=\"n\">input<\/span><span class=\"o\">.<\/span><span class=\"na\">get<\/span><span class=\"o\">(<\/span><span class=\"mi\">0<\/span><span class=\"o\">);<\/span><\/div><div class=\'line\' id=\'LC22\'> <span class=\"k\">try<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC23\'> <span class=\"c1\">// In Soviet Russia, factory builds you!<\/span><\/div><div class=\'line\' id=\'LC24\'> <span class=\"n\">TupleFactory<\/span> <span class=\"n\">tf<\/span> <span class=\"o\">=<\/span> <span class=\"n\">TupleFactory<\/span><span class=\"o\">.<\/span><span class=\"na\">getInstance<\/span><span class=\"o\">();<\/span><\/div><div class=\'line\' id=\'LC25\'> <span class=\"n\">Tuple<\/span> <span class=\"n\">t<\/span> <span class=\"o\">=<\/span> <span class=\"n\">tf<\/span><span class=\"o\">.<\/span><span class=\"na\">newTuple<\/span><span class=\"o\">();<\/span><\/div><div class=\'line\' id=\'LC26\'><br/><\/div><div class=\'line\' id=\'LC27\'> <span class=\"n\">t<\/span><span class=\"o\">.<\/span><span class=\"na\">append<\/span><span class=\"o\">(<\/span><span class=\"n\">getHttpMethod<\/span><span class=\"o\">());<\/span><\/div><div class=\'line\' id=\'LC28\'> <span class=\"n\">t<\/span><span class=\"o\">.<\/span><span class=\"na\">append<\/span><span class=\"o\">(<\/span><span class=\"n\">getIP<\/span><span class=\"o\">());<\/span><\/div><div class=\'line\' id=\'LC29\'> <span class=\"n\">t<\/span><span class=\"o\">.<\/span><span class=\"na\">append<\/span><span class=\"o\">(<\/span><span class=\"n\">getDate<\/span><span class=\"o\">());<\/span><\/div><div class=\'line\' id=\'LC30\'><br/><\/div><div class=\'line\' id=\'LC31\'> <span class=\"c1\">// The tuple we are returning now has 3 elements, all strings.<\/span><\/div><div class=\'line\' id=\'LC32\'> <span class=\"c1\">// In order, they are the HTTP method, the IP address, and the date.<\/span><\/div><div class=\'line\' id=\'LC33\'><br/><\/div><div class=\'line\' id=\'LC34\'> <span class=\"k\">return<\/span> <span class=\"n\">t<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC35\'> <span class=\"o\">}<\/span> <span class=\"k\">catch<\/span> <span class=\"o\">(<\/span><span class=\"n\">Exception<\/span> <span class=\"n\">e<\/span><span class=\"o\">)<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC36\'> <span class=\"c1\">// Any problems? Just return null and this one doesn't get<\/span><\/div><div class=\'line\' id=\'LC37\'> <span class=\"c1\">// 'generated' by pig<\/span><\/div><div class=\'line\' id=\'LC38\'> <span class=\"k\">return<\/span> <span class=\"kc\">null<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC39\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC40\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC41\'><br/><\/div><div class=\'line\' id=\'LC42\'> <span class=\"kd\">public<\/span> <span class=\"n\">Schema<\/span> <span class=\"nf\">outputSchema<\/span><span class=\"o\">(<\/span><span class=\"n\">Schema<\/span> <span class=\"n\">input<\/span><span class=\"o\">)<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC43\'> <span class=\"k\">try<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC44\'> <span class=\"n\">Schema<\/span> <span class=\"n\">s<\/span> <span class=\"o\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">Schema<\/span><span class=\"o\">();<\/span><\/div><div class=\'line\' id=\'LC45\'><br/><\/div><div class=\'line\' id=\'LC46\'> <span class=\"n\">s<\/span><span class=\"o\">.<\/span><span class=\"na\">add<\/span><span class=\"o\">(<\/span><span class=\"k\">new<\/span> <span class=\"n\">Schema<\/span><span class=\"o\">.<\/span><span class=\"na\">FieldSchema<\/span><span class=\"o\">(<\/span><span class=\"s\">\"action\"<\/span><span class=\"o\">,<\/span> <span class=\"n\">DataType<\/span><span class=\"o\">.<\/span><span class=\"na\">CHARARRAY<\/span><span class=\"o\">));<\/span><\/div><div class=\'line\' id=\'LC47\'> <span class=\"n\">s<\/span><span class=\"o\">.<\/span><span class=\"na\">add<\/span><span class=\"o\">(<\/span><span class=\"k\">new<\/span> <span class=\"n\">Schema<\/span><span class=\"o\">.<\/span><span class=\"na\">FieldSchema<\/span><span class=\"o\">(<\/span><span class=\"s\">\"ip\"<\/span><span class=\"o\">,<\/span> <span class=\"n\">DataType<\/span><span class=\"o\">.<\/span><span class=\"na\">CHARARRAY<\/span><span class=\"o\">));<\/span><\/div><div class=\'line\' id=\'LC48\'> <span class=\"n\">s<\/span><span class=\"o\">.<\/span><span class=\"na\">add<\/span><span class=\"o\">(<\/span><span class=\"k\">new<\/span> <span class=\"n\">Schema<\/span><span class=\"o\">.<\/span><span class=\"na\">FieldSchema<\/span><span class=\"o\">(<\/span><span class=\"s\">\"date\"<\/span><span class=\"o\">,<\/span> <span class=\"n\">DataType<\/span><span class=\"o\">.<\/span><span class=\"na\">CHARARRAY<\/span><span class=\"o\">));<\/span><\/div><div class=\'line\' id=\'LC49\'><br/><\/div><div class=\'line\' id=\'LC50\'> <span class=\"k\">return<\/span> <span class=\"n\">s<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC51\'> <span class=\"o\">}<\/span> <span class=\"k\">catch<\/span> <span class=\"o\">(<\/span><span class=\"n\">Exception<\/span> <span class=\"n\">e<\/span><span class=\"o\">)<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC52\'> <span class=\"c1\">// Any problems? Just return null...there probably won't be any<\/span><\/div><div class=\'line\' id=\'LC53\'> <span class=\"c1\">// problems though.<\/span><\/div><div class=\'line\' id=\'LC54\'> <span class=\"k\">return<\/span> <span class=\"kc\">null<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC55\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC56\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC57\'><br/><\/div><div class=\'line\' id=\'LC58\'> <span class=\"kd\">public<\/span> <span class=\"n\">String<\/span> <span class=\"nf\">getHttpMethod<\/span><span class=\"o\">()<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC59\'> <span class=\"k\">return<\/span> <span class=\"s\">\"\"<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC60\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC61\'><br/><\/div><div class=\'line\' id=\'LC62\'> <span class=\"kd\">public<\/span> <span class=\"n\">String<\/span> <span class=\"nf\">getIP<\/span><span class=\"o\">()<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC63\'> <span class=\"k\">return<\/span> <span class=\"s\">\"\"<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC64\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC65\'><br/><\/div><div class=\'line\' id=\'LC66\'> <span class=\"kd\">public<\/span> <span class=\"n\">String<\/span> <span class=\"nf\">getDate<\/span><span class=\"o\">()<\/span> <span class=\"o\">{<\/span><\/div><div class=\'line\' id=\'LC67\'> <span class=\"k\">return<\/span> <span class=\"s\">\"\"<\/span><span class=\"o\">;<\/span><\/div><div class=\'line\' id=\'LC68\'> <span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC69\'><span class=\"o\">}<\/span><\/div><div class=\'line\' id=\'LC70\'><br/><\/div><\/pre><\/div>\n \n <\/div>\n\n <div class=\"gist-meta\">\n <a href=\"http://gist.github.com/raw/348301/f249e58fe0fc9897e8d575764ecabf153d2da683/LogParser.java\" style=\"float:right;\">view raw<\/a>\n <a href=\"http://gist.github.com/348301#file_log_parser.java\" style=\"float:right;margin-right:10px;color:#666\">LogParser.java<\/a>\n <a href=\"http://gist.github.com/348301\">This Gist<\/a> brought to you by <a href=\"http://github.com\">GitHub<\/a>.\n <\/div>\n <\/div>\n \n \n<\/div>\n')} % @gist_id
|
135
141
|
end
|
136
142
|
end
|
137
143
|
|
@@ -143,12 +149,12 @@ describe "Rack::Gist" do
|
|
143
149
|
headers['Content-Type'].should == 'application/javascript'
|
144
150
|
|
145
151
|
RestClient.should_not_receive(:get)
|
146
|
-
cache.should_receive(:fetch).once.with("rack-gist:#{@gist_id}:example.pig", :expires_in => 3600).and_return(body) # 1.hour
|
152
|
+
cache.should_receive(:fetch).once.with("rack-gist:#{@gist_id}:example.pig", :expires_in => 3600).and_return(pbody(body)) # 1.hour
|
147
153
|
|
148
154
|
status, headers, body2 = a.call(mock_env("/gist.github.com/#{@gist_id}/example.pig.js"))
|
149
155
|
status.should == 200
|
150
156
|
headers['Content-Type'].should == 'application/javascript'
|
151
|
-
body.should == body2
|
157
|
+
pbody(body).should == pbody(body2)
|
152
158
|
end
|
153
159
|
end
|
154
160
|
|
@@ -160,12 +166,12 @@ describe "Rack::Gist" do
|
|
160
166
|
headers['Content-Type'].should == 'application/javascript'
|
161
167
|
|
162
168
|
RestClient.should_not_receive(:get)
|
163
|
-
cache.should_receive(:fetch).once.with("rack-gist:#{@gist_id}:example.pig", :expires_in => 60).and_return(body) # 1.hour
|
169
|
+
cache.should_receive(:fetch).once.with("rack-gist:#{@gist_id}:example.pig", :expires_in => 60).and_return(pbody(body)) # 1.hour
|
164
170
|
|
165
171
|
status, headers, body2 = a.call(mock_env("/gist.github.com/#{@gist_id}/example.pig.js"))
|
166
172
|
status.should == 200
|
167
173
|
headers['Content-Type'].should == 'application/javascript'
|
168
|
-
body.should == body2
|
174
|
+
pbody(body).should == pbody(body2)
|
169
175
|
end
|
170
176
|
end
|
171
177
|
|
data/spec/spec_helper.rb
CHANGED
@@ -25,8 +25,6 @@ FakeWeb.allow_net_connect = false
|
|
25
25
|
FakeWeb.register_uri(:get, 'http://gist.github.com/348301.js', :body => File.read(File.join(File.dirname(__FILE__), 'full-gist.js')), :content_type => 'text/javascript; charset=utf-8')
|
26
26
|
FakeWeb.register_uri(:get, 'http://gist.github.com/348301.js?file=example.pig', :body => File.read(File.join(File.dirname(__FILE__), 'partial-gist.js')), :content_type => 'text/javascript; charset=utf-8')
|
27
27
|
|
28
|
-
require 'hpricot'
|
29
|
-
|
30
28
|
Spec::Matchers.define :have_html_tag do |tag|
|
31
29
|
chain :count do |count|
|
32
30
|
@count = count
|
@@ -44,7 +42,7 @@ Spec::Matchers.define :have_html_tag do |tag|
|
|
44
42
|
@count ||= 1
|
45
43
|
@contents ||= {}
|
46
44
|
@inner ||= //
|
47
|
-
doc =
|
45
|
+
doc = Nokogiri(doc)
|
48
46
|
doc.search(tag).tap do |results|
|
49
47
|
results.size.should == @count
|
50
48
|
results.each do |node|
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-gist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 19
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 1
|
8
7
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
8
|
+
- 1
|
9
|
+
version: 1.1.1
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Daniel Huckstep
|
@@ -15,136 +14,130 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-10 00:00:00 -06:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
|
-
prerelease: false
|
23
|
-
type: :runtime
|
24
21
|
name: nokogiri
|
25
|
-
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
23
|
none: false
|
27
24
|
requirements:
|
28
25
|
- - ~>
|
29
26
|
- !ruby/object:Gem::Version
|
30
|
-
hash: 113
|
31
27
|
segments:
|
32
28
|
- 1
|
33
29
|
- 4
|
34
30
|
- 3
|
35
31
|
- 1
|
36
32
|
version: 1.4.3.1
|
37
|
-
requirement: *id001
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
prerelease: false
|
40
33
|
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
41
37
|
name: rest-client
|
42
|
-
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
43
39
|
none: false
|
44
40
|
requirements:
|
45
41
|
- - ~>
|
46
42
|
- !ruby/object:Gem::Version
|
47
|
-
hash: 15
|
48
43
|
segments:
|
49
44
|
- 1
|
50
45
|
- 6
|
51
46
|
- 0
|
52
47
|
version: 1.6.0
|
53
|
-
|
54
|
-
- !ruby/object:Gem::Dependency
|
48
|
+
type: :runtime
|
55
49
|
prerelease: false
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: jeweler
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 1
|
60
|
+
- 4
|
61
|
+
- 0
|
62
|
+
version: 1.4.0
|
56
63
|
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
57
67
|
name: fakeweb
|
58
|
-
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
59
69
|
none: false
|
60
70
|
requirements:
|
61
71
|
- - ~>
|
62
72
|
- !ruby/object:Gem::Version
|
63
|
-
hash: 15
|
64
73
|
segments:
|
65
74
|
- 1
|
66
75
|
- 2
|
67
76
|
- 8
|
68
77
|
version: 1.2.8
|
69
|
-
requirement: *id003
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
prerelease: false
|
72
78
|
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
73
82
|
name: rspec
|
74
|
-
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
75
84
|
none: false
|
76
85
|
requirements:
|
77
86
|
- - ~>
|
78
87
|
- !ruby/object:Gem::Version
|
79
|
-
hash: 27
|
80
88
|
segments:
|
81
89
|
- 1
|
82
90
|
- 3
|
83
91
|
- 0
|
84
92
|
version: 1.3.0
|
85
|
-
requirement: *id004
|
86
|
-
- !ruby/object:Gem::Dependency
|
87
|
-
prerelease: false
|
88
93
|
type: :development
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: *id005
|
96
|
+
- !ruby/object:Gem::Dependency
|
89
97
|
name: yard
|
90
|
-
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
91
99
|
none: false
|
92
100
|
requirements:
|
93
101
|
- - ~>
|
94
102
|
- !ruby/object:Gem::Version
|
95
|
-
hash: 27
|
96
103
|
segments:
|
97
104
|
- 0
|
98
105
|
- 5
|
99
106
|
- 8
|
100
107
|
version: 0.5.8
|
101
|
-
requirement: *id005
|
102
|
-
- !ruby/object:Gem::Dependency
|
103
|
-
prerelease: false
|
104
108
|
type: :development
|
109
|
+
prerelease: false
|
110
|
+
version_requirements: *id006
|
111
|
+
- !ruby/object:Gem::Dependency
|
105
112
|
name: rack
|
106
|
-
|
113
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
107
114
|
none: false
|
108
115
|
requirements:
|
109
116
|
- - ~>
|
110
117
|
- !ruby/object:Gem::Version
|
111
|
-
hash: 29
|
112
118
|
segments:
|
113
119
|
- 1
|
114
120
|
- 2
|
115
121
|
- 1
|
116
122
|
version: 1.2.1
|
117
|
-
requirement: *id006
|
118
|
-
- !ruby/object:Gem::Dependency
|
119
|
-
prerelease: false
|
120
123
|
type: :development
|
124
|
+
prerelease: false
|
125
|
+
version_requirements: *id007
|
126
|
+
- !ruby/object:Gem::Dependency
|
121
127
|
name: activesupport
|
122
|
-
|
128
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
123
129
|
none: false
|
124
130
|
requirements:
|
125
131
|
- - ~>
|
126
132
|
- !ruby/object:Gem::Version
|
127
|
-
hash: 19
|
128
133
|
segments:
|
129
134
|
- 2
|
130
135
|
- 3
|
131
136
|
- 8
|
132
137
|
version: 2.3.8
|
133
|
-
requirement: *id007
|
134
|
-
- !ruby/object:Gem::Dependency
|
135
|
-
prerelease: false
|
136
138
|
type: :development
|
137
|
-
|
138
|
-
version_requirements:
|
139
|
-
none: false
|
140
|
-
requirements:
|
141
|
-
- - ">="
|
142
|
-
- !ruby/object:Gem::Version
|
143
|
-
hash: 3
|
144
|
-
segments:
|
145
|
-
- 0
|
146
|
-
version: "0"
|
147
|
-
requirement: *id008
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: *id008
|
148
141
|
description: Load gists in the background. KTHXBYE!
|
149
142
|
email: darkhelmet@darkhelmetlive.com
|
150
143
|
executables: []
|
@@ -158,6 +151,7 @@ files:
|
|
158
151
|
- .document
|
159
152
|
- .gitignore
|
160
153
|
- Gemfile
|
154
|
+
- Gemfile.lock
|
161
155
|
- LICENSE
|
162
156
|
- README.rdoc
|
163
157
|
- Rakefile
|
@@ -187,7 +181,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
187
181
|
requirements:
|
188
182
|
- - ">="
|
189
183
|
- !ruby/object:Gem::Version
|
190
|
-
hash: 3
|
191
184
|
segments:
|
192
185
|
- 0
|
193
186
|
version: "0"
|
@@ -196,7 +189,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
189
|
requirements:
|
197
190
|
- - ">="
|
198
191
|
- !ruby/object:Gem::Version
|
199
|
-
hash: 3
|
200
192
|
segments:
|
201
193
|
- 0
|
202
194
|
version: "0"
|