jb 0.8.0 → 0.8.1

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
  SHA256:
3
- metadata.gz: '09fa54e898f00cadade145bbad06c48b3a110d780cb7caa61f652f3b5b9f91d4'
4
- data.tar.gz: 8f7d703998d358b7be99b5a3dec6779b816ef135cd33c434aad95bf151205c13
3
+ metadata.gz: 59c07bc2a0d9dd1b6e304a1f6c3037ccd2234cda1a5273ff8f0d12bb1e814270
4
+ data.tar.gz: 545f3b027f587ab30de9d2e93fad5b3ea399ad8a6695b9090d3e7b55085ab505
5
5
  SHA512:
6
- metadata.gz: b1ccca7074f5b936db1d12e164404adaee0916255f4ee0bc2d92f080d5948e7d0cd661a18feaf29895842424377992f05807a9f498244af7617fef9d0722812c
7
- data.tar.gz: 8564a73f19b09a5a9a75e4f07e92811a90b924de039832e4642ebb5b119403cb20a5c05023004b446ea8331f30b1129747cbc87db8af0aaa75183a1e5e11f063
6
+ metadata.gz: b9ef88b516a5bee2132af07f394a00f03bfda2928764b538189aa061d9af1c60c4942cb874d416e5d36265839bac1df8463cb5c8e795536000a903bbbecadc25
7
+ data.tar.gz: e0b272e833109cd995104fa033208eca904922a3ef66148dcbe583665917393efd99120800605ae9c35c3527f2530ee96762ee5bb991f650538f7dd0c896fab7
@@ -0,0 +1,63 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ schedule:
7
+ - cron: '26 13 * * *'
8
+
9
+ jobs:
10
+ build:
11
+ strategy:
12
+ matrix:
13
+ ruby_version: [ruby-head, '3.2', '3.1', '3.0', '2.7']
14
+ rails_version: [edge, '7.0', '6.1']
15
+
16
+ include:
17
+ - ruby_version: '3.0'
18
+ rails_version: '6.0'
19
+
20
+ - ruby_version: '2.7'
21
+ rails_version: '6.0'
22
+
23
+ - ruby_version: '2.6'
24
+ rails_version: '6.1'
25
+ - ruby_version: '2.6'
26
+ rails_version: '6.0'
27
+ - ruby_version: '2.6'
28
+ rails_version: '5.2'
29
+ - ruby_version: '2.6'
30
+ rails_version: '5.1'
31
+ - ruby_version: '2.6'
32
+ rails_version: '5.0'
33
+ - ruby_version: '2.6'
34
+ rails_version: '4.2'
35
+ bundler_version: '1'
36
+
37
+ - ruby_version: '2.5'
38
+ rails_version: '5.2'
39
+ - ruby_version: '2.5'
40
+ rails_version: '4.2'
41
+ bundler_version: '1'
42
+
43
+ - ruby_version: '2.4'
44
+ rails_version: '5.2'
45
+ - ruby_version: '2.4'
46
+ rails_version: '4.2'
47
+ bundler_version: '1'
48
+
49
+ env:
50
+ RAILS_VERSION: ${{ matrix.rails_version }}
51
+
52
+ runs-on: ubuntu-latest
53
+
54
+ steps:
55
+ - uses: actions/checkout@v4
56
+ - uses: ruby/setup-ruby@v1
57
+ with:
58
+ ruby-version: ${{ matrix.ruby_version }}
59
+ bundler: ${{ matrix.bundler_version }}
60
+ bundler-cache: true
61
+ continue-on-error: ${{ (matrix.ruby_version == 'ruby-head') || (matrix.allow_failures == 'true') }}
62
+ - run: bundle exec rake
63
+ continue-on-error: ${{ (matrix.ruby_version == 'ruby-head') || (matrix.allow_failures == 'true') }}
data/Gemfile CHANGED
@@ -5,5 +5,18 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in jb.gemspec
6
6
  gemspec
7
7
 
8
+ if ENV['RAILS_VERSION'] == 'edge'
9
+ gem 'rails', git: 'https://github.com/rails/rails.git', branch: 'main'
10
+ elsif ENV['RAILS_VERSION']
11
+ gem 'rails', "~> #{ENV['RAILS_VERSION']}.0"
12
+ else
13
+ gem 'rails'
14
+ end
15
+
16
+ gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
17
+ gem 'loofah', RUBY_VERSION < '2.5' ? '< 2.21.0' : '>= 0'
18
+ gem 'selenium-webdriver'
19
+ gem 'net-smtp' if RUBY_VERSION >= '3.1'
20
+
8
21
  # For benchmarking
9
22
  gem 'action_args'
data/README.md CHANGED
@@ -21,19 +21,34 @@ Put a template file named `*.jb` in your Rails app's `app/views/*` directory, an
21
21
 
22
22
  ## Features
23
23
 
24
- * No ugly builder syntax
24
+ * No original builder syntax that you have to learn
25
25
  * No `method_missing` calls
26
26
  * `render_partial` with :collection option actually renders the collection (unlike Jbuilder)
27
27
 
28
28
 
29
29
  ## Syntax
30
30
 
