haml_interceptor 0.2.0 → 0.3.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/VERSION +1 -1
- data/haml_interceptor.gemspec +1 -1
- data/lib/haml_interceptor.rb +8 -3
- data/test/test_haml_interceptor.rb +12 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/haml_interceptor.gemspec
CHANGED
data/lib/haml_interceptor.rb
CHANGED
@@ -6,10 +6,15 @@ class HamlInterceptor
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def call(env)
|
9
|
-
status, headers,
|
10
|
-
|
11
|
-
|
9
|
+
status, headers, resp = @app.call(env)
|
10
|
+
body = resp.body.respond_to?(:join) ? resp.body.join : resp.body
|
11
|
+
if js_response?(env, headers)
|
12
|
+
body = Haml::HTML.new(body).render
|
12
13
|
end
|
13
14
|
[status, headers, body]
|
14
15
|
end
|
16
|
+
|
17
|
+
def js_response?(env, headers)
|
18
|
+
env['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' || (headers.has_key?('Content-Type') && headers['Content-Type'] =~ /javascript/)
|
19
|
+
end
|
15
20
|
end
|
@@ -13,12 +13,23 @@ class TestHamlInterceptor < Test::Unit::TestCase
|
|
13
13
|
assert_equal last_response.body, '<html><head><title>Boneshaker</title></head><body><p>Hello!</p></body></html>'
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def test_it_should_capture_js_responses_by_content_type
|
17
17
|
get '/ajax'
|
18
18
|
assert_equal last_response.body, <<HAML
|
19
19
|
%h1 Boneshaker
|
20
20
|
#author
|
21
21
|
%p by Cherie Priest
|
22
|
+
HAML
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_it_should_capture_js_responses_by_requested_header
|
26
|
+
get '/', {}, {'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'}
|
27
|
+
assert_equal last_response.body, <<HAML
|
28
|
+
%html
|
29
|
+
%head
|
30
|
+
%title Boneshaker
|
31
|
+
%body
|
32
|
+
%p Hello!
|
22
33
|
HAML
|
23
34
|
end
|
24
35
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: haml_interceptor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ben Scofield
|
@@ -138,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
138
|
requirements:
|
139
139
|
- - ">="
|
140
140
|
- !ruby/object:Gem::Version
|
141
|
-
hash: -
|
141
|
+
hash: -1072519243524474088
|
142
142
|
segments:
|
143
143
|
- 0
|
144
144
|
version: "0"
|