tilt-jbuilder 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/Gemfile +1 -0
- data/lib/sinatra/jbuilder.rb +2 -2
- data/lib/tilt/jbuilder.rb +7 -18
- data/spec/sinatra_integration_spec.rb +1 -47
- data/spec/sinatra_json_integration_spec.rb +7 -0
- data/spec/support/sinatra_integration_tests.rb +49 -0
- data/spec/tilt-jbuilder_spec.rb +5 -2
- data/tilt-jbuilder.gemspec +2 -2
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b283dedad1f47c0b518b44f20cf770ec0fc1b35
|
4
|
+
data.tar.gz: b2cb848c88cb66bada087b062734ec331b70fd32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a732b210b1a5251282b5a52916f9aea1aba0e3b8da43cc563c3839d2bca468add1ea90985ae08a3c0c116b2a14ad3f5e984714d7ed52f6ef19c25838f5c1d50
|
7
|
+
data.tar.gz: 36358ed4e79ec48d5cfd19277a51e068258f192c8a063a29afc49a39286bc85ca9e41853df812f558044a36ac3d4a6bf1064c1c865d24c6bb0906f6bd18f3b5e
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/lib/sinatra/jbuilder.rb
CHANGED
@@ -4,13 +4,13 @@ require "sinatra/base"
|
|
4
4
|
module Sinatra
|
5
5
|
module Templates
|
6
6
|
def jbuilder(template, options={}, locals={})
|
7
|
+
options[:default_content_type] = :json
|
7
8
|
render :jbuilder, template, options, locals
|
8
9
|
end
|
9
10
|
|
10
11
|
def render_with_view_path_support(engine, data, options = {}, locals = {}, &block)
|
11
12
|
# Same as `views` extraction in the original method.
|
12
|
-
options[:view_path] = options[:views] || settings.views || "./views"
|
13
|
-
if engine.to_s.downcase == "jbuilder"
|
13
|
+
options[:view_path] = options[:views] || settings.views || "./views" if engine.to_s.downcase == "jbuilder"
|
14
14
|
render_without_view_path_support(engine, data, options, locals, &block)
|
15
15
|
end
|
16
16
|
alias_method :render_without_view_path_support, :render
|
data/lib/tilt/jbuilder.rb
CHANGED
@@ -43,26 +43,15 @@ module Tilt
|
|
43
43
|
|
44
44
|
def evaluate(scope, locals, &block)
|
45
45
|
scope ||= Object.new
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
if @_tilt_data.kind_of? Proc
|
52
|
-
return @_tilt_data.call(klass.new(scope))
|
53
|
-
else
|
54
|
-
eval @_tilt_data, binding
|
55
|
-
end
|
46
|
+
::Tilt::Jbuilder.encode(scope) do |json|
|
47
|
+
context = scope.instance_eval { binding }
|
48
|
+
set_locals(locals, scope, context)
|
49
|
+
if data.kind_of?(Proc)
|
50
|
+
return data.call(::Tilt::Jbuilder.new(scope))
|
56
51
|
else
|
57
|
-
|
58
|
-
if @_tilt_data.kind_of? Proc
|
59
|
-
return @_tilt_data.call(klass.new(scope))
|
60
|
-
else
|
61
|
-
eval @_tilt_data, binding
|
62
|
-
end
|
63
|
-
end
|
52
|
+
eval(data, context)
|
64
53
|
end
|
65
|
-
|
54
|
+
end
|
66
55
|
end
|
67
56
|
|
68
57
|
private
|
@@ -1,51 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Sinatra Integration" do
|
4
|
-
|
5
|
-
jbuilder_app { jbuilder "json.author 'Anthony'" }
|
6
|
-
body.should == "{\"author\":\"Anthony\"}"
|
7
|
-
end
|
8
|
-
|
9
|
-
it "renders .jbuilder files in views path" do
|
10
|
-
jbuilder_app { jbuilder :hello }
|
11
|
-
body.should == "{\"author\":\"Anthony\"}"
|
12
|
-
end
|
13
|
-
|
14
|
-
it "renders instance variables" do
|
15
|
-
jbuilder_app { @last_name = "Smith"; jbuilder "json.last_name @last_name" }
|
16
|
-
body.should == "{\"last_name\":\"Smith\"}"
|
17
|
-
end
|
18
|
-
|
19
|
-
it "renders helper methods" do
|
20
|
-
jbuilder_app { jbuilder "json.is_admin admin?" }
|
21
|
-
body.should == "{\"is_admin\":false}"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "renders partials with local variables" do
|
25
|
-
jbuilder_app { jbuilder "json.partial! :partial_with_local_variable, last_name: \"Smith\"" }
|
26
|
-
body.should == "{\"last_name\":\"Smith\"}"
|
27
|
-
end
|
28
|
-
|
29
|
-
it "renders partials with instance variables" do
|
30
|
-
jbuilder_app { @last_name = "Smith"; jbuilder "json.partial! :partial_with_instance_variable" }
|
31
|
-
body.should == "{\"last_name\":\"Smith\"}"
|
32
|
-
end
|
33
|
-
|
34
|
-
it "renders partials with helper methods" do
|
35
|
-
jbuilder_app { jbuilder "json.partial! :partial_with_helper_method" }
|
36
|
-
body.should == "{\"is_admin\":false}"
|
37
|
-
end
|
38
|
-
|
39
|
-
it "renders partials with local variables and non-Sinatra-application scope" do
|
40
|
-
jbuilder_app { jbuilder "json.partial! :partial_with_local_variable, last_name: \"Smith\"", :scope => Object.new }
|
41
|
-
body.should == "{\"last_name\":\"Smith\"}"
|
42
|
-
end
|
43
|
-
|
44
|
-
it "renders partials multiple times" do
|
45
|
-
lambda do
|
46
|
-
2.times do
|
47
|
-
jbuilder_app { jbuilder "json.partial! :partial_with_local_variable, last_name: \"Smith\"" }
|
48
|
-
end
|
49
|
-
end.should_not raise_error
|
50
|
-
end
|
4
|
+
sinatra_integration_tests
|
51
5
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
def sinatra_integration_tests
|
2
|
+
it "renders inline jbuilder strings" do
|
3
|
+
jbuilder_app { jbuilder "json.author 'Anthony'" }
|
4
|
+
body.should == "{\"author\":\"Anthony\"}"
|
5
|
+
end
|
6
|
+
|
7
|
+
it "renders .jbuilder files in views path" do
|
8
|
+
jbuilder_app { jbuilder :hello }
|
9
|
+
body.should == "{\"author\":\"Anthony\"}"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "renders instance variables" do
|
13
|
+
jbuilder_app { @last_name = "Smith"; jbuilder "json.last_name @last_name" }
|
14
|
+
body.should == "{\"last_name\":\"Smith\"}"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "renders helper methods" do
|
18
|
+
jbuilder_app { jbuilder "json.is_admin admin?" }
|
19
|
+
body.should == "{\"is_admin\":false}"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "renders partials with local variables" do
|
23
|
+
jbuilder_app { jbuilder "json.partial! :partial_with_local_variable, last_name: \"Smith\"" }
|
24
|
+
body.should == "{\"last_name\":\"Smith\"}"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "renders partials with instance variables" do
|
28
|
+
jbuilder_app { @last_name = "Smith"; jbuilder "json.partial! :partial_with_instance_variable" }
|
29
|
+
body.should == "{\"last_name\":\"Smith\"}"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "renders partials with helper methods" do
|
33
|
+
jbuilder_app { jbuilder "json.partial! :partial_with_helper_method" }
|
34
|
+
body.should == "{\"is_admin\":false}"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "renders partials with local variables and non-Sinatra-application scope" do
|
38
|
+
jbuilder_app { jbuilder "json.partial! :partial_with_local_variable, last_name: \"Smith\"", :scope => Object.new }
|
39
|
+
body.should == "{\"last_name\":\"Smith\"}"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "renders partials multiple times" do
|
43
|
+
lambda do
|
44
|
+
2.times do
|
45
|
+
jbuilder_app { jbuilder "json.partial! :partial_with_local_variable, last_name: \"Smith\"" }
|
46
|
+
end
|
47
|
+
end.should_not raise_error
|
48
|
+
end
|
49
|
+
end
|
data/spec/tilt-jbuilder_spec.rb
CHANGED
@@ -28,8 +28,11 @@ describe Tilt::JbuilderTemplate do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should evaluate block style templates" do
|
31
|
-
template = Tilt::JbuilderTemplate.new do |
|
32
|
-
lambda
|
31
|
+
template = Tilt::JbuilderTemplate.new do |json|
|
32
|
+
lambda do |json|
|
33
|
+
json.author 'Anthony'
|
34
|
+
json.target!
|
35
|
+
end
|
33
36
|
end
|
34
37
|
"{\"author\":\"Anthony\"}".should == template.render
|
35
38
|
end
|
data/tilt-jbuilder.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.summary = %q{Adds support for rendering Jbuilder templates in Tilt.}
|
7
7
|
gem.homepage = "https://github.com/anthonator/tilt-jbuilder"
|
8
8
|
|
9
|
-
gem.add_dependency 'tilt', '<= 1.
|
9
|
+
gem.add_dependency 'tilt', '<= 1.5.0'
|
10
10
|
gem.add_dependency 'jbuilder'
|
11
11
|
|
12
12
|
gem.add_development_dependency 'bundler'
|
@@ -16,5 +16,5 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
17
|
gem.name = "tilt-jbuilder"
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
-
gem.version = '0.
|
19
|
+
gem.version = '0.6.0'
|
20
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tilt-jbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "<="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.5.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "<="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.5.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: jbuilder
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,8 +69,10 @@ files:
|
|
69
69
|
- lib/tilt/jbuilder.rb
|
70
70
|
- spec/_partial.json.jbuilder
|
71
71
|
- spec/sinatra_integration_spec.rb
|
72
|
+
- spec/sinatra_json_integration_spec.rb
|
72
73
|
- spec/spec_helper.rb
|
73
74
|
- spec/support/sinatra_integration_test_methods.rb
|
75
|
+
- spec/support/sinatra_integration_tests.rb
|
74
76
|
- spec/support/views/_partial_with_helper_method.jbuilder
|
75
77
|
- spec/support/views/_partial_with_instance_variable.jbuilder
|
76
78
|
- spec/support/views/_partial_with_local_variable.jbuilder
|
@@ -96,15 +98,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
98
|
version: '0'
|
97
99
|
requirements: []
|
98
100
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.2.
|
101
|
+
rubygems_version: 2.2.2
|
100
102
|
signing_key:
|
101
103
|
specification_version: 4
|
102
104
|
summary: Adds support for rendering Jbuilder templates in Tilt.
|
103
105
|
test_files:
|
104
106
|
- spec/_partial.json.jbuilder
|
105
107
|
- spec/sinatra_integration_spec.rb
|
108
|
+
- spec/sinatra_json_integration_spec.rb
|
106
109
|
- spec/spec_helper.rb
|
107
110
|
- spec/support/sinatra_integration_test_methods.rb
|
111
|
+
- spec/support/sinatra_integration_tests.rb
|
108
112
|
- spec/support/views/_partial_with_helper_method.jbuilder
|
109
113
|
- spec/support/views/_partial_with_instance_variable.jbuilder
|
110
114
|
- spec/support/views/_partial_with_local_variable.jbuilder
|