breezy 0.9.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/lib/breezy.rb +10 -15
  3. data/lib/breezy/helpers.rb +541 -11
  4. data/lib/breezy/redirection.rb +30 -0
  5. data/lib/breezy/xhr_headers.rb +0 -10
  6. data/lib/generators/rails/breezy_generator.rb +13 -4
  7. data/lib/generators/rails/templates/_form.json.props +13 -0
  8. data/lib/generators/rails/templates/controller.rb.tt +0 -3
  9. data/lib/generators/rails/templates/edit.json.props +14 -0
  10. data/lib/generators/rails/templates/index.json.props +13 -0
  11. data/lib/generators/rails/templates/new.json.props +15 -0
  12. data/lib/generators/rails/templates/{show.js.props → show.json.props} +0 -2
  13. data/lib/generators/rails/templates/web/base.jsx +3 -4
  14. data/lib/generators/rails/templates/web/edit.html.erb +11 -0
  15. data/lib/generators/rails/templates/web/edit.jsx +22 -27
  16. data/lib/generators/rails/templates/web/index.html.erb +10 -0
  17. data/lib/generators/rails/templates/web/index.jsx +13 -9
  18. data/lib/generators/rails/templates/web/new.html.erb +11 -0
  19. data/lib/generators/rails/templates/web/new.jsx +19 -24
  20. data/lib/generators/rails/templates/web/show.html.erb +12 -0
  21. data/lib/generators/rails/templates/web/show.jsx +3 -3
  22. data/lib/install/templates/web/action_creators.js +14 -0
  23. data/lib/install/templates/web/actions.js +3 -0
  24. data/lib/install/templates/web/application.js +30 -5
  25. data/lib/install/templates/web/application.json.props +25 -0
  26. data/lib/install/templates/web/initializer.rb +1 -6
  27. data/lib/install/templates/web/reducer.js +28 -0
  28. data/lib/install/web.rb +27 -40
  29. data/lib/tasks/install.rake +11 -7
  30. data/test/helpers_test.rb +23 -0
  31. data/test/render_test.rb +25 -92
  32. data/test/test_helper.rb +2 -2
  33. metadata +32 -30
  34. data/app/views/breezy/response.html.erb +0 -0
  35. data/lib/breezy/configuration.rb +0 -35
  36. data/lib/breezy/render.rb +0 -37
  37. data/lib/generators/rails/templates/edit.js.props +0 -16
  38. data/lib/generators/rails/templates/index.js.props +0 -14
  39. data/lib/generators/rails/templates/new.js.props +0 -4
  40. data/lib/generators/rails/templates/web/form.jsx +0 -31
  41. data/lib/install/templates/web/babelrc +0 -33
  42. data/test/breezy_test.rb +0 -125
  43. data/test/configuration_test.rb +0 -36
@@ -5,10 +5,10 @@ require 'action_controller'
5
5
  require 'breezy'
6
6
  require "active_support"
7
7
  require 'active_record'
8
- require 'active_support/testing/autorun' if Rails.version >= '4'
8
+ require 'active_support/testing/autorun'
9
9
  require 'active_support/test_case'
10
10
 
11
- require 'breezy_template'
11
+ require 'props_template'
12
12
 
13
13
  ActiveSupport::TestCase.test_order = :random if ActiveSupport::TestCase.respond_to?(:test_order=)
14
14
  ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breezy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johny Ho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-30 00:00:00.000000000 Z
11
+ date: 2020-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: 6.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: 6.0.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: breezy_template
28
+ name: props_template
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.9.0
33
+ version: 0.14.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.9.0
40
+ version: 0.14.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: webpacker
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activerecord
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '5.0'
61
+ version: '6.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '5.0'
68
+ version: '6.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -156,35 +156,39 @@ executables: []
156
156
  extensions: []
157
157
  extra_rdoc_files: []
158
158
  files:
159
- - app/views/breezy/response.html.erb
160
159
  - lib/breezy.rb
161
- - lib/breezy/configuration.rb
162
160
  - lib/breezy/helpers.rb
163
- - lib/breezy/render.rb
161
+ - lib/breezy/redirection.rb
164
162
  - lib/breezy/x_domain_blocker.rb
165
163
  - lib/breezy/xhr_headers.rb
166
164
  - lib/breezy/xhr_url_for.rb
167
165
  - lib/generators/rails/breezy_generator.rb
