haml_interceptor 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{haml_interceptor}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Scofield"]
@@ -6,10 +6,15 @@ class HamlInterceptor
6
6
  end
7
7
 
8
8
  def call(env)
9
- status, headers, body = @app.call(env)
10
- if headers.has_key?('Content-Type') && headers['Content-Type'] =~ /javascript/
11
- body = Haml::HTML.new(body.body.join).render
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 test_it_should_capture_js_responses
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.2.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: -1861882101416818593
141
+ hash: -1072519243524474088
142
142
  segments:
143
143
  - 0
144
144
  version: "0"