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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ce8173d024f2eb565369d2e8f26ea09dc5235e7
4
- data.tar.gz: b73633ccd806484d4f5c2a11533f1787fbf90d2b
3
+ metadata.gz: d949cb2167336c8e5b026626493bb07843dab242
4
+ data.tar.gz: 1c0a6e23cb4441794732665e5fa2ef73a63eae0d
5
5
  SHA512:
6
- metadata.gz: 63ab27131b380962043ca8c17440ee0d8da28196c17793d61c2fbacf19045799a4c652402ec5d65afa6d899cc91e54c56cf460e86c809c402d37024ecc734469
7
- data.tar.gz: 8d0def4d3db80aa215246f3b8fb2df57943adc02fbe9e678c88d2f40523959ecf285a36f905fe0ac1a566b583a2abb9432feb1064bf6f1a7d276db6e2382c104
6
+ metadata.gz: bd78d3b8d0fa94ead3c7a77c7769593f2202ec46d18f3a2d3ba875f35a72040bd0e519bfd6e67b60fea465fbef8ffaf8966d964e02538eb8479c52011a5c24a1
7
+ data.tar.gz: dc257849862f9619da61c740ab9596026b1e2d9cdf0b3b8aa7eee7ab23eef1912fc00ec49eb6c6a3cd888161104929ff851ddbabb1358d655dc947003f6222cc
@@ -7,8 +7,8 @@ rvm:
7
7
  - 1.9
8
8
  - 2.0
9
9
  - 2.1
10
- - 2.2.4
11
- - 2.3.0
10
+ - 2.2.5
11
+ - 2.3.1
12
12
  - ruby-head
13
13
  - jruby-19mode
14
14
  - rbx
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", ">= 5.0.0.beta2", "< 5.1"
42
- gem "actionpack", ">= 5.0.0.beta2", "< 5.1"
43
- gem "activemodel", ">= 5.0.0.beta2", "< 5.1"
41
+ gem "railties", "~> 5.0.0"
42
+ gem "actionpack", "~> 5.0.0"
43
+ gem "activemodel", "~> 5.0.0"
44
44
  end
@@ -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
 
@@ -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](http://img.shields.io/gem/v/jbuilder.svg)][gem]
6
- [![Code Climate](http://img.shields.io/codeclimate/github/rails/jbuilder.svg)][codeclimate]
7
- [![Dependencies Status](http://img.shields.io/gemnasium/rails/jbuilder.svg)][gemnasium]
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/message/show.json.jbuilder
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.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jbuilder'
3
- s.version = '2.5.0'
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!(@<%= plural_table_name %>) do |<%= singular_table_name %>|
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 %>
@@ -0,0 +1,2 @@
1
+ json.extract! <%= singular_table_name %>, <%= attributes_list_with_timestamps %>
2
+ json.url <%= singular_table_name %>_url(<%= singular_table_name %>, format: :json)
@@ -1 +1 @@
1
- json.extract! @<%= singular_table_name %>, <%= attributes_list_with_timestamps %>
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 = ::Rails.cache.fetch(_cache_key(key, options), options) do
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
- key = _fragment_name_with_digest(key, options)
107
- key = url_for(key).split('://', 2).last if ::Hash === 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
 
@@ -3,7 +3,7 @@ require 'jbuilder/jbuilder_template'
3
3
 
4
4
  class Jbuilder
5
5
  class Railtie < ::Rails::Railtie
6
- initializer :jbuilder do |app|
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\.array!\(@posts\) do \|post\|/, content
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\.extract! @post, :id, :title, :body, :created_at, :updated_at/, content
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.5.0
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-05-30 00:00:00.000000000 Z
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.5.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