31
- A `.jb` template should contain Ruby code that returns any Ruby Object that responds_to `to_json` (generally Hash or Array).
32
- Then the return value will be `to_json`ed to a JSON String.
31
+ A `.jb` template should contain Ruby code that returns any Ruby Object that responds\_to `to_json` (generally Hash or Array). Then the return value will be `to_json`ed to a JSON String.
33
32
 
34
33
 
35
34
  ## Examples
36
35
 
36
+ Let's start with a very simple one. Just write a Ruby Hash as a template:
37
+
38
+ ``` ruby
39
+ {language: 'Ruby', author: {name: 'Matz'}}
40
+ ```
41
+
42
+ This renders the following JSON text:
43
+
44
+ ``` javascript
45
+ {"language": "Ruby", "author": {"name": "Matz"}}
46
+ ```
47
+
48
+ Note that modern Ruby Hash syntax pretty much looks alike JSON syntax. It's super-straight forward. Who needs a DSL to do this?
49
+
50
+ Next one is a little bit advanced usage. The template doesn't have to be a single literal but can be any code that returns a Hash object:
51
+
37
52
  ``` ruby
38
53
  # app/views/messages/show.json.jb
39
54
 
@@ -97,18 +112,17 @@ This will build the following structure:
97
112
  }
98
113
  ```
99
114
 
100
- To define attribute and structure names dynamically, just use Ruby Hash.
101
- Note that modern Ruby Hash syntax pretty much looks alike JSON syntax.
102
- It's super-straight forward. Who needs a DSL to do this?
115
+ If you want to define attribute and structure names dynamically, of course you still can do this with a Ruby Hash literal.
103
116
 
104
117
  ``` ruby
105
- {author: {name: 'Matz'}}
118
+ # model_name, column_name = :author, :name
119
+
120
+ {model_name => {column_name => 'Matz'}}
106
121
 
107
122
  # => {"author": {"name": "Matz"}}
108
123
  ```
109
124
 
110
- Top level arrays can be handled directly. Useful for index and other collection actions.
111
- And you know, Ruby is such a powerful language for manipulating collections:
125
+ Top level arrays can be handled directly. Useful for index and other collection actions. And you know, Ruby is such a powerful language for manipulating collections:
112
126
 
113
127
  ``` ruby
114
128
  # @comments = @post.comments
@@ -136,11 +150,7 @@ Jb has no special DSL method for extracting attributes from array directly, but
136
150
  # => [{"id": 1, "name": "Matz"}, {"id": 2, "name": "Nobu"}]
137
151
  ```
138
152
 
139
- You can use Jb directly as an Action View template language.
140
- When required in Rails, you can create views ala show.json.jb.
141
- You'll notice in the following example that the `.jb` template
142
- doesn't have to be one big Ruby Hash literal as a whole
143
- but it can be any Ruby code that finally returns a Hash instance.
153
+ You can use Jb directly as an Action View template language. When required in Rails, you can create views ala `show.json.jb`. You'll notice in the following example that the `.jb` template doesn't have to be one big Ruby Hash literal as a whole but it can be any Ruby code that finally returns a Hash instance.
144
154
 
145
155
  ``` ruby
146
156
  # Any helpers available to views are available in the template
@@ -163,10 +173,7 @@ end
163
173
  json
164
174
  ```
165
175
 
166
- You can use partials as well. The following will render the file
167
- `views/comments/_comments.json.jb`, and set a local variable
168
- `comments` with all this message's comments, which you can use inside
169
- the partial.
176
+ You can use partials as well. The following will render the file `views/comments/_comments.json.jb`, and set a local variable `comments` with all this message's comments, which you can use inside the partial.
170
177
 
171
178
  ```ruby
172
179
  render 'comments/comments', comments: @message.comments
@@ -178,8 +185,7 @@ It's also possible to render collections of partials:
178
185
  render partial: 'posts/post', collection: @posts, as: :post
179
186
  ```
180
187
 
181
- > NOTE: Don't use `render @post.comments` because if the collection is empty,
182
- `render` will return `nil` instead of an empty array.
188
+ > NOTE: Don't use `render @post.comments` because if the collection is empty, `render` will return `nil` instead of an empty array.
183
189
 
184
190
  You can pass any objects into partial templates with or without `:locals` option.
185
191
 
@@ -211,8 +217,7 @@ end
211
217
 
212
218
 
213
219
  ## The Generator
214
- Jb extends the default Rails scaffold generator and adds some .jb templates.
215
- If you don't need them, please configure like so.
220
+ Jb extends the default Rails scaffold generator and adds some `.jb` templates. If you don't need them, please configure like so.
216
221
 
