tilt-jbuilder 0.6.1 → 0.7.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.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +4 -0
- data/Gemfile +1 -1
- data/README.md +4 -4
- data/lib/tilt/jbuilder.rb +50 -4
- data/spec/sinatra_json_integration_spec.rb +2 -2
- data/spec/spec_helper.rb +4 -2
- data/spec/templates/_collection_partial.json.jbuilder +1 -0
- data/spec/{_partial.json.jbuilder → templates/_partial.json.jbuilder} +0 -0
- data/spec/tilt-jbuilder_spec.rb +42 -6
- data/tilt-jbuilder.gemspec +12 -12
- metadata +17 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3479ae47f34755751c8800f0a303dc2452ad0ccd
|
4
|
+
data.tar.gz: edede33e7a7235d4875d36f74a6550cfc5b892d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c18a29f7da6f6402d91ba959b0677564c504178656070cb4f763b82f2fe085c588a0ceb89fdd4a0ead5b638664e211742864e97deb80457bada32d59838f82b
|
7
|
+
data.tar.gz: bcf3903c08e27aea78be98e7085b35410f936b0ba4fefc7a5ea553176acb12268dc07498a8498d450cfc876494964e3cda328f89f396516b4b480a888eaa56af
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# tilt-jbuilder
|
1
|
+
# tilt-jbuilder
|
2
2
|
|
3
3
|
Adds support for rendering Jbuilder templates using Tilt.
|
4
4
|
|
@@ -24,7 +24,7 @@ Or install it yourself as:
|
|
24
24
|
require 'tilt/jbuilder.rb'
|
25
25
|
|
26
26
|
template = Tilt::JbuilderTemplate.new("templates/awesomeness.json.jbuilder")
|
27
|
-
|
27
|
+
template.render
|
28
28
|
|
29
29
|
# With locals
|
30
30
|
template = Tilt::JbuilderTemplate.new { "json.author name" }
|
@@ -52,8 +52,8 @@ template.render
|
|
52
52
|
|
53
53
|
## Credits
|
54
54
|
|
55
|
-
[](http://www.sticksnleaves.com)
|
56
56
|
|
57
57
|
tilt-jbuilder is maintained and funded by [Sticksnleaves](http://www.sticksnleaves.com)
|
58
58
|
|
59
|
-
Thanks to all of our [contributors](https://github.com/anthonator/tilt-jbuilder/graphs/contributors)
|
59
|
+
Thanks to all of our [contributors](https://github.com/anthonator/tilt-jbuilder/graphs/contributors)
|
data/lib/tilt/jbuilder.rb
CHANGED
@@ -8,11 +8,37 @@ module Tilt
|
|
8
8
|
super(*args, &block)
|
9
9
|
end
|
10
10
|
|
11
|
-
def partial!(
|
12
|
-
|
11
|
+
def partial!(name_or_options, locals = {})
|
12
|
+
case name_or_options
|
13
|
+
when ::Hash
|
14
|
+
# partial! partial: 'name', locals: { foo: 'bar' }
|
15
|
+
options = name_or_options
|
16
|
+
else
|
17
|
+
# partial! 'name', foo: 'bar'
|
18
|
+
options = { partial: name_or_options, locals: locals }
|
19
|
+
as = locals.delete(:as)
|
20
|
+
options[:as] = as if as.present?
|
21
|
+
options[:collection] = locals[:collection] if locals.key?(:collection)
|
22
|
+
end
|
23
|
+
|
13
24
|
view_path = @scope.instance_variable_get('@_jbuilder_view_path')
|
14
|
-
template = ::Tilt::JbuilderTemplate.new(fetch_partial_path(options.to_s, view_path), nil, view_path: view_path)
|
15
|
-
|
25
|
+
@template = ::Tilt::JbuilderTemplate.new(fetch_partial_path(options[:partial].to_s, view_path), nil, view_path: view_path)
|
26
|
+
render_partial_with_options options
|
27
|
+
end
|
28
|
+
|
29
|
+
def array!(collection = [], *attributes, &block)
|
30
|
+
options = attributes.extract_options!
|
31
|
+
|
32
|
+
if options.key?(:partial)
|
33
|
+
partial! options[:partial], options.merge(collection: collection)
|
34
|
+
else
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# for now caching is not supported, but at least we can transparently ignore it
|
40
|
+
def cache!(key=nil, options={}, &block)
|
41
|
+
yield
|
16
42
|
end
|
17
43
|
|
18
44
|
private
|
@@ -26,6 +52,26 @@ module Tilt
|
|
26
52
|
partial_file[-1] = "_#{partial_file[-1]}" unless partial_file[-1].start_with?("_")
|
27
53
|
partial_file.join("/")
|
28
54
|
end
|
55
|
+
|
56
|
+
def render_partial_with_options(options)
|
57
|
+
options[:locals] ||= {}
|
58
|
+
if options[:as] && options.key?(:collection)
|
59
|
+
collection = options.delete(:collection)
|
60
|
+
locals = options.delete(:locals)
|
61
|
+
array! collection do |member|
|
62
|
+
member_locals = locals.clone
|
63
|
+
member_locals.merge! options[:as] => member
|
64
|
+
render_partial member_locals
|
65
|
+
end
|
66
|
+
else
|
67
|
+
render_partial options[:locals]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def render_partial(options)
|
72
|
+
options.merge! json: self
|
73
|
+
@template.render @scope, options
|
74
|
+
end
|
29
75
|
end
|
30
76
|
|
31
77
|
class JbuilderTemplate < Template
|
data/spec/spec_helper.rb
CHANGED
@@ -4,9 +4,11 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
|
4
4
|
SimpleCov::Formatter::HTMLFormatter,
|
5
5
|
Coveralls::SimpleCov::Formatter
|
6
6
|
]
|
7
|
-
SimpleCov.start
|
7
|
+
SimpleCov.start do
|
8
|
+
add_filter('.gems')
|
9
|
+
end
|
8
10
|
|
9
|
-
ENV['RACK_ENV'] ||=
|
11
|
+
ENV['RACK_ENV'] ||= 'test'
|
10
12
|
|
11
13
|
require 'tilt/jbuilder'
|
12
14
|
require 'sinatra/jbuilder'
|
@@ -0,0 +1 @@
|
|
1
|
+
json.attribute name
|
File without changes
|
data/spec/tilt-jbuilder_spec.rb
CHANGED
@@ -36,6 +36,11 @@ describe Tilt::JbuilderTemplate do
|
|
36
36
|
"{\"author\":\"Anthony\"}".should == template.render(scope)
|
37
37
|
end
|
38
38
|
|
39
|
+
it "should ignore cache!" do
|
40
|
+
template = Tilt::JbuilderTemplate.new { "json.cache! { json.author name }" }
|
41
|
+
"{\"author\":\"Anthony\"}".should == template.render(Object.new, :name => 'Anthony')
|
42
|
+
end
|
43
|
+
|
39
44
|
it "should evaluate block style templates" do
|
40
45
|
template = Tilt::JbuilderTemplate.new do |json|
|
41
46
|
lambda do |json|
|
@@ -46,13 +51,44 @@ describe Tilt::JbuilderTemplate do
|
|
46
51
|
"{\"author\":\"Anthony\"}".should == template.render
|
47
52
|
end
|
48
53
|
|
49
|
-
|
50
|
-
|
51
|
-
|
54
|
+
describe '.partial!' do
|
55
|
+
it "should evaluate partials" do
|
56
|
+
template = Tilt::JbuilderTemplate.new { "json.partial! 'spec/templates/partial', last_name: 'Smith'" }
|
57
|
+
"{\"last_name\":\"Smith\"}".should == template.render
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should evaluate partials with view_path" do
|
61
|
+
template = Tilt::JbuilderTemplate.new(nil, nil, view_path: 'spec') { "json.partial! '/templates/partial', last_name: 'Smith'" }
|
62
|
+
"{\"last_name\":\"Smith\"}".should == template.render
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'with jbuilder syntax' do
|
66
|
+
let(:template) { Tilt::JbuilderTemplate.new { template_body } }
|
67
|
+
subject { template.render }
|
68
|
+
|
69
|
+
context 'with json.partial! "partial", collection: [], as: :name' do
|
70
|
+
let(:template_body) { "json.partial! 'spec/templates/collection_partial', collection: ['foo', 'bar'], as: :name" }
|
71
|
+
it { is_expected.to eq %q/[{"attribute":"foo"},{"attribute":"bar"}]/ }
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'with json.partial! partial: "partial", collection: [], as: :name' do
|
75
|
+
let(:template_body) { "json.partial! partial: 'spec/templates/collection_partial', collection: ['foo', 'bar'], as: :name" }
|
76
|
+
it { is_expected.to eq %q/[{"attribute":"foo"},{"attribute":"bar"}]/ }
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'with json.partial! partial: "partial", locals: {}' do
|
80
|
+
let(:template_body) { "json.partial! partial: 'spec/templates/partial', locals: { last_name: 'Smith' }" }
|
81
|
+
it { is_expected.to eq %q/{"last_name":"Smith"}/ }
|
82
|
+
end
|
83
|
+
end
|
52
84
|
end
|
53
85
|
|
54
|
-
|
55
|
-
template
|
56
|
-
|
86
|
+
describe '.array!' do
|
87
|
+
let(:template) { Tilt::JbuilderTemplate.new { template_body } }
|
88
|
+
subject { template.render }
|
89
|
+
context 'with json.array! [], partial: "partial", as: :name' do
|
90
|
+
let(:template_body) { "json.array! ['foo', 'bar'], partial: 'spec/templates/collection_partial', as: :name" }
|
91
|
+
it { is_expected.to eq %q/[{"attribute":"foo"},{"attribute":"bar"}]/ }
|
92
|
+
end
|
57
93
|
end
|
58
94
|
end
|
data/tilt-jbuilder.gemspec
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |gem|
|
3
|
-
gem.authors = [
|
4
|
-
gem.email = [
|
5
|
-
gem.description =
|
6
|
-
gem.summary =
|
7
|
-
gem.homepage =
|
3
|
+
gem.authors = ['Anthony Smith']
|
4
|
+
gem.email = ['anthony@sticksnleaves.com']
|
5
|
+
gem.description = 'Jbuilder support for Tilt'
|
6
|
+
gem.summary = 'Adds support for rendering Jbuilder templates in Tilt.'
|
7
|
+
gem.homepage = 'https://github.com/anthonator/tilt-jbuilder'
|
8
8
|
|
9
|
-
gem.add_dependency 'tilt', '
|
9
|
+
gem.add_dependency 'tilt', '>= 1.3.0', '< 3'
|
10
10
|
gem.add_dependency 'jbuilder'
|
11
11
|
|
12
12
|
gem.add_development_dependency 'bundler'
|
13
13
|
|
14
|
-
gem.files = `git ls-files`.split(
|
15
|
-
gem.executables = gem.files.grep(
|
16
|
-
gem.test_files = gem.files.grep(
|
17
|
-
gem.name =
|
18
|
-
gem.require_paths = [
|
19
|
-
gem.version = '0.
|
14
|
+
gem.files = `git ls-files`.split($ORS)
|
15
|
+
gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(/^(test|spec|features)\//)
|
17
|
+
gem.name = 'tilt-jbuilder'
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
gem.version = '0.7.0'
|
20
20
|
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tilt-jbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.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:
|
11
|
+
date: 2015-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.0
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
22
|
+
version: '3'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.3.0
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
32
|
+
version: '3'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: jbuilder
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,7 +73,6 @@ files:
|
|
67
73
|
- Rakefile
|
68
74
|
- lib/sinatra/jbuilder.rb
|
69
75
|
- lib/tilt/jbuilder.rb
|
70
|
-
- spec/_partial.json.jbuilder
|
71
76
|
- spec/sinatra_integration_spec.rb
|
72
77
|
- spec/sinatra_json_integration_spec.rb
|
73
78
|
- spec/spec_helper.rb
|
@@ -78,6 +83,8 @@ files:
|
|
78
83
|
- spec/support/views/_partial_with_local_variable.jbuilder
|
79
84
|
- spec/support/views/hello.jbuilder
|
80
85
|
- spec/support/views/invalid.jbuilder
|
86
|
+
- spec/templates/_collection_partial.json.jbuilder
|
87
|
+
- spec/templates/_partial.json.jbuilder
|
81
88
|
- spec/tilt-jbuilder_spec.rb
|
82
89
|
- tilt-jbuilder.gemspec
|
83
90
|
homepage: https://github.com/anthonator/tilt-jbuilder
|
@@ -99,12 +106,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
106
|
version: '0'
|
100
107
|
requirements: []
|
101
108
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.4.5
|
103
110
|
signing_key:
|
104
111
|
specification_version: 4
|
105
112
|
summary: Adds support for rendering Jbuilder templates in Tilt.
|
106
113
|
test_files:
|
107
|
-
- spec/_partial.json.jbuilder
|
108
114
|
- spec/sinatra_integration_spec.rb
|
109
115
|
- spec/sinatra_json_integration_spec.rb
|
110
116
|
- spec/spec_helper.rb
|
@@ -115,4 +121,6 @@ test_files:
|
|
115
121
|
- spec/support/views/_partial_with_local_variable.jbuilder
|
116
122
|
- spec/support/views/hello.jbuilder
|
117
123
|
- spec/support/views/invalid.jbuilder
|
124
|
+
- spec/templates/_collection_partial.json.jbuilder
|
125
|
+
- spec/templates/_partial.json.jbuilder
|
118
126
|
- spec/tilt-jbuilder_spec.rb
|