jbuilder 2.5.0 → 2.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 +2 -2
- data/Appraisals +3 -3
- data/CHANGELOG.md +6 -0
- data/CONTRIBUTING.md +3 -3
- data/README.md +2 -2
- data/jbuilder.gemspec +1 -1
- data/lib/generators/rails/jbuilder_generator.rb +1 -0
- data/lib/generators/rails/templates/index.json.jbuilder +1 -4
- data/lib/generators/rails/templates/partial.json.jbuilder +2 -0
- data/lib/generators/rails/templates/show.json.jbuilder +1 -1
- data/lib/jbuilder/jbuilder_template.rb +29 -3
- data/lib/jbuilder/railtie.rb +1 -1
- data/test/jbuilder_generator_test.rb +10 -4
- data/test/jbuilder_template_test.rb +41 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d949cb2167336c8e5b026626493bb07843dab242
|
4
|
+
data.tar.gz: 1c0a6e23cb4441794732665e5fa2ef73a63eae0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd78d3b8d0fa94ead3c7a77c7769593f2202ec46d18f3a2d3ba875f35a72040bd0e519bfd6e67b60fea465fbef8ffaf8966d964e02538eb8479c52011a5c24a1
|
7
|
+
data.tar.gz: dc257849862f9619da61c740ab9596026b1e2d9cdf0b3b8aa7eee7ab23eef1912fc00ec49eb6c6a3cd888161104929ff851ddbabb1358d655dc947003f6222cc
|
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
@@ -38,7 +38,7 @@ appraise "rails-4-2" do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
appraise "rails-5-0" do
|
41
|
-
gem "railties",
|
42
|
-
gem "actionpack",
|
43
|
-
gem "activemodel", "
|
41
|
+
gem "railties", "~> 5.0.0"
|
42
|
+
gem "actionpack", "~> 5.0.0"
|
43
|
+
gem "activemodel", "~> 5.0.0"
|
44
44
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
2.6.0
|
4
|
+
-----
|
5
|
+
|
6
|
+
* [Rails 5 cache! with expire support](https://github.com/rails/jbuilder/commit/d61e3354563863731bc1f358f495b1dbb7ae9d32)
|
7
|
+
* [Generated view DRYed by using model partial](https://github.com/rails/jbuilder/commit/83256f4d7e9211c9dc47972feaed7fd31e4f7cac)
|
8
|
+
|
3
9
|
2.5.0
|
4
10
|
-----
|
5
11
|
|
data/CONTRIBUTING.md
CHANGED
@@ -2,9 +2,9 @@ Contributing to Jbuilder
|
|
2
2
|
=====================
|
3
3
|
|
4
4
|
[![Build Status](https://api.travis-ci.org/rails/jbuilder.svg?branch=master)][travis]
|
5
|
-
[![Gem Version](
|
6
|
-
[![Code Climate](
|
7
|
-
[![Dependencies Status](
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/jbuilder.svg)][gem]
|
6
|
+
[![Code Climate](https://codeclimate.com/github/rails/jbuilder/badges/gpa.svg)][codeclimate]
|
7
|
+
[![Dependencies Status](https://gemnasium.com/rails/jbuilder.svg)][gemnasium]
|
8
8
|
|
9
9
|
[travis]: https://travis-ci.org/rails/jbuilder
|
10
10
|
[gem]: https://rubygems.org/gems/jbuilder
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ generation process is fraught with conditionals and loops. Here's a simple
|
|
6
6
|
example:
|
7
7
|
|
8
8
|
``` ruby
|
9
|
-
# app/views/
|
9
|
+
# app/views/messages/show.json.jbuilder
|
10
10
|
|
11
11
|
json.content format_content(@message.content)
|
12
12
|
json.(@message, :created_at, :updated_at)
|
@@ -64,7 +64,7 @@ json.set! :author do
|
|
64
64
|
json.set! :name, 'David'
|
65
65
|
end
|
66
66
|
|
67
|
-
# => "author": { "name": "David" }
|
67
|
+
# => {"author": { "name": "David" }}
|
68
68
|
```
|
69
69
|
|
70
70
|
Top level arrays can be handled directly. Useful for index and other collection actions.
|
data/jbuilder.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'jbuilder'
|
3
|
-
s.version = '2.
|
3
|
+
s.version = '2.6.0'
|
4
4
|
s.authors = ['David Heinemeier Hansson', 'Pavel Pravosud']
|
5
5
|
s.email = ['david@37signals.com', 'pavel@pravosud.com']
|
6
6
|
s.summary = 'Create JSON structures via a Builder-style DSL'
|
@@ -20,6 +20,7 @@ module Rails
|
|
20
20
|
filename = filename_with_extensions(view)
|
21
21
|
template filename, File.join('app/views', controller_file_path, filename)
|
22
22
|
end
|
23
|
+
template filename_with_extensions('partial'), File.join('app/views', controller_file_path, filename_with_extensions("_#{singular_table_name}"))
|
23
24
|
end
|
24
25
|
|
25
26
|
|
@@ -1,4 +1 @@
|
|
1
|
-
json.array!
|
2
|
-
json.extract! <%= singular_table_name %>, <%= attributes_list %>
|
3
|
-
json.url <%= singular_table_name %>_url(<%= singular_table_name %>, format: :json)
|
4
|
-
end
|
1
|
+
json.array! @<%= plural_table_name %>, partial: '<%= plural_table_name %>/<%= singular_table_name %>', as: :<%= singular_table_name %>
|
@@ -1 +1 @@
|
|
1
|
-
json.
|
1
|
+
json.partial! "<%= plural_table_name %>/<%= singular_table_name %>", <%= singular_table_name %>: @<%= singular_table_name %>
|
@@ -32,7 +32,7 @@ class JbuilderTemplate < Jbuilder
|
|
32
32
|
# end
|
33
33
|
def cache!(key=nil, options={})
|
34
34
|
if @context.controller.perform_caching
|
35
|
-
value =
|
35
|
+
value = _cache_fragment_for(key, options) do
|
36
36
|
_scope { yield self }
|
37
37
|
end
|
38
38
|
|
@@ -102,9 +102,35 @@ class JbuilderTemplate < Jbuilder
|
|
102
102
|
@context.render options
|
103
103
|
end
|
104
104
|
|
105
|
+
def _cache_fragment_for(key, options, &block)
|
106
|
+
key = _cache_key(key, options)
|
107
|
+
_read_fragment_cache(key, options) || _write_fragment_cache(key, options, &block)
|
108
|
+
end
|
109
|
+
|
110
|
+
def _read_fragment_cache(key, options = nil)
|
111
|
+
@context.controller.instrument_fragment_cache :read_fragment, key do
|
112
|
+
::Rails.cache.read(key, options)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def _write_fragment_cache(key, options = nil)
|
117
|
+
@context.controller.instrument_fragment_cache :write_fragment, key do
|
118
|
+
yield.tap do |value|
|
119
|
+
::Rails.cache.write(key, value, options)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
105
124
|
def _cache_key(key, options)
|
106
|
-
|
107
|
-
key =
|
125
|
+
name_options = options.slice(:skip_digest, :virtual_path)
|
126
|
+
key = _fragment_name_with_digest(key, name_options)
|
127
|
+
|
128
|
+
if @context.respond_to?(:fragment_cache_key)
|
129
|
+
key = @context.fragment_cache_key(key)
|
130
|
+
else
|
131
|
+
key = url_for(key).split('://', 2).last if ::Hash === key
|
132
|
+
end
|
133
|
+
|
108
134
|
::ActiveSupport::Cache.expand_cache_key(key, :jbuilder)
|
109
135
|
end
|
110
136
|
|
data/lib/jbuilder/railtie.rb
CHANGED
@@ -3,7 +3,7 @@ require 'jbuilder/jbuilder_template'
|
|
3
3
|
|
4
4
|
class Jbuilder
|
5
5
|
class Railtie < ::Rails::Railtie
|
6
|
-
initializer :jbuilder do
|
6
|
+
initializer :jbuilder do
|
7
7
|
ActiveSupport.on_load :action_view do
|
8
8
|
ActionView::Template.register_template_handler :jbuilder, JbuilderHandler
|
9
9
|
require 'jbuilder/dependency_tracker'
|
@@ -14,19 +14,25 @@ class JbuilderGeneratorTest < Rails::Generators::TestCase
|
|
14
14
|
%w(index show).each do |view|
|
15
15
|
assert_file "app/views/posts/#{view}.json.jbuilder"
|
16
16
|
end
|
17
|
+
assert_file "app/views/posts/_post.json.jbuilder"
|
17
18
|
end
|
18
19
|
|
19
20
|
test 'index content' do
|
20
21
|
run_generator
|
21
22
|
|
22
23
|
assert_file 'app/views/posts/index.json.jbuilder' do |content|
|
23
|
-
assert_match /json
|
24
|
-
assert_match /json\.extract! post, :id, :title, :body/, content
|
25
|
-
assert_match /json\.url post_url\(post, format: :json\)/, content
|
24
|
+
assert_match /json.array! @posts, partial: 'posts\/post', as: :post/, content
|
26
25
|
end
|
27
26
|
|
28
27
|
assert_file 'app/views/posts/show.json.jbuilder' do |content|
|
29
|
-
assert_match /json
|
28
|
+
assert_match /json.partial! \"posts\/post\", post: @post/, content
|
29
|
+
end
|
30
|
+
|
31
|
+
assert_file 'app/views/posts/_post.json.jbuilder' do |content|
|
32
|
+
assert_match /json\.extract! post, :id, :title, :body/, content
|
33
|
+
assert_match /json\.url post_url\(post, format: :json\)/, content
|
30
34
|
end
|
35
|
+
|
36
|
+
|
31
37
|
end
|
32
38
|
end
|
@@ -332,6 +332,35 @@ class JbuilderTemplateTest < ActionView::TestCase
|
|
332
332
|
JBUILDER
|
333
333
|
end
|
334
334
|
|
335
|
+
test "fragment caching uses fragment_cache_key" do
|
336
|
+
undef_context_methods :fragment_name_with_digest, :cache_fragment_name
|
337
|
+
|
338
|
+
@context.expects(:fragment_cache_key).with("cachekey")
|
339
|
+
|
340
|
+
jbuild <<-JBUILDER
|
341
|
+
json.cache! "cachekey" do
|
342
|
+
json.name "Cache"
|
343
|
+
end
|
344
|
+
JBUILDER
|
345
|
+
end
|
346
|
+
|
347
|
+
test "fragment caching instrumentation" do
|
348
|
+
undef_context_methods :fragment_name_with_digest, :cache_fragment_name
|
349
|
+
|
350
|
+
payloads = {}
|
351
|
+
ActiveSupport::Notifications.subscribe("read_fragment.action_controller") { |*args| payloads[:read_fragment] = args.last }
|
352
|
+
ActiveSupport::Notifications.subscribe("write_fragment.action_controller") { |*args| payloads[:write_fragment] = args.last }
|
353
|
+
|
354
|
+
jbuild <<-JBUILDER
|
355
|
+
json.cache! "cachekey" do
|
356
|
+
json.name "Cache"
|
357
|
+
end
|
358
|
+
JBUILDER
|
359
|
+
|
360
|
+
assert_equal "jbuilder/cachekey", payloads[:read_fragment][:key]
|
361
|
+
assert_equal "jbuilder/cachekey", payloads[:write_fragment][:key]
|
362
|
+
end
|
363
|
+
|
335
364
|
test "current cache digest option accepts options" do
|
336
365
|
undef_context_methods :fragment_name_with_digest
|
337
366
|
|
@@ -345,6 +374,18 @@ class JbuilderTemplateTest < ActionView::TestCase
|
|
345
374
|
JBUILDER
|
346
375
|
end
|
347
376
|
|
377
|
+
test "fragment caching accepts expires_in option" do
|
378
|
+
undef_context_methods :fragment_name_with_digest
|
379
|
+
|
380
|
+
@context.expects(:cache_fragment_name).with("cachekey", {})
|
381
|
+
|
382
|
+
jbuild <<-JBUILDER
|
383
|
+
json.cache! "cachekey", expires_in: 1.minute do
|
384
|
+
json.name "Cache"
|
385
|
+
end
|
386
|
+
JBUILDER
|
387
|
+
end
|
388
|
+
|
348
389
|
test "does not perform caching when controller.perform_caching is false" do
|
349
390
|
controller.perform_caching = false
|
350
391
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-07-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- lib/generators/rails/templates/api_controller.rb
|
76
76
|
- lib/generators/rails/templates/controller.rb
|
77
77
|
- lib/generators/rails/templates/index.json.jbuilder
|
78
|
+
- lib/generators/rails/templates/partial.json.jbuilder
|
78
79
|
- lib/generators/rails/templates/show.json.jbuilder
|
79
80
|
- lib/jbuilder.rb
|
80
81
|
- lib/jbuilder/blank.rb
|
@@ -111,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
112
|
version: '0'
|
112
113
|
requirements: []
|
113
114
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.6.4
|
115
116
|
signing_key:
|
116
117
|
specification_version: 4
|
117
118
|
summary: Create JSON structures via a Builder-style DSL
|