217
222
  ```ruby
218
223
  Rails.application.config.generators.jb false
data/jb.gemspec CHANGED
@@ -26,5 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'test-unit-rails'
27
27
  spec.add_development_dependency 'rails'
28
28
  spec.add_development_dependency 'action_args'
29
- spec.add_development_dependency 'byebug'
29
+ spec.add_development_dependency 'debug'
30
+ spec.add_development_dependency 'selenium-webdriver'
30
31
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # Mokey-patches for Action View 4 and 5
2
+ # Monkey-patches for Action View 4 and 5
3
3
 
4
4
  module Jb
5
5
  module PartialRenderer
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # Mokey-patches for Action View 6+
2
+ # Monkey-patches for Action View 6+
3
3
 
4
4
  module Jb
5
5
  # A monkey-patch that converts non-partial result to a JSON String
@@ -13,6 +13,19 @@ module Jb
13
13
  end
14
14
  end
15
15
 
16
+ # Rails 7.1+: A monkey-patch not to stringify rendered object from JB templates
17
+ module BaseToSCanceller
18
+ def _run(method, template, *, **)
19
+ val = super
20
+ if template.respond_to?(:handler) && (template.handler == Jb::Handler)
21
+ def val.to_s
22
+ self
23
+ end
24
+ end
25
+ val
26
+ end
27
+ end
28
+
16
29
  # Rails 6.1+: A monkey-patch for jb template collection result's `body` not to return a String but an Array
17
30
  module CollectionRendererExtension
18
31
  private def render_collection(_collection, _view, _path, template, _layout, _block)
@@ -45,6 +58,7 @@ module Jb
45
58
  end
46
59
 
47
60
  ::ActionView::TemplateRenderer.prepend ::Jb::TemplateRenderer::JSONizer
61
+ ::ActionView::Base.prepend ::Jb::BaseToSCanceller if (ActionView::VERSION::MAJOR >= 7) && (ActionView::VERSION::MINOR >= 1)
48
62
  begin
49
63
  # ActionView::CollectionRenderer is a newly added class since 6.1
50
64
  ::ActionView::CollectionRenderer.prepend ::Jb::CollectionRendererExtension
data/lib/jb/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jb
4
- VERSION = '0.8.0'
4
+ VERSION = '0.8.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-27 00:00:00.000000000 Z
11
+ date: 2023-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,7 +81,21 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: byebug
84
+ name: debug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: selenium-webdriver
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
@@ -101,8 +115,8 @@ executables: []
101
115
  extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
118
+ - ".github/workflows/main.yml"
104
119
  - ".gitignore"
105
- - ".travis.yml"
106
120
  - Gemfile
107
121
  - LICENSE.txt
108
122
  - README.md
@@ -111,12 +125,6 @@ files:
111
125
  - bin/console
112
126
  - bin/setup
113
127
  - gemfiles/benchmark.gemfile
114
- - gemfiles/rails_42.gemfile
115
- - gemfiles/rails_50.gemfile
116
- - gemfiles/rails_51.gemfile
117
- - gemfiles/rails_52.gemfile
118
- - gemfiles/rails_60.gemfile
119
- - gemfiles/rails_edge.gemfile
120
128
  - jb.gemspec
121
129
  - lib/generators/rails/jb_generator.rb
122
130
  - lib/generators/rails/scaffold_controller_generator.rb
@@ -147,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
155
  - !ruby/object:Gem::Version
148
156
  version: '0'
149
157
  requirements: []
150
- rubygems_version: 3.1.4
158
+ rubygems_version: 3.5.0.dev
151
159
  signing_key:
152
160
  specification_version: 4
153
161
  summary: Faster and simpler Jbuilder alternative
data/.travis.yml DELETED
@@ -1,33 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.7.2
5
- - 2.6.6
6
- - 2.5.8
7
-
8
- gemfile:
9
- - gemfiles/rails_60.gemfile
10
- - gemfiles/rails_52.gemfile
11
- - gemfiles/rails_51.gemfile
12
- - gemfiles/rails_50.gemfile
13
- - gemfiles/rails_42.gemfile
14
-
15
- matrix:
16
- exclude:
17
- - rvm: 2.7.2
18
- gemfile: gemfiles/rails_52.gemfile
19
- - rvm: 2.7.2
20
- gemfile: gemfiles/rails_51.gemfile
21
- - rvm: 2.7.2
22
- gemfile: gemfiles/rails_50.gemfile
23
- - rvm: 2.7.2
24
- gemfile: gemfiles/rails_42.gemfile
25
-
26
- include:
27
- - rvm: 2.7.2
28
- gemfile: gemfiles/rails_edge.gemfile
29
- - rvm: ruby-head
30
- gemfile: gemfiles/rails_edge.gemfile
31
-
32
- allow_failures:
33
- - rvm: ruby-head
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gemspec :path => '../'
6
-
7
- gem 'rails', '~> 4.2.0'
8
- gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gemspec :path => '../'
6
-
7
- gem 'rails', '~> 5.0.0'
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gemspec :path => '../'
6
-
7
- gem 'rails', '~> 5.1.0'
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gemspec :path => '../'
6
-
7
- gem 'rails', '~> 5.2.0'
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gemspec :path => '../'
6
-
7
- gem 'rails', '~> 6.0.0'
8
- gem 'selenium-webdriver'
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gemspec :path => '../'
6
-
7
- git_source(:github) do |repo_name|
8
- repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
9
- "https://github.com/#{repo_name}.git"
10
- end
11
-
12
- github 'rails/rails' do
13
- gem 'rails'
14
- end
15
-
16
- gem 'selenium-webdriver'