168
166
  - lib/generators/rails/scaffold_controller_generator.rb
167
+ - lib/generators/rails/templates/_form.json.props
169
168
  - lib/generators/rails/templates/controller.rb.tt
170
- - lib/generators/rails/templates/edit.js.props
171
- - lib/generators/rails/templates/index.js.props
172
- - lib/generators/rails/templates/new.js.props
173
- - lib/generators/rails/templates/show.js.props
169
+ - lib/generators/rails/templates/edit.json.props
170
+ - lib/generators/rails/templates/index.json.props
171
+ - lib/generators/rails/templates/new.json.props
172
+ - lib/generators/rails/templates/show.json.props
174
173
  - lib/generators/rails/templates/web/base.jsx
174
+ - lib/generators/rails/templates/web/edit.html.erb
175
175
  - lib/generators/rails/templates/web/edit.jsx
176
- - lib/generators/rails/templates/web/form.jsx
176
+ - lib/generators/rails/templates/web/index.html.erb
177
177
  - lib/generators/rails/templates/web/index.jsx
178
+ - lib/generators/rails/templates/web/new.html.erb
178
179
  - lib/generators/rails/templates/web/new.jsx
180
+ - lib/generators/rails/templates/web/show.html.erb
179
181
  - lib/generators/rails/templates/web/show.jsx
182
+ - lib/install/templates/web/action_creators.js
183
+ - lib/install/templates/web/actions.js
180
184
  - lib/install/templates/web/application.js
181
- - lib/install/templates/web/babelrc
185
+ - lib/install/templates/web/application.json.props
182
186
  - lib/install/templates/web/initializer.rb
187
+ - lib/install/templates/web/reducer.js
183
188
  - lib/install/web.rb
184
189
  - lib/tasks/install.rake
185
- - test/breezy_test.rb
186
- - test/configuration_test.rb
187
190
  - test/engine_test.rb
191
+ - test/helpers_test.rb
188
192
  - test/render_test.rb
189
193
  - test/test_helper.rb
190
194
  homepage: https://github.com/jho406/breezy/
@@ -206,14 +210,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
210
  - !ruby/object:Gem::Version
207
211
  version: '0'
208
212
  requirements: []
209
- rubyforge_project:
210
- rubygems_version: 2.5.2
213
+ rubygems_version: 3.0.3
211
214
  signing_key:
212
215
  specification_version: 4
213
216
  summary: Rails integration for BreezyJS
214
217
  test_files:
215
218
  - test/render_test.rb
216
- - test/configuration_test.rb
219
+ - test/helpers_test.rb
217
220
  - test/engine_test.rb
218
221
  - test/test_helper.rb
