jbuilder 2.2.16 → 2.6.4

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: 79566456f0f777b15fdab405ea286da70467e78c
4
- data.tar.gz: 73ac0f91316aea81448cca1e2d414d4b1c20fde4
3
+ metadata.gz: e35bd234795a5d5f23c73a30d259ca195e42f6e5
4
+ data.tar.gz: 3e884978c900ea0ef14aa7e68e611246b2b74814
5
5
  SHA512:
6
- metadata.gz: cef291a3f61cd86b1f36bbf171dcea06bc4388cb23cde5a309cf4c9217d6dad9b3641b6d3cc2994fcee3b6b21018763a53d0d3358d938570b1e5b274f356dafd
7
- data.tar.gz: 4b4e043b1b7a029bebecf8f90bc9f9fb46c5ed6be43e0cdefca0711ef292302651b126ae6c033f02c15c715c7f65a0f86c3bb1248375083cf0e09dd117bb639f
6
+ metadata.gz: de29407995773a316901cee9012d9f363366ac02ecd4faeb98ab58099536dc5377d53e3c07242f24f17e039111a7f45842ecb5cfc37be67af5852e4ce7c471de
7
+ data.tar.gz: 9bc528a7c2f5fe784567d0d62012a51b3e398debf13a72e68496f7345be69f0f62c401b6dfa07e1a38773a4d4d952b768e63b83c32fa24e64041fe62b6dd3778
data/.travis.yml CHANGED
@@ -1,10 +1,15 @@
1
1
  language: ruby
2
2
 
3
+ sudo: false
4
+ cache: bundler
5
+
3
6
  rvm:
4
7
  - 1.9
5
8
  - 2.0
6
9
  - 2.1
7
- - 2.2
10
+ - 2.2.5
11
+ - 2.3.1
12
+ - 2.4.0
8
13
  - ruby-head
9
14
  - jruby-19mode
10
15
  - rbx
@@ -16,6 +21,8 @@ gemfile:
16
21
  - gemfiles/rails_4_0.gemfile
17
22
  - gemfiles/rails_4_1.gemfile
18
23
  - gemfiles/rails_4_2.gemfile
24
+ - gemfiles/rails_5_0.gemfile
25
+ - gemfiles/rails_5_1.gemfile
19
26
 
20
27
  matrix:
21
28
  allow_failures:
@@ -23,6 +30,37 @@ matrix:
23
30
  - rvm: rbx
24
31
  - rvm: ruby-head
25
32
  fast_finish: true
33
+ exclude:
34
+ - rvm: 1.9
35
+ gemfile: gemfiles/rails_5_0.gemfile
36
+ - rvm: 1.9
37
+ gemfile: gemfiles/rails_5_1.gemfile
38
+ - rvm: 2.0
39
+ gemfile: gemfiles/rails_5_0.gemfile
40
+ - rvm: 2.0
41
+ gemfile: gemfiles/rails_5_1.gemfile
42
+ - rvm: 2.1
43
+ gemfile: gemfiles/rails_5_0.gemfile
44
+ - rvm: 2.1
45
+ gemfile: gemfiles/rails_5_1.gemfile
46
+ - rvm: jruby-19mode
47
+ gemfile: gemfiles/rails_5_0.gemfile
48
+ - rvm: jruby-19mode
49
+ gemfile: gemfiles/rails_5_1.gemfile
50
+ - rvm: rbx
51
+ gemfile: gemfiles/rails_5_0.gemfile
52
+ - rvm: rbx
53
+ gemfile: gemfiles/rails_5_1.gemfile
54
+ - rvm: 2.4.0
55
+ gemfile: gemfiles/rails_3_0.gemfile
56
+ - rvm: 2.4.0
57
+ gemfile: gemfiles/rails_3_1.gemfile
58
+ - rvm: 2.4.0
59
+ gemfile: gemfiles/rails_3_2.gemfile
60
+ - rvm: 2.4.0
61
+ gemfile: gemfiles/rails_4_0.gemfile
62
+ - rvm: 2.4.0
63
+ gemfile: gemfiles/rails_4_1.gemfile
26
64
 
