breezy 0.12.0 → 0.17.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 +6 -9
  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 -6
  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.js.props → index.json.props} +1 -2
  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/edit.html.erb +7 -0
  14. data/lib/generators/rails/templates/web/edit.jsx +21 -28
  15. data/lib/generators/rails/templates/web/index.html.erb +7 -0
  16. data/lib/generators/rails/templates/web/index.jsx +10 -7
  17. data/lib/generators/rails/templates/web/new.html.erb +7 -0
  18. data/lib/generators/rails/templates/web/new.jsx +18 -25
  19. data/lib/generators/rails/templates/web/show.html.erb +7 -0
  20. data/lib/generators/rails/templates/web/show.jsx +3 -4
  21. data/lib/install/templates/web/action_creators.js +14 -12
  22. data/lib/install/templates/web/actions.js +4 -1
  23. data/lib/install/templates/web/application.js +173 -47
  24. data/lib/install/templates/web/application.json.props +26 -0
  25. data/lib/install/templates/web/application_visit.js +65 -0
  26. data/lib/install/templates/web/initializer.rb +1 -15
  27. data/lib/install/templates/web/reducer.js +62 -9
  28. data/lib/install/web.rb +23 -61
  29. data/lib/tasks/install.rake +11 -1
  30. data/test/helpers_test.rb +9 -17
  31. data/test/render_test.rb +19 -95
  32. data/test/test_helper.rb +1 -1
  33. metadata +25 -28
  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/new.js.props +0 -4
  39. data/lib/generators/rails/templates/web/base.jsx +0 -11
  40. data/lib/generators/rails/templates/web/form.jsx +0 -31
  41. data/lib/install/templates/web/babelrc +0 -35
  42. data/test/breezy_test.rb +0 -125
  43. data/test/configuration_test.rb +0 -36
@@ -8,7 +8,7 @@ require 'active_record'
8
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breezy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johny Ho
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-31 00:00:00.000000000 Z
11
+ date: 2021-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.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.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.12.0
33
+ version: 0.17.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.12.0
40
+ version: 0.17.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: webpacker
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
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,37 +156,37 @@ 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
174
- - lib/generators/rails/templates/web/base.jsx
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
173
+ - lib/generators/rails/templates/web/edit.html.erb
175
174
  - lib/generators/rails/templates/web/edit.jsx
176
- - lib/generators/rails/templates/web/form.jsx
175
+ - lib/generators/rails/templates/web/index.html.erb
177
176
  - lib/generators/rails/templates/web/index.jsx
177
+ - lib/generators/rails/templates/web/new.html.erb
178
178
  - lib/generators/rails/templates/web/new.jsx
179
+ - lib/generators/rails/templates/web/show.html.erb
179
180
  - lib/generators/rails/templates/web/show.jsx
180
181
  - lib/install/templates/web/action_creators.js
181
182
  - lib/install/templates/web/actions.js
182
183
  - lib/install/templates/web/application.js
183
- - lib/install/templates/web/babelrc
184
+ - lib/install/templates/web/application.json.props
185
+ - lib/install/templates/web/application_visit.js
184
186
  - lib/install/templates/web/initializer.rb
185
187
  - lib/install/templates/web/reducer.js
186
188
  - lib/install/web.rb
187
189
  - lib/tasks/install.rake
188
- - test/breezy_test.rb
189
- - test/configuration_test.rb
190
190
  - test/engine_test.rb
191
191
  - test/helpers_test.rb
192
192
  - test/render_test.rb
@@ -195,7 +195,7 @@ homepage: https://github.com/jho406/breezy/
195
195
  licenses:
196
196
  - MIT
197
197
  metadata: {}
198
- post_install_message:
198
+ post_install_message:
199
199
  rdoc_options: []
200
200
  require_paths:
201
201
  - lib
@@ -210,15 +210,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  - !ruby/object:Gem::Version
211
211
  version: '0'
212
212
  requirements: []
213
- rubyforge_project:
214
- rubygems_version: 2.6.11
215
- signing_key:
213
+ rubygems_version: 3.1.2
214
+ signing_key:
216
215
  specification_version: 4
217
216
  summary: Rails integration for BreezyJS
218
217
  test_files:
219
218
  - test/render_test.rb
220
- - test/configuration_test.rb
221
219
  - test/helpers_test.rb
222
220
  - test/engine_test.rb
223
221
  - test/test_helper.rb
224
- - 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.<%= singular_table_name%>_path <%= singular_table_name%>_path(@<%=singular_table_name%>)
16
- json.<%= plural_table_name %>_path <%= plural_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,11 +0,0 @@
1
- import React from 'react'
2
- import {enhanceVisitWithBrowserBehavior} from '@jho406/breezy'
3
-
4
- export default class extends React.Component {
5
- constructor (props) {
6
- super(props)
7
- const visit = enhanceVisitWithBrowserBehavior(props.visit)
8
- this.enhancedVisit = visit.bind(this)
9
- }
10
- }
11
-
@@ -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.camelize(:lower).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.camelize(:lower).to_s%> && touched.<%=attr.camelize(:lower).to_s%> && errors.<%=attr.camelize(:lower).to_s%>}
21
- <%- end -%>
22
-
23
- <button type="submit" disabled={isSubmitting}>
24
- Submit
25
- </button>
26
- </Form>
27
- )}
28
- </Formik>
29
- )
30
- }
31
- )
@@ -1,35 +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
- "components": "./app/components",
23
- "javascript": "./app/javascript"
24
- }
25
- }],
26
- "transform-object-rest-spread",
27
- [
28
- "transform-class-properties",
29
- {
30
- "spec": true
31
- }
32
- ]
33
- ]
34
- }
35
-
@@ -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