219
- - test/breezy_test.rb
File without changes
@@ -1,35 +0,0 @@
1
- module Breezy
2
- class Configuration
3
- def initialize
4
- BreezyTemplate.configuration = nil
5
- end
6
-
7
- def track_sprockets_assets=(assets)
8
- BreezyTemplate.configuration.track_sprockets_assets = assets
9
- end
10
-
11
- def track_sprockets_assets
12
- BreezyTemplate.configuration.track_sprockets_assets
13
- end
14
-
15
- def track_pack_assets=(assets)
16
- BreezyTemplate.configuration.track_pack_assets = assets
17
- end
18
-
19
- def track_pack_assets
20
- BreezyTemplate.configuration.track_pack_assets
21
- end
22
- end
23
-
24
- def self.configuration
25
- @configuration ||= Configuration.new
26
- end
27
-
28
- def self.configuration=(config)
29
- @configuration = config
30
- end
31
-
32
- def self.configure
33
- yield configuration
34
- end
35
- end
@@ -1,37 +0,0 @@
1
- module Breezy
2
- module Render
3
- def default_render(*args)
4
- if @_use_breezy
5
- render(*args)
6
- else
7
- super
8
- end
9
- end
10
-
11
- def render(*args, &block)
12
- if !@_use_breezy
13
- return super
14
- end
15
-
16
- render_options = args.extract_options!
17
- breezy_options = render_options.delete(:breezy)
18
-
19
- if !breezy_options
20
- breezy = {}
21
- end
22
-
23
- render_options[:locals] ||= {}
24
- render_options[:locals][:breezy] = breezy
25
-
26
- if request.format == :html
27
- original_formats = self.formats
28
- @_breezy_snippet = render_to_string(*args, render_options.merge(formats: [:js]))
29
- self.formats = original_formats
30
-
31
- render_options.reverse_merge!(formats: original_formats, template: 'breezy/response')
32
- end
33
-
34
- super(*args, render_options, &block)
35
- end
36
- end
37
- end
@@ -1,16 +0,0 @@
1
- json.flash flash.to_h
2
- json.errors @<%= singular_table_name %>.errors.to_h
3
-
4
- <%- attributes_list_with_timestamps.each do |attr| -%>
5
- json.<%=attr%> @<%= singular_table_name %>.<%=attr%>
6
- <%- end -%>
7
-
8
-
9
- json.attributes_for_form do
10
- <%- attributes_list.select{|attr| attr != :id }.each do |attr| -%>
11
- json.<%=attr%> @<%= singular_table_name %>.<%=attr%>
12
- <%- end -%>
13
- end
14
-
15
- json.post_path <%= singular_table_name%>_path(@<%=singular_table_name%>)
16
- json.posts_path <%= plural_table_name %>_path
@@ -1,14 +0,0 @@
1
- json.flash flash.to_h
2
-
3
- json.<%= plural_table_name %> do
4
- json.array! @<%= plural_table_name %> do |<%= singular_table_name %>|
5
- <%- attributes_list_with_timestamps.each do |attr| -%>
6
- json.<%=attr%> <%= singular_table_name %>.<%=attr%>
7
- <%- end -%>
8
- json.edit_post_path edit_<%=singular_table_name%>_path(<%=singular_table_name%>)
9
- json.post_path <%=singular_table_name%>_path(<%=singular_table_name%>)
10
- end
11
- end
12
-
13
-
14
- json.new_post_path new_<%= singular_table_name %>_path
@@ -1,4 +0,0 @@
1
- json.flash flash.to_h
2
- json.errors @<%= singular_table_name %>.errors.to_h
3
-
4
- json.<%= plural_table_name %>_path <%= plural_table_name %>_path
@@ -1,31 +0,0 @@
1
- import React from 'react'
2
- import { Formik, Form, Field } from 'formik';
3
-
4
- export default React.forwardRef(
5
- ({initialValues = {
6
- <%- attributes_list.select{|attr| attr != :id }.each do |attr| -%>
7
- <%=attr.to_s%>:'',
8
- <%- end -%>
9
- }, onSubmit}, ref) => {
10
- return (
11
- <Formik
12
- initialValues={initialValues}
13
- onSubmit={onSubmit}
14
- ref={ref}
15
- >
16
- {({ errors, touched, isSubmitting }) => (
17
- <Form>
18
- <%- attributes_list.select{|attr| attr != :id }.each do |attr| -%>
19
- <Field type="text" name="<%=attr.to_s%>" />
20
- {errors.<%=attr.to_s%> && touched.<%=attr.to_s%> && errors.<%=attr.to_s%>}
21
- <%- end -%>
22
-
23
- <button type="submit" disabled={isSubmitting}>
24
- Submit
25
- </button>
26
- </Form>
27
- )}
28
- </Formik>
29
- )
30
- }
31
- )
@@ -1,33 +0,0 @@
1
- {
2
- "presets": [
3
- [
4
- "env",
5
- {
6
- "modules": false,
7
- "targets": {
8
- "browsers": "> 1%",
9
- "uglify": true
10
- },
11
- "useBuiltIns": true
12
- }
13
- ],
14
- "react"
15
- ],
16
- "plugins": [
17
- "syntax-dynamic-import",
18
- ["module-resolver", {
19
- "root": ["./app"],
20
- "alias": {
21
- "views": "./app/views"
22
- }
23
- }],
24
- "transform-object-rest-spread",
25
- [
26
- "transform-class-properties",
27
- {
28
- "spec": true
29
- }
30
- ]
31
- ]
32
- }
33
-
@@ -1,125 +0,0 @@
1
- require 'test_helper'
2
-
3
- class BreezyController < TestController
4
- before_action do
5
- @_use_breezy = false
6
- end
7
-
8
- def simple_action
9
- render plain: ''
10
- end
11
-
12
- def redirect_to_same_origin
13
- redirect_to "#{request.protocol}#{request.host}/path"
14
- end
15
-
16
- def redirect_to_different_host
17
- redirect_to "#{request.protocol}foo.#{request.host}/path"
18
- end
19
-
20
- def redirect_to_different_protocol
21
- redirect_to "#{request.protocol == 'http://' ? 'https://' : 'http://'}#{request.host}/path"
22
- end
23
-
24
- def redirect_to_back
25
- if Rails.version >= "5.0"
26
- redirect_back(fallback_location: '/')
27
- else
28
- redirect_to :back
29
- end
30
- end
31
-
32
- def redirect_to_unescaped_path
33
- redirect_to "#{request.protocol}#{request.host}/foo bar"
34
- end
35
- end
36
-
37
- class BreezyTest < ActionController::TestCase
38
- tests BreezyController
39
-
40
- test "request referer returns xhr referer or standard referer" do
41
- @request.env['HTTP_REFERER'] = 'referer'
42
- assert_equal 'referer', @request.referer
43
-
44
- @request.env['HTTP_X_XHR_REFERER'] = 'xhr-referer'
45
- assert_equal 'xhr-referer', @request.referer
46
- end
47
-
48
- test "url for with back uses xhr referer when available" do
49
- @request.env['HTTP_REFERER'] = 'referer'
50
- assert_equal 'referer', @controller.view_context.url_for(:back)
51
-
52
- @request.env['HTTP_X_XHR_REFERER'] = 'xhr-referer'
53
- assert_equal 'xhr-referer', @controller.view_context.url_for(:back)
54
- end
55
-
56
- test "redirect to back uses xhr referer when available" do
57
- @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
58
- @request.headers['X-BREEZY-REQUEST'] = 't'
59
-
60
- @request.env['HTTP_REFERER'] = 'http://test.host/referer'
61
- get :redirect_to_back
62
- assert_response :ok
63
- assert_equal @response.headers['X-BREEZY-LOCATION'], 'http://test.host/referer'
64
-
65
- @request.env['HTTP_X_XHR_REFERER'] = 'http://test.host/referer'
66
- get :redirect_to_back
67
- assert_response :ok
68
- assert_equal @response.headers['X-BREEZY-LOCATION'], 'http://test.host/referer'
69
- end
70
-
71
- test "sets X-BREEZY-LOCATION header on redirect requests coming from breezy" do
72
- @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
73
- @request.headers['X-BREEZY-REQUEST'] = 't'
74
-
75
- get :redirect_to_same_origin
76
- get :simple_action
77
- assert_nil @response.headers['X-BREEZY-LOCATION']
78
-
79
- @request.env['HTTP_X_XHR_REFERER'] = 'http://test.host/'
80
- get :redirect_to_same_origin
81
- assert_equal 'http://test.host/path', @response.headers['X-BREEZY-LOCATION']
82
- end
83
-
84
- test "changes status to 403 on breezy requests redirecting to different origin" do
85
- @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
86
- @request.headers['X-BREEZY-REQUEST'] = 't'
87
-
88
- get :redirect_to_different_host
89
- assert_response :ok
90
- assert @response.headers['X-BREEZY-LOCATION']
91
-
92
- get :redirect_to_different_protocol
93
- assert_response :ok
94
- assert @response.headers['X-BREEZY-LOCATION']
95
-
96
- @request.env['HTTP_X_XHR_REFERER'] = 'http://test.host'
97
- get :redirect_to_different_host
98
- assert_response :forbidden
99
-
100
- get :redirect_to_different_protocol
101
- assert_response :forbidden
102
-
103
- get :redirect_to_same_origin
104
- assert_response :ok
105
- assert @response.headers['X-BREEZY-LOCATION']
106
- end
107
-
108
- test "handles invalid xhr referer on redirection" do
109
- @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
110
- @request.headers['X-BREEZY-REQUEST'] = 't'
111
- @request.env['HTTP_X_XHR_REFERER'] = ':'
112
- get :redirect_to_same_origin
113
- assert_response :ok
114
- assert @response.headers['X-BREEZY-LOCATION']
115
- end
116
-
117
- test "handles unescaped same origin location on redirection" do
118
- @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
119
- @request.headers['X-BREEZY-REQUEST'] = 't'
120
- @request.env['HTTP_X_XHR_REFERER'] = 'http://test.host/'
121
- get :redirect_to_unescaped_path
122
- assert_response :ok
123
- assert @response.headers['X-BREEZY-LOCATION']
124
- end
125
- end