27
65
  notifications:
28
66
  email: false
data/Appraisals CHANGED
@@ -1,32 +1,50 @@
1
1
  appraise "rails-3-0" do
2
2
  gem "test-unit"
3
- gem "railties", "~> 3.0.0"
4
- gem "actionpack", "~> 3.0.0"
3
+ gem "railties", "~> 3.0.0"
4
+ gem "actionpack", "~> 3.0.0"
5
+ gem "activemodel", "~> 3.0.0"
5
6
  end
6
7
 
7
8
  appraise "rails-3-1" do
8
9
  gem "test-unit"
9
- gem "railties", "~> 3.1.0"
10
- gem "actionpack", "~> 3.1.0"
10
+ gem "railties", "~> 3.1.0"
11
+ gem "actionpack", "~> 3.1.0"
12
+ gem "activemodel", "~> 3.1.0"
11
13
  end
12
14
 
13
15
  appraise "rails-3-2" do
14
16
  gem "test-unit"
15
- gem "railties", "~> 3.2.0"
16
- gem "actionpack", "~> 3.2.0"
17
+ gem "railties", "~> 3.2.0"
18
+ gem "actionpack", "~> 3.2.0"
19
+ gem "activemodel", "~> 3.2.0"
17
20
  end
18
21
 
19
22
  appraise "rails-4-0" do
20
- gem "railties", "~> 4.0.0"
21
- gem "actionpack", "~> 4.0.0"
23
+ gem "railties", "~> 4.0.0"
24
+ gem "actionpack", "~> 4.0.0"
25
+ gem "activemodel", "~> 4.0.0"
22
26
  end
23
27
 
24
28
  appraise "rails-4-1" do
25
- gem "railties", "~> 4.1.0"
26
- gem "actionpack", "~> 4.1.0"
29
+ gem "railties", "~> 4.1.0"
30
+ gem "actionpack", "~> 4.1.0"
31
+ gem "activemodel", "~> 4.1.0"
27
32
  end
28
33
 
29
34
  appraise "rails-4-2" do
30
- gem "railties", "~> 4.2.0"
31
- gem "actionpack", "~> 4.2.0"
35
+ gem "railties", "~> 4.2.0"
36
+ gem "actionpack", "~> 4.2.0"
37
+ gem "activemodel", "~> 4.2.0"
38
+ end
39
+
40
+ appraise "rails-5-0" do
41
+ gem "railties", "~> 5.0.0"
42
+ gem "actionpack", "~> 5.0.0"
43
+ gem "activemodel", "~> 5.0.0"
44
+ end
45
+
46
+ appraise "rails-5-1" do
47
+ gem "railties", ">= 5.1.0", "< 5.2"
48
+ gem "actionpack", ">= 5.1.0", "< 5.2"
49
+ gem "activemodel", ">= 5.1.0", "< 5.2"
32
50
  end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,65 @@
1
1
  # Changelog
2
2
 
3
+ 2.6.4
4
+ -----
5
+
6
+ * Drop the pessimistic upper-bound restriction on Active Support and MultiJSON to prevent future gemfile resolution deadlocks *DHH*
7
+
8
+ 2.6.3
9
+ -----
10
+
11
+ * Support Rails 5.1
12
+
13
+ 2.6.2
14
+ -----
15
+
16
+ * Fix thor warnings
17
+
18
+ 2.6.1
19
+ -----
20
+
21
+ * [Optimize root caches with cache_root!](https://github.com/rails/jbuilder/pull/370)
22
+
23
+ 2.6.0
24
+ -----
25
+
26
+ * [Rails 5 cache! with expire support](https://github.com/rails/jbuilder/commit/d61e3354563863731bc1f358f495b1dbb7ae9d32)
27
+ * [Generated view DRYed by using model partial](https://github.com/rails/jbuilder/commit/83256f4d7e9211c9dc47972feaed7fd31e4f7cac)
28
+
29
+ 2.5.0
30
+ -----
31
+
32
+ * [Rails 5 compatibility](https://github.com/rails/jbuilder/commit/64c510ec69d9e63b73ffd5942e802d21a7d14701)
33
+
34
+ 2.4.1
35
+ -----
36
+
37
+ * [Fix controller generators to be Rails 5 compatible](https://github.com/rails/jbuilder/commit/2dc6203c5c4a98701d5b64c2a5200835a48bb533)
38
+
39
+ 2.4.0
40
+ -----
41
+
42
+ * [Rails 5 compatibility](https://github.com/rails/jbuilder/commit/4aa2cfcc19a4634d65a28ffc75f0ac0cb8304115)
43
+
44
+ 2.3.2
45
+ -----
46
+
47
+ * [Remove Mime Types deprecation message](https://github.com/rails/jbuilder/commit/5ba4e4ac654cc8388619538f576fe234659b84ec)
48
+
49
+ 2.3.1
50
+ -----
51
+
52
+ * [Explicitly require ostruct to prevent NameError](https://github.com/rails/jbuilder/pull/281)
53
+
54
+ 2.3.0
55
+ -----
56
+
57
+ * [Add new in-place partial invocation support](https://github.com/rails/jbuilder/commit/1feda7ee605c136e59fb4de970f4674de518e6de)
58
+ * [Add implicit partial rendering for AM::Models](https://github.com/rails/jbuilder/commit/4d5bf7d0ea92765adb7be36834e84f9855a061df)
59
+ * [Generate API controller if Rails API option is enabled](https://github.com/rails/jbuilder/commit/db68f6bd327cf42b47ef22d455fb5721a8c2cf5f)
60
+ * [JBuilder's templates have less priority than app templates](https://github.com/rails/jbuilder/commit/7c1a5f25603ec1f4e51fba3dbba9db23726a5d69)
61
+ * [Add AC::Helpers module to jbuilder for api only apps](https://github.com/rails/jbuilder/commit/7cf1d1eb7d125caf38309b5427952030011c1aa0)
62
+
3
63
  2.2.16
4
64
  ------
5
65
 
@@ -13,12 +73,12 @@
13
73
  2.2.13
14
74
  ------
15
75
 
16
- * Several peformance optimizations: [#260](https://github.com/rails/jbuilder/pull/260) & [#261](https://github.com/rails/jbuilder/pull/261)
76
+ * Several performance optimizations: [#260](https://github.com/rails/jbuilder/pull/260) & [#261](https://github.com/rails/jbuilder/pull/261)
17
77
 
18
78
  2.2.12
19
79
  ------
20
80
 
21
- * [Replace explici block calls with yield for performance](https://github.com/rails/jbuilder/commit/3184f941276ad03a071cf977133d1a32302afa47)
81
+ * [Replace explicit block calls with yield for performance](https://github.com/rails/jbuilder/commit/3184f941276ad03a071cf977133d1a32302afa47)
22
82
 
23
83
  2.2.11
24
84
  ------
@@ -162,7 +222,7 @@
162
222
  -----
163
223
  * [Add quick collection attribute extraction](https://github.com/rails/jbuilder/commit/c2b966cf653ea4264fbb008b8cc6ce5359ebe40a)
164
224
  * [Block has priority over attributes extraction](https://github.com/rails/jbuilder/commit/77c24766362c02769d81dac000b1879a9e4d4a00)
165
- * [Meaningfull error messages when adding properties to null](https://github.com/rails/jbuilder/commit/e26764602e34b3772e57e730763d512e59489e3b)
225
+ * [Meaningful error messages when adding properties to null](https://github.com/rails/jbuilder/commit/e26764602e34b3772e57e730763d512e59489e3b)
166
226
  * [Do not enforce template format, enforce handlers instead](https://github.com/rails/jbuilder/commit/72576755224b15da45e50cbea877679800ab1398)
167
227
 
168
228
  1.3.0
@@ -171,7 +231,7 @@
171
231
 
172
232
  1.2.1
173
233
  -----
174
- * [Added explicit dependency for MultiJson](https://github.com/rails/jbuilder/commit/4d58eacb6cd613679fb243484ff73a79bbbff2d2
234
+ * [Added explicit dependency for MultiJson](https://github.com/rails/jbuilder/commit/4d58eacb6cd613679fb243484ff73a79bbbff2d2)
175
235
 
176
236
  1.2.0
177
237
  -----
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,108 @@
1
+ Contributing to Jbuilder
2
+ =====================
3
+
4
+ [![Build Status](https://api.travis-ci.org/rails/jbuilder.svg?branch=master)][travis]
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
+
9
+ [travis]: https://travis-ci.org/rails/jbuilder
10
+ [gem]: https://rubygems.org/gems/jbuilder
11
+ [codeclimate]: https://codeclimate.com/github/rails/jbuilder
12
+ [gemnasium]: https://gemnasium.com/rails/jbuilder
13
+
14
+ Jbuilder is work of [many contributors](https://github.com/rails/jbuilder/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/rails/jbuilder/pulls), [propose features and discuss issues](https://github.com/rails/jbuilder/issues).
15
+
16
+ #### Fork the Project
17
+
18
+ Fork the [project on Github](https://github.com/rails/jbuilder) and check out your copy.
19
+
20
+ ```
21
+ git clone https://github.com/contributor/jbuilder.git
22
+ cd jbuilder
23
+ git remote add upstream https://github.com/rails/jbuilder.git
24
+ ```
25
+
26
+ #### Create a Topic Branch
27
+
28
+ Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
29
+
30
+ ```
31
+ git checkout master
32
+ git pull upstream master
33
+ git checkout -b my-feature-branch
34
+ ```
35
+
36
+ #### Bundle Install and Test
37
+
38
+ Ensure that you can build the project and run tests.
39
+
40
+ ```
41
+ bundle install
42
+ appraisal install
43
+ appraisal rake test
44
+ ```
45
+
46
+ #### Write Tests
47
+
48
+ Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to [test](test).
49
+
50
+ We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
51
+
52
+ #### Write Code
53
+
54
+ Implement your feature or bug fix.
55
+
56
+ Make sure that `appraisal rake test` completes without errors.
57
+
58
+ #### Write Documentation
59
+
60
+ Document any external behavior in the [README](README.md).
61
+
62
+ #### Commit Changes
63
+
64
+ Make sure git knows your name and email address:
65
+
66
+ ```
67
+ git config --global user.name "Your Name"
68
+ git config --global user.email "contributor@example.com"
69
+ ```
70
+
71
+ Writing good commit logs is important. A commit log should describe what changed and why.
72
+
73
+ ```
74
+ git add ...
75
+ git commit
76
+ ```
77
+
78
+ #### Push
79
+
80
+ ```
81
+ git push origin my-feature-branch
82
+ ```
83
+
84
+ #### Make a Pull Request
85
+
86
+ Visit your forked repo and click the 'New pull request' button. Select your feature branch, fill out the form, and click the 'Create pull request' button. Pull requests are usually reviewed within a few days.
87
+
88
+ #### Rebase
89
+
90
+ If you've been working on a change for a while, rebase with upstream/master.
91
+
92
+ ```
93
+ git fetch upstream
94
+ git rebase upstream/master
95
+ git push origin my-feature-branch -f
96
+ ```
97
+
98
+ #### Check on Your Pull Request
99
+
100
+ Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
101
+
102
+ #### Be Patient
103
+
104
+ It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang in there!
105
+
106
+ #### Thank You
107
+
108
+ Please do know that we really appreciate and value your time and work. We love you, really.
data/Gemfile CHANGED
@@ -5,3 +5,4 @@ gemspec
5
5
  gem "rake"
6
6
  gem "mocha", require: false
7
7
  gem "appraisal"
8
+ gem "pry"
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2014 David Heinemeier Hansson, 37signals
1
+ Copyright (c) 2011-2017 David Heinemeier Hansson, 37signals
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,22 +1,12 @@
1
1
  # Jbuilder
2
2
 
3
- [![Build Status](https://api.travis-ci.org/rails/jbuilder.svg)][travis]
4
- [![Gem Version](http://img.shields.io/gem/v/jbuilder.svg)][gem]
5
- [![Code Climate](http://img.shields.io/codeclimate/github/rails/jbuilder.svg)][codeclimate]
6
- [![Dependencies Status](http://img.shields.io/gemnasium/rails/jbuilder.svg)][gemnasium]
7
-
8
- [travis]: https://travis-ci.org/rails/jbuilder
9
- [gem]: https://rubygems.org/gems/jbuilder
10
- [codeclimate]: https://codeclimate.com/github/rails/jbuilder
11
- [gemnasium]: https://gemnasium.com/rails/jbuilder
12
-
13
3
  Jbuilder gives you a simple DSL for declaring JSON structures that beats
14
- massaging giant hash structures. This is particularly helpful when the
4
+ manipulating giant hash structures. This is particularly helpful when the
15
5
  generation process is fraught with conditionals and loops. Here's a simple
16
6
  example:
17
7
 
18
8
  ``` ruby
19
- # app/views/message/show.json.jbuilder
9
+ # app/views/messages/show.json.jbuilder
20
10
 
21
11
  json.content format_content(@message.content)
22
12
  json.(@message, :created_at, :updated_at)
@@ -74,7 +64,7 @@ json.set! :author do
74
64
  json.set! :name, 'David'
75
65
  end
76
66
 
77
- # => "author": { "name": "David" }
67
+ # => {"author": { "name": "David" }}
78
68
  ```
79
69
 
80
70
  Top level arrays can be handled directly. Useful for index and other collection actions.
@@ -134,7 +124,7 @@ company.to_builder.target!
134
124
  ```
135
125
 
136
126
  You can either use Jbuilder stand-alone or directly as an ActionView template
137
- language. When required in Rails, you can create views ala show.json.jbuilder
127
+ language. When required in Rails, you can create views a la show.json.jbuilder
138
128
  (the json is already yielded):
139
129
 
140
130
  ``` ruby
@@ -178,7 +168,7 @@ json.partial! partial: 'posts/post', collection: @posts, as: :post
178
168
 
179
169
  # or
180
170
 
181
- json.comments @post.comments, partial: 'comment/comment', as: :comment
171
+ json.comments @post.comments, partial: 'comments/comment', as: :comment
182
172
  ```
183
173
 
184
174
  You can pass any objects into partial templates with or without `:locals` option.
@@ -206,6 +196,15 @@ json.author do
206
196
  end
207
197
  ```
208
198
 
199
+ To prevent Jbuilder from including null values in the output, you can use the `ignore_nil!` method:
200
+
201
+ ```ruby
202
+ json.ignore_nil!
203
+ json.foo nil
204
+ json.bar "bar"
205
+ # => { "bar": "bar" }
206
+ ```
207
+
209
208
  Fragment caching is supported, it uses `Rails.cache` and works like caching in
210
209
  HTML templates:
211
210
 
@@ -258,3 +257,13 @@ for MultiJson:
258
257
  require 'multi_json'
259
258
  MultiJson.use :yajl
260
259
  ```
260
+
261
+ ## Contributing to Jbuilder
262
+
263
+ Jbuilder is the work of many contributors. You're encouraged to submit pull requests, propose
264
+ features and discuss issues.
265
+
266
+ See [CONTRIBUTING](CONTRIBUTING.md).
267
+
268
+ ## License
269
+ Jbuilder is released under the [MIT License](http://www.opensource.org/licenses/MIT).
@@ -5,8 +5,10 @@ source "https://rubygems.org"
5
5
  gem "rake"
6
6
  gem "mocha", :require => false
7
7
  gem "appraisal"
8
+ gem "pry"
8
9
  gem "test-unit"
9
10
  gem "railties", "~> 3.0.0"
10
11
  gem "actionpack", "~> 3.0.0"
12
+ gem "activemodel", "~> 3.0.0"
11
13
 
12
14
  gemspec :path => "../"
@@ -5,8 +5,10 @@ source "https://rubygems.org"
5
5
  gem "rake"
6
6
  gem "mocha", :require => false
7
7
  gem "appraisal"
8
+ gem "pry"
8
9
  gem "test-unit"
9
10
  gem "railties", "~> 3.1.0"
10
11
  gem "actionpack", "~> 3.1.0"
12
+ gem "activemodel", "~> 3.1.0"
11
13
 
12
14
  gemspec :path => "../"
@@ -5,8 +5,10 @@ source "https://rubygems.org"
5
5
  gem "rake"
6
6
  gem "mocha", :require => false
7
7
  gem "appraisal"
8
+ gem "pry"
8
9
  gem "test-unit"
9
10
  gem "railties", "~> 3.2.0"
10
11
  gem "actionpack", "~> 3.2.0"
12
+ gem "activemodel", "~> 3.2.0"
11
13
 
12
14
  gemspec :path => "../"
@@ -5,7 +5,9 @@ source "https://rubygems.org"
5
5
  gem "rake"
6
6
  gem "mocha", :require => false
7
7
  gem "appraisal"
8
+ gem "pry"
8
9
  gem "railties", "~> 4.0.0"
9
10
  gem "actionpack", "~> 4.0.0"
11
+ gem "activemodel", "~> 4.0.0"
10
12
 
11
13
  gemspec :path => "../"
@@ -5,7 +5,9 @@ source "https://rubygems.org"
5
5
  gem "rake"
6
6
  gem "mocha", :require => false
7
7
  gem "appraisal"
8
+ gem "pry"
8
9
  gem "railties", "~> 4.1.0"
9
10
  gem "actionpack", "~> 4.1.0"
11
+ gem "activemodel", "~> 4.1.0"
10
12
 
11
13
  gemspec :path => "../"
@@ -5,7 +5,10 @@ source "https://rubygems.org"
5
5
  gem "rake"
6
6
  gem "mocha", :require => false
7
7
  gem "appraisal"
8
+ gem "pry"
8
9
  gem "railties", "~> 4.2.0"
9
10
  gem "actionpack", "~> 4.2.0"
11
+ gem "activemodel", "~> 4.2.0"
12
+ gem "nokogiri", "< 1.7" if RUBY_VERSION < "2.1"
10
13
 
11
14
  gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake"
6
+ gem "mocha", :require => false
7
+ gem "appraisal"
8
+ gem "pry"
9
+ gem "railties", "~> 5.0.0"
10
+ gem "actionpack", "~> 5.0.0"
11
+ gem "activemodel", "~> 5.0.0"
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake"
6
+ gem "mocha", :require => false
7
+ gem "appraisal"
8
+ gem "pry"
9
+ gem "railties", ">= 5.1.0", "< 5.2"
10
+ gem "actionpack", ">= 5.1.0", "< 5.2"
11
+ gem "activemodel", ">= 5.1.0", "< 5.2"
12
+
13
+ gemspec :path => "../"
data/jbuilder.gemspec CHANGED
@@ -1,16 +1,16 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jbuilder'
3
- s.version = '2.2.16'
4
- s.authors = ['David Heinemeier Hansson', 'Pavel Pravosud']
5
- s.email = ['david@37signals.com', 'pavel@pravosud.com']
3
+ s.version = '2.6.4'
4
+ s.authors = ['David Heinemeier Hansson']
5
+ s.email = ['david@37signals.com']
6
6
  s.summary = 'Create JSON structures via a Builder-style DSL'
7
7
  s.homepage = 'https://github.com/rails/jbuilder'
8
8
  s.license = 'MIT'
9
9
 
10
10
  s.required_ruby_version = '>= 1.9.3'
11
11
 
12
- s.add_dependency 'activesupport', '>= 3.0.0', '< 5'
13
- s.add_dependency 'multi_json', '~> 1.2'
12
+ s.add_dependency 'activesupport', '>= 3.0.0'
13
+ s.add_dependency 'multi_json', '>= 1.2'
14
14
 
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- test/*`.split("\n")
@@ -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
 
@@ -4,9 +4,9 @@ require 'rails/generators/rails/scaffold_controller/scaffold_controller_generato
4
4
  module Rails
5
5
  module Generators
6
6
  class ScaffoldControllerGenerator
7
- source_paths.unshift File.expand_path('../templates', __FILE__)
7
+ source_paths << File.expand_path('../templates', __FILE__)
8
8
 
9
- hook_for :jbuilder, default: true
9
+ hook_for :jbuilder, type: :boolean, default: true
10
10
  end
11
11
  end
12
12
  end
@@ -0,0 +1,63 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_file_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= controller_class_name %>Controller < ApplicationController
7
+ before_action :set_<%= singular_table_name %>, only: [:show, :update, :destroy]
8
+
9
+ # GET <%= route_url %>
10
+ # GET <%= route_url %>.json
11
+ def index
12
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
13
+ end
14
+
15
+ # GET <%= route_url %>/1
16
+ # GET <%= route_url %>/1.json
17
+ def show
18
+ end
19
+
20
+ # POST <%= route_url %>
21
+ # POST <%= route_url %>.json
22
+ def create
23
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
24
+
25
+ if @<%= orm_instance.save %>
26
+ render :show, status: :created, location: <%= "@#{singular_table_name}" %>
27
+ else
28
+ render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity
29
+ end
30
+ end
31
+
32
+ # PATCH/PUT <%= route_url %>/1
33
+ # PATCH/PUT <%= route_url %>/1.json
34
+ def update
35
+ if @<%= orm_instance.update("#{singular_table_name}_params") %>
36
+ render :show, status: :ok, location: <%= "@#{singular_table_name}" %>
37
+ else
38
+ render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity
39
+ end
40
+ end
41
+
42
+ # DELETE <%= route_url %>/1
43
+ # DELETE <%= route_url %>/1.json
44
+ def destroy
45
+ @<%= orm_instance.destroy %>
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_<%= singular_table_name %>
51
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
52
+ end
53
+
54
+ # Never trust parameters from the scary internet, only allow the white list through.
55
+ def <%= "#{singular_table_name}_params" %>
56
+ <%- if attributes_names.empty? -%>
57
+ params.fetch(<%= ":#{singular_table_name}" %>, {})
58
+ <%- else -%>
59
+ params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
60
+ <%- end -%>
61
+ end
62
+ end
63
+ <% end -%>
@@ -75,7 +75,7 @@ class <%= controller_class_name %>Controller < ApplicationController
75
75
  # Never trust parameters from the scary internet, only allow the white list through.
76
76
  def <%= "#{singular_table_name}_params" %>
77
77
  <%- if attributes_names.empty? -%>
78
- params[<%= ":#{singular_table_name}" %>]
78
+ params.fetch(<%= ":#{singular_table_name}" %>, {})
79
79
  <%- else -%>
80
80
  params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
81
81
  <%- end -%>
@@ -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)