react_on_rails 11.1.1 → 11.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +10 -0
- data/README.md +2 -2
- data/docs/basics/configuration.md +41 -5
- data/docs/basics/generator-functions-and-railscontext.md +11 -1
- data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
- data/lib/react_on_rails/configuration.rb +1 -1
- data/lib/react_on_rails/react_component/render_options.rb +2 -2
- data/lib/react_on_rails/test_helper.rb +10 -0
- data/lib/react_on_rails/utils.rb +15 -6
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/webpacker_utils.rb +6 -0
- data/package.json +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24362cafd62e7bf03e57b82b3fad400765ab55dda2eba19c68411f5b6599bbbe
|
4
|
+
data.tar.gz: '091f3c971b243209fb72c53723f72f2c9915533f20602b0b7d94297a1e0ffd96'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eccf5d97a8c77b782082d94646e5068dcf7f4f667f0efdc23bc459c5ff7b78d95750162f96bc398691825860ea8b9fe8c1f2e59cc0418a5e46d9e176ab387c91
|
7
|
+
data.tar.gz: 10bb36f5b233e5444b92a900c7e16b8b6a70b6c6a4d5d925aaa139c411ab526797d64b0ea334dc5c096143698087c3fe3699dd90b85f367b16aa6a62742f9870
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -9,6 +9,16 @@ See [Upgrading React on Rails](./docs/basics/upgrading-react-on-rails.md) for mo
|
|
9
9
|
Changes since last non-beta release.
|
10
10
|
|
11
11
|
*Please add entries here for your pull requests that are not yet released.*
|
12
|
+
|
13
|
+
### [11.1.2] - 2018-08-18
|
14
|
+
|
15
|
+
#### Fixed
|
16
|
+
- Tests now properly exit if the config.build_test_command fails!
|
17
|
+
- Source path for project using Webpacker would default to "app/javascript" even if when the node_modules
|
18
|
+
directory was set to "client". Fix now makes the configuration of this crystal clear.
|
19
|
+
- renamed method RenderOptions.has_random_dom_id? to RenderOptions.random_dom_id? for rubocop rule.
|
20
|
+
[PR 1133](https://github.com/shakacode/react_on_rails/pull/1133) by [justin808](https://github.com/justin808)
|
21
|
+
|
12
22
|
### [11.1.1] - 2018-08-09
|
13
23
|
#### Fixed
|
14
24
|
- `TRUE` was deprecated in ruby 2.4, using `true` instead. [PR 1128](https://github.com/shakacode/react_on_rails/pull/1128) by [Aguardientico](https://github.com/Aguardientico).
|
data/README.md
CHANGED
@@ -27,9 +27,10 @@ Given that rails/webpacker gem already provides basic React integration, why wou
|
|
27
27
|
|
28
28
|
See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
|
29
29
|
|
30
|
-
|
31
30
|
## React on Rails Pro and ShakaCode Pro Support
|
32
31
|
|
32
|
+

|
33
|
+
|
33
34
|
React on Rails Pro provides Node server rendering and other performance enhancements for React on Rails. It's live at [egghead.io](https://egghead.io). See the [React on Rails Pro Docs](https://github.com/shakacode/react_on_rails/wiki).
|
34
35
|
|
35
36
|
The [React on Rails Pro Support Plan](http://www.shakacode.com/work/shakacode-pro-support.pdf) can help you with:
|
@@ -44,7 +45,6 @@ ShakaCode can also help you with your Rails, JavaScript, and React-Native develo
|
|
44
45
|
|
45
46
|
The article [Why Hire ShakaCode?](https://blog.shakacode.com/can-shakacode-help-you-4a5b1e5a8a63#.jex6tg9w9) provides additional details about our projects.
|
46
47
|
|
47
|
-
|
48
48
|
Please [email me (Justin Gordon), the creator of React on Rails](mailto:justin@shakacode.com), to see if I can help you or if you want an invite to our private Slack room for ShakaCode.
|
49
49
|
|
50
50
|
## Testimonials for Hiring ShakaCode and our "Pro Support"
|
@@ -1,5 +1,40 @@
|
|
1
1
|
Here is the full set of config options. This file is `/config/initializers/react_on_rails.rb`
|
2
2
|
|
3
|
+
First, you should have a `/config/webpacker.yml` setup.
|
4
|
+
|
5
|
+
Here is the setup when using the recommended `/client` directory for your node_modules and source files:
|
6
|
+
|
7
|
+
```yaml
|
8
|
+
# Note: Base output directory of /public is assumed for static files
|
9
|
+
default: &default
|
10
|
+
compile: false
|
11
|
+
# Used in your webpack configuration. Must be created in the
|
12
|
+
# public_output_path folder
|
13
|
+
manifest: manifest.json
|
14
|
+
cache_manifest: false
|
15
|
+
source_path: client/app
|
16
|
+
|
17
|
+
development:
|
18
|
+
<<: *default
|
19
|
+
# generated files for development, in /public/webpack/dev
|
20
|
+
public_output_path: webpack/dev
|
21
|
+
|
22
|
+
test:
|
23
|
+
<<: *default
|
24
|
+
# generated files for tests, in /public/webpack/test
|
25
|
+
public_output_path: webpack/test
|
26
|
+
|
27
|
+
production:
|
28
|
+
<<: *default
|
29
|
+
# generated files for tests, in /public/webpack/production
|
30
|
+
public_output_path: webpack/production
|
31
|
+
cache_manifest: true
|
32
|
+
```
|
33
|
+
|
34
|
+
Here's a representative `/config/initializers/react_on_rails.rb` setup when using this `/client` directory
|
35
|
+
for all client files, including your sources and node_modules.
|
36
|
+
|
37
|
+
|
3
38
|
```ruby
|
4
39
|
# frozen_string_literal: true
|
5
40
|
|
@@ -24,7 +59,7 @@ ReactOnRails.configure do |config|
|
|
24
59
|
|
25
60
|
# defaults to "" (top level)
|
26
61
|
#
|
27
|
-
config.node_modules_location = ""
|
62
|
+
config.node_modules_location = "client" # Recommended!
|
28
63
|
|
29
64
|
# This configures the script to run to build the production assets by webpack. Set this to nil
|
30
65
|
# if you don't want react_on_rails building this file for you.
|
@@ -52,17 +87,18 @@ ReactOnRails.configure do |config|
|
|
52
87
|
# public_output_path: packs-test
|
53
88
|
# which means files in /public/packs-test
|
54
89
|
#
|
55
|
-
# Alternately, you may configure this. It is relative to your Rails
|
56
|
-
# A custom, non-webpacker, config might use something like:
|
90
|
+
# Alternately, you may configure this if you are NOT using webpacker. It is relative to your Rails
|
91
|
+
# root directory. A custom, non-webpacker, config might use something like:
|
57
92
|
#
|
58
93
|
# config.generated_assets_dir = File.join(%w[public webpack], Rails.env)
|
59
94
|
# This setting should not be used if using webpacker.
|
60
95
|
|
96
|
+
# CONFIGURE YOUR SOURCE FILES
|
61
97
|
# The test helper needs to know where your JavaScript files exist. The default is configured
|
62
98
|
# by your config/webpacker.yml soure_path:
|
63
|
-
# source_path: app/javascript
|
99
|
+
# source_path: client/app/javascript # if using recommended /client directory
|
64
100
|
#
|
65
|
-
# If you
|
101
|
+
# If you are not using webpacker, the `node_modules_location` is assumed to be the location of your source
|
66
102
|
# files.
|
67
103
|
|
68
104
|
# Define the files we need to check for webpack compilation when running tests.
|
@@ -43,11 +43,18 @@ Note: you never make these calls. React on Rails makes these calls when it does
|
|
43
43
|
|
44
44
|
(Note: see below [section](#multiple-react-components-on-a-page-with-one-store) on how to setup redux stores that allow multiple components to talk to the same store.)
|
45
45
|
|
46
|
-
The `railsContext` has: (see implementation in file [
|
46
|
+
The `railsContext` has: (see implementation in file [ReactOnRails::Helper](https://github.com/shakacode/react_on_rails/tree/master/lib/react_on_rails/helper.rb), method `rails_context` for the definitive list).
|
47
47
|
|
48
48
|
```ruby
|
49
49
|
{
|
50
50
|
railsEnv: Rails.env
|
51
|
+
inMailer: in_mailer?,
|
52
|
+
# Locale settings
|
53
|
+
i18nLocale: I18n.locale,
|
54
|
+
i18nDefaultLocale: I18n.default_locale,
|
55
|
+
rorVersion: ReactOnRails::VERSION,
|
56
|
+
rorPro: ReactOnRails::Utils.react_on_rails_pro?
|
57
|
+
|
51
58
|
# URL settings
|
52
59
|
href: request.original_url,
|
53
60
|
location: "#{uri.path}#{uri.query.present? ? "?#{uri.query}": ""}",
|
@@ -56,6 +63,7 @@ The `railsContext` has: (see implementation in file [react_on_rails_helper.rb](h
|
|
56
63
|
port: uri.port,
|
57
64
|
pathname: uri.path, # /posts
|
58
65
|
search: uri.query, # id=30&limit=5
|
66
|
+
httpAcceptLanguage: request.env["HTTP_ACCEPT_LANGUAGE"]
|
59
67
|
|
60
68
|
# Other
|
61
69
|
serverSide: boolean # Are we being called on the server or client? Note: if you conditionally
|
@@ -64,6 +72,8 @@ The `railsContext` has: (see implementation in file [react_on_rails_helper.rb](h
|
|
64
72
|
}
|
65
73
|
```
|
66
74
|
|
75
|
+
Plus, you can add your customizations to this. See "rendering extension" below.
|
76
|
+
|
67
77
|
## Rails Context
|
68
78
|
|
69
79
|
The `railsContext` is a second param passed to your generator functions for React components. This is in addition to the props that are passed from the `react_component` Rails helper. For example:
|
@@ -50,7 +50,7 @@ module ReactOnRails
|
|
50
50
|
replacement_value = <<-STRING
|
51
51
|
"scripts": {
|
52
52
|
"postinstall": "yarn link react-on-rails",
|
53
|
-
STRING
|
53
|
+
STRING
|
54
54
|
new_client_package_json_contents = contents.gsub(/ {2}"scripts": {/,
|
55
55
|
replacement_value)
|
56
56
|
File.open(package_json, "w+") { |f| f.puts new_client_package_json_contents }
|
@@ -116,7 +116,7 @@ module ReactOnRails
|
|
116
116
|
webpacker_public_output_path = ReactOnRails::WebpackerUtils.webpacker_public_output_path
|
117
117
|
|
118
118
|
if File.expand_path(generated_assets_dir) == webpacker_public_output_path.to_s
|
119
|
-
Rails.logger.warn("You specified
|
119
|
+
Rails.logger.warn("You specified generated_assets_dir in `config/initializers/react_on_rails.rb` "\
|
120
120
|
"with Webpacker. Remove this line from your configuration file.")
|
121
121
|
else
|
122
122
|
msg = <<-MSG.strip_heredoc
|
@@ -36,7 +36,7 @@ module ReactOnRails
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
39
|
+
def random_dom_id?
|
40
40
|
return false if options[:id]
|
41
41
|
|
42
42
|
return false unless random_dom_id
|
@@ -77,7 +77,7 @@ module ReactOnRails
|
|
77
77
|
attr_reader :options
|
78
78
|
|
79
79
|
def base_dom_id
|
80
|
-
|
80
|
+
"#{react_component_name}-react-component"
|
81
81
|
end
|
82
82
|
|
83
83
|
def generate_unique_dom_id
|
@@ -75,6 +75,16 @@ module ReactOnRails
|
|
75
75
|
"outdated/missing bundles based on source_path #{source_path}"
|
76
76
|
puts
|
77
77
|
@printed_once = true
|
78
|
+
|
79
|
+
if ReactOnRails::WebpackerUtils.using_webpacker? &&
|
80
|
+
ReactOnRails::Utils.using_webpacker_source_path_is_not_defined_and_custom_node_modules?
|
81
|
+
msg = <<-MSG.strip_heredoc
|
82
|
+
WARNING: Define config.webpacker.yml to include sourcePath to configure
|
83
|
+
the location of your JavaScript source for React on Rails.
|
84
|
+
Default location of #{source_path} is used.
|
85
|
+
MSG
|
86
|
+
puts ReactOnRails::Utils.wrap_message(msg, :orange)
|
87
|
+
end
|
78
88
|
end
|
79
89
|
end
|
80
90
|
|
data/lib/react_on_rails/utils.rb
CHANGED
@@ -8,7 +8,7 @@ require "active_support/core_ext/string"
|
|
8
8
|
|
9
9
|
module ReactOnRails
|
10
10
|
module Utils
|
11
|
-
TRUNCATION_FILLER = "\n... TRUNCATED ...\n"
|
11
|
+
TRUNCATION_FILLER = "\n... TRUNCATED ...\n".freeze
|
12
12
|
|
13
13
|
# https://forum.shakacode.com/t/yak-of-the-week-ruby-2-4-pathname-empty-changed-to-look-at-file-size/901
|
14
14
|
# return object if truthy, else return nil
|
@@ -57,7 +57,9 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
|
|
57
57
|
MSG
|
58
58
|
# rubocop:enable Layout/IndentHeredoc
|
59
59
|
puts wrap_message(msg)
|
60
|
-
|
60
|
+
|
61
|
+
# Rspec catches exit without! in the exit callbacks
|
62
|
+
exit!(1)
|
61
63
|
end
|
62
64
|
[stdout, stderr, status]
|
63
65
|
end
|
@@ -135,6 +137,13 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
|
|
135
137
|
end
|
136
138
|
end
|
137
139
|
|
140
|
+
def self.using_webpacker_source_path_is_not_defined_and_custom_node_modules?
|
141
|
+
return false unless ReactOnRails::WebpackerUtils.using_webpacker?
|
142
|
+
|
143
|
+
!ReactOnRails::WebpackerUtils.webpacker_source_path_explicit? &&
|
144
|
+
ReactOnRails.configuration.node_modules_location.present?
|
145
|
+
end
|
146
|
+
|
138
147
|
def self.generated_assets_full_path
|
139
148
|
if ReactOnRails::WebpackerUtils.using_webpacker?
|
140
149
|
ReactOnRails::WebpackerUtils.webpacker_public_output_path
|
@@ -163,10 +172,10 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
|
|
163
172
|
|
164
173
|
return str[0, 1] + TRUNCATION_FILLER if max_length == 1
|
165
174
|
|
166
|
-
midpoint = (str.length / 2.0).ceil
|
167
|
-
to_remove = str.length - max_length
|
168
|
-
lstrip = (to_remove / 2.0).ceil
|
169
|
-
rstrip = to_remove - lstrip
|
175
|
+
midpoint = (str.length / 2.0).ceil
|
176
|
+
to_remove = str.length - max_length
|
177
|
+
lstrip = (to_remove / 2.0).ceil
|
178
|
+
rstrip = to_remove - lstrip
|
170
179
|
str[0..(midpoint - lstrip - 1)] + TRUNCATION_FILLER + str[(midpoint + rstrip)..-1]
|
171
180
|
end
|
172
181
|
end
|
@@ -31,6 +31,12 @@ module ReactOnRails
|
|
31
31
|
Webpacker.config.public_manifest_path.exist?
|
32
32
|
end
|
33
33
|
|
34
|
+
def self.webpacker_source_path_explicit?
|
35
|
+
# WARNING: Calling private method `data` on Webpacker::Configuration, lib/webpacker/configuration.rb
|
36
|
+
config_webpacker_yml = Webpacker.config.send(:data)
|
37
|
+
config_webpacker_yml[:source_path].present?
|
38
|
+
end
|
39
|
+
|
34
40
|
def self.check_manifest_not_cached
|
35
41
|
return unless using_webpacker? && Webpacker.config.cache_manifest?
|
36
42
|
msg = <<-MSG.strip_heredoc
|
data/package.json
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: react_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 11.1.
|
4
|
+
version: 11.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Gordon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|