jrb 0.1.1 → 0.2.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.
@@ -1,9 +1,12 @@
1
1
  module JRB
2
2
  module Rails
3
3
  class TemplateHandler
4
+ HTML_MIME_TYPES = ["text/html", "application/xhtml+xml"]
5
+
4
6
  class << self
5
7
  def call(template)
6
- tilt_template = JRB::Template.new(template.identifier) { template.source }
8
+ auto_escape = HTML_MIME_TYPES.include? template.mime_type
9
+ tilt_template = JRB::Template.new(template.identifier, 1, :escape_html => auto_escape) { template.source }
7
10
  tilt_template.send(:precompiled, {}).first
8
11
  end
9
12
  end
@@ -1,3 +1,3 @@
1
1
  module JRB
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -9,10 +9,20 @@ class ActionViewTest < ActionController::TestCase
9
9
  assert_equal "<html><head></head><body>Hello John!</body></html>", response.body
10
10
  end
11
11
 
12
- test "escaping html characters" do
12
+ test "escaping html characters in html templates" do
13
13
  get :index, :name => "<script>unsafe</script>"
14
14
  assert_equal "<html><head></head><body>Hello &lt;script&gt;unsafe&lt;/script&gt;!</body></html>", response.body
15
15
  end
16
+
17
+ test "not escaping html characters in xml templates" do
18
+ get :index, :name => "<script>unsafe</script>", :format => :xml
19
+ assert_equal "<greeting>Hello &lt;script&gt;unsafe&lt;/script&gt;!</greeting>", response.body
20
+ end
21
+
22
+ test "not escaping html characters in json templates" do
23
+ get :index, :name => "<script>safe</script>", :format => :json
24
+ assert_equal '{"greeting":"Hello <script>safe</script>!"}', response.body
25
+ end
16
26
 
17
27
  test "capturing content" do
18
28
  get :capture, :name => "John"
@@ -0,0 +1 @@
1
+ { :greeting => "Hello #{params[:name]}!" }.to_json
@@ -0,0 +1,5 @@
1
+ require "builder"
2
+
3
+ xml = Builder::XmlMarkup.new
4
+ xml.greeting "Hello #{params[:name]}!"
5
+ xml.target!
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jrb
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rolf Timmermans
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-25 00:00:00 Z
13
+ date: 2011-06-07 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: tilt
@@ -61,6 +61,8 @@ files:
61
61
  - test/dummy/app/views/layouts/test.html.rb
62
62
  - test/dummy/app/views/test/capture.html.rb
63
63
  - test/dummy/app/views/test/index.html.rb
64
+ - test/dummy/app/views/test/index.json.rb
65
+ - test/dummy/app/views/test/index.xml.rb
64
66
  - test/dummy/config.ru
65
67
  - test/dummy/config/application.rb
66
68
  - test/dummy/config/boot.rb
@@ -102,6 +104,8 @@ test_files:
102
104
  - test/dummy/app/views/layouts/test.html.rb
103
105
  - test/dummy/app/views/test/capture.html.rb
104
106
  - test/dummy/app/views/test/index.html.rb
107
+ - test/dummy/app/views/test/index.json.rb
108
+ - test/dummy/app/views/test/index.xml.rb
105
109
  - test/dummy/config.ru
106
110
  - test/dummy/config/application.rb
107
111
  - test/dummy/config/boot.rb