react_on_rails 6.8.2 → 6.9.0

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: 330b3bfdba74e7185714c89c06b0e6ed85511d55
4
- data.tar.gz: fbbb20768dad8d656c5d9d53132f6507a976d31f
3
+ metadata.gz: 9328c100671c200027cdc7d8230de79916044a23
4
+ data.tar.gz: bfa2ba3f71de5f4951ca0b2d0b8bbe0ece0afc8b
5
5
  SHA512:
6
- metadata.gz: c1e98356761f51eaef235c49efcab92333bb5e75683639ecc68e2a3658b0db4b8a314a4b48be5f66b9644af0f16e7eee4955c2f9f4780315ef8210e824393ba0
7
- data.tar.gz: afad9d48c7aa908c641e052123e8ca265077aedeeb7d89ab56cc89331990cc20f9fc29dbc8711ec0e131cec7880634e48315183f9aeaabd2c533a1c568510613
6
+ metadata.gz: 5328449a8ec4805624926acbe23359748c4bbf3f7680b798c392b85d653bbe3fe6c4cfcf2dac43ce12d9a9adaa698992116cf075486aa1671ea76afbb6744c94
7
+ data.tar.gz: fa1ebc8f3eb2db3caa2f9d4957d20b3bfd76ada8a064f0a8035dbd28bddd5662e3855c3003936048b7783e90692bbcd4dc3aac1fdbf90ca0549f13fcfebf3686
data/CHANGELOG.md CHANGED
@@ -4,8 +4,21 @@ All notable changes to this project's source code will be documented in this fil
4
4
  Contributors: please follow the recommendations outlined at [keepachangelog.com](http://keepachangelog.com/). Please use the existing headings and styling as a guide, and add a link for the version diff at the bottom of the file. Also, please update the `Unreleased` link to compare to the latest release version.
5
5
 
6
6
  ## [Unreleased]
7
- *Please add entries here for your pull requests.*
7
+
8
+ ## [6.9.0] - 2017-03-29
9
+
10
+ ## Fixed
11
+ - Fixed error in the release script. [#767](https://github.com/shakacode/react_on_rails/issues/767) by [isolo](https://github.com/isolo).
12
+
8
13
  ## Changed
14
+ - Use <script type="application/json"> for props and store instead of hidden div. [#775] (https://github.com/shakacode/react_on_rails/pull/775) by [cheremukhin23](https://github.com/cheremukhin23).
15
+
16
+ ## Added
17
+ - Add option to specify i18n_yml_dir in order to include only subset of locale files when generating translations.js & default.js for react-intl.
18
+ [#777](https://github.com/shakacode/react_on_rails/pull/777) by [danijel](https://github.com/danijel).
19
+
20
+ ## [6.8.2] - 2017-03-24
21
+ ## Fixed
9
22
  - Change webpack output path to absolute and update webpack to version ^2.3.1. [#771](https://github.com/shakacode/react_on_rails/pull/771) by [cheremukhin23](https://github.com/cheremukhin23).
10
23
 
11
24
  ## [6.8.1] - 2017-03-21
@@ -491,7 +504,9 @@ Best done with Object destructing:
491
504
  ##### Fixed
492
505
  - Fix several generator related issues.
493
506
 
494
- [Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.8.1...master
507
+ [Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.9.0...master
508
+ [6.9.0]: https://github.com/shakacode/react_on_rails/compare/6.8.2...6.9.0
509
+ [6.8.2]: https://github.com/shakacode/react_on_rails/compare/6.8.1...6.8.2
495
510
  [6.8.1]: https://github.com/shakacode/react_on_rails/compare/6.8.0...6.8.1
496
511
  [6.8.0]: https://github.com/shakacode/react_on_rails/compare/6.7.2...6.8.0
497
512
  [6.7.2]: https://github.com/shakacode/react_on_rails/compare/6.7.1...6.7.2
data/KUDOS.md CHANGED
@@ -6,6 +6,10 @@ I'm looking for quotes on why you like using React on Rails. You might mention a
6
6
  Github issue [#766](https://github.com/shakacode/react_on_rails/issues/766).
7
7
  ![2017-03-23_17-43-17](https://cloud.githubusercontent.com/assets/1118459/24279884/badab166-0ff0-11e7-87ab-94253f55a3d9.png)
8
8
 
9
+ ## March 21, 2017
10
+ Twitter from [@rfc2616](https://twitter.com/rfc2616)
11
+ ![2017-03-24_20-20-20](https://cloud.githubusercontent.com/assets/1118459/24319983/7adfd57a-10cf-11e7-9a50-5c23d5d5bcab.png)
12
+
9
13
  ### March 2, 2017
10
14
  ![2017-03-05_21-34-34](https://cloud.githubusercontent.com/assets/1118459/23600716/0d8c40d6-01ec-11e7-998d-4ce9e6abcacb.png)
11
15
 
@@ -103,13 +103,10 @@ module ReactOnRailsHelper
103
103
 
104
104
  # Setup the page_loaded_js, which is the same regardless of prerendering or not!
105
105
  # The reason is that React is smart about not doing extra work if the server rendering did its job.
106
-
107
- component_specification_tag =
108
- content_tag(:div,
109
- "",
110
- class: "js-react-on-rails-component",
111
- style: options.style,
112
- data: options.data)
106
+ component_specification_tag = content_tag(:script,
107
+ json_safe_and_pretty(options.data).html_safe,
108
+ type: "application/json",
109
+ class: "js-react-on-rails-component")
113
110
 
114
111
  # Create the HTML rendering part
115
112
  result = server_rendered_react_component_html(options.props, options.name, options.dom_id,
@@ -174,7 +171,7 @@ module ReactOnRailsHelper
174
171
  end
175
172
 
176
173
  def sanitized_props_string(props)
177
- props.is_a?(String) ? json_escape(props) : props.to_json
174
+ props.is_a?(String) ? ERB::Util.json_escape(props) : props.to_json
178
175
  end
179
176
 
180
177
  # Helper method to take javascript expression and returns the output from evaluating it.
@@ -225,30 +222,36 @@ module ReactOnRailsHelper
225
222
 
226
223
  private
227
224
 
225
+ def json_safe_and_pretty(something)
226
+ if Rails.env.development?
227
+ ERB::Util.json_escape(JSON.pretty_generate(something.as_json))
228
+ else
229
+ ERB::Util.json_escape(something.to_json)
230
+ end
231
+ end
232
+
228
233
  # prepend the rails_context if not yet applied
229
234
  def prepend_render_rails_context(render_value)
230
235
  return render_value if @rendered_rails_context
231
236
 
232
- data = {
233
- rails_context: rails_context(server_side: false)
234
- }
237
+ data = rails_context(server_side: false)
235
238
 
236
239
  @rendered_rails_context = true
237
240
 
238
- rails_context_content = content_tag(:div,
239
- "",
240
- id: "js-react-on-rails-context",
241
- style: ReactOnRails.configuration.skip_display_none ? nil : "display:none",
242
- data: data)
241
+ rails_context_content = content_tag(:script,
242
+ json_safe_and_pretty(data).html_safe,
243
+ type: "application/json",
244
+ id: "js-react-on-rails-context")
245
+
243
246
  "#{rails_context_content}\n#{render_value}".html_safe
244
247
  end
245
248
 
246
249
  def render_redux_store_data(redux_store_data)
247
- result = content_tag(:div,
248
- "",
249
- class: "js-react-on-rails-store",
250
- style: ReactOnRails.configuration.skip_display_none ? nil : "display:none",
251
- data: redux_store_data)
250
+ result = content_tag(:script,
251
+ json_safe_and_pretty(redux_store_data[:props]).html_safe,
252
+ type: "application/json",
253
+ "data-js-react-on-rails-store" => redux_store_data[:store_name].html_safe)
254
+
252
255
  prepend_render_rails_context(result)
253
256
  end
254
257
 
data/docs/basics/i18n.md CHANGED
@@ -16,21 +16,28 @@ You can refer to [react-webpack-rails-tutorial](https://github.com/shakacode/rea
16
16
  ```
17
17
 
18
18
  2. Add `config.i18n_dir` in `config/initializers/react_on_rails.rb`
19
-
19
+
20
20
  `react-intl` requires locale files in json format. React on Rails will generate `translations.js` & `default.js` automatically after you configured your `config.i18n_dir` in `config/initializers/react_on_rails.rb`.
21
21
 
22
22
  ```ruby
23
23
  # Replace the following line to the location where you keep translation.js & default.js.
24
24
  config.i18n_dir = Rails.root.join("PATH_TO", "YOUR_JS_I18N_FOLDER")
25
25
  ```
26
-
26
+
27
+ Optionally you can also set `config.i18n_yml_dir` if you do not what to use all the locale files from rails.
28
+ ```ruby
29
+ # Replace the following line to the location where you keep your client i18n yml files
30
+ # By default(without this option), all yaml files from Rails.root.join("config", "locales") and installed gems are loaded
31
+ config.i18n_yml_dir = Rails.root.join("PATH_TO", "YOUR_YAML_I18N_FOLDER")
32
+ ```
33
+
27
34
  `translations.js`: All your locales in json format.
28
35
  `default.js`: Default settings in json format.
29
36
 
30
37
  3. Add `translations.js` and `default.js` to your `.gitignore` and `.eslintignore`.
31
-
32
- 4. Javascript locale files must be generated before `yarn build`.
33
-
38
+
39
+ 4. Javascript locale files must be generated before `yarn build`.
40
+
34
41
  Once you setup `config.i18n_dir` as in the previous step, react_on_rails will automatically do this for testing (if using the `ReactOnRails::TestHelper.configure_rspec_to_compile_assets` and for production deployments if using the [default precompile rake hook](../additional-reading/heroku-deployment.md). For development, you should adjust your startup scripts (Procfiles) so that they run `bundle exec rake react_on_rails:locale` before running any webpack watch process (`yarn run build:development`).
35
42
 
36
43
  5. In React, you need to initialize `react-intl`, and set parameters for it.
@@ -65,14 +65,16 @@ ReactOnRails.configure do |config|
65
65
  # Replace the following line to the location where you keep translation.js & default.js for use
66
66
  # by the npm packages react-intl. Be sure this directory exists!
67
67
  # config.i18n_dir = Rails.root.join("client", "app", "libs", "i18n")
68
+ #
69
+ # Replace the following line to the location where you keep your client i18n yml files
70
+ # that will source for automatic generation on translations.js & default.js
71
+ # By default(without this option) all yaml files from Rails.root.join("config", "locales") and installed gems are loaded
72
+ # config.i18n_yml_dir = Rails.root.join("config", "locales", "client")
68
73
 
69
74
  ################################################################################
70
75
  # MISCELLANEOUS OPTIONS
71
76
  ################################################################################
72
77
 
73
- # Default is false, enable if your content security policy doesn't include `style-src: 'unsafe-inline'`
74
- config.skip_display_none = false
75
-
76
78
  # The server render method - either ExecJS or NodeJS
77
79
  <%- if options.node? -%>
78
80
  config.server_render_method = "NodeJS"
@@ -9,9 +9,11 @@ module ReactOnRails
9
9
  def self.setup_config_values
10
10
  ensure_webpack_generated_files_exists
11
11
  configure_generated_assets_dirs_deprecation
12
+ configure_skip_display_none_deprecation
12
13
  ensure_generated_assets_dir_present
13
14
  ensure_server_bundle_js_file_has_no_path
14
15
  check_i18n_directory_exists
16
+ check_i18n_yml_directory_exists
15
17
  end
16
18
 
17
19
  def self.check_i18n_directory_exists
@@ -23,6 +25,15 @@ module ReactOnRails
23
25
  "out if not using this i18n with React on Rails."
24
26
  end
25
27
 
28
+ def self.check_i18n_yml_directory_exists
29
+ return unless @configuration.i18n_yml_dir.present?
30
+ return if Dir.exist?(@configuration.i18n_yml_dir)
31
+
32
+ raise "Error configuring /config/react_on_rails.rb: invalid value for `config.i18n_yml_dir`. "\
33
+ "Directory does not exist: #{@configuration.i18n_yml_dir}. Set to value to nil or comment it "\
34
+ "out if not using this i18n with React on Rails, or if you want to use all translation files."
35
+ end
36
+
26
37
  def self.ensure_generated_assets_dir_present
27
38
  return unless @configuration.generated_assets_dir.blank?
28
39
 
@@ -61,6 +72,11 @@ module ReactOnRails
61
72
  @configuration.server_bundle_js_file = File.basename(@configuration.server_bundle_js_file)
62
73
  end
63
74
 
75
+ def self.configure_skip_display_none_deprecation
76
+ return if @configuration.skip_display_none.nil?
77
+ puts "[DEPRECATION] ReactOnRails: remove skip_display_none from configuration."
78
+ end
79
+
64
80
  def self.configuration
65
81
  @configuration ||= Configuration.new(
66
82
  generated_assets_dirs: nil,
@@ -76,13 +92,16 @@ module ReactOnRails
76
92
  development_mode: Rails.env.development?,
77
93
  server_renderer_pool_size: 1,
78
94
  server_renderer_timeout: 20,
79
- skip_display_none: false,
95
+ skip_display_none: nil,
96
+
97
+ # skip_display_none is deprecated
80
98
  webpack_generated_files: [],
81
99
  rendering_extension: nil,
82
100
  server_render_method: "",
83
101
  symlink_non_digested_assets_regex: /\.(png|jpg|jpeg|gif|tiff|woff|ttf|eot|svg|map)/,
84
102
  npm_build_test_command: "",
85
103
  i18n_dir: "",
104
+ i18n_yml_dir: "",
86
105
  npm_build_production_command: ""
87
106
  )
88
107
  end
@@ -91,11 +110,11 @@ module ReactOnRails
91
110
  attr_accessor :server_bundle_js_file, :prerender, :replay_console,
92
111
  :trace, :development_mode,
93
112
  :logging_on_server, :server_renderer_pool_size,
94
- :server_renderer_timeout, :raise_on_prerender_error,
95
- :skip_display_none, :generated_assets_dirs, :generated_assets_dir,
113
+ :server_renderer_timeout, :skip_display_none, :raise_on_prerender_error,
114
+ :generated_assets_dirs, :generated_assets_dir,
96
115
  :webpack_generated_files, :rendering_extension, :npm_build_test_command,
97
116
  :npm_build_production_command,
98
- :i18n_dir,
117
+ :i18n_dir, :i18n_yml_dir,
99
118
  :server_render_method, :symlink_non_digested_assets_regex
100
119
 
101
120
  def initialize(server_bundle_js_file: nil, prerender: nil, replay_console: nil,
@@ -106,7 +125,7 @@ module ReactOnRails
106
125
  generated_assets_dir: nil, webpack_generated_files: nil,
107
126
  rendering_extension: nil, npm_build_test_command: nil,
108
127
  npm_build_production_command: nil,
109
- i18n_dir: nil,
128
+ i18n_dir: nil, i18n_yml_dir: nil,
110
129
  server_render_method: nil, symlink_non_digested_assets_regex: nil)
111
130
  self.server_bundle_js_file = server_bundle_js_file
112
131
  self.generated_assets_dirs = generated_assets_dirs
@@ -114,6 +133,7 @@ module ReactOnRails
114
133
  self.npm_build_test_command = npm_build_test_command
115
134
  self.npm_build_production_command = npm_build_production_command
116
135
  self.i18n_dir = i18n_dir
136
+ self.i18n_yml_dir = i18n_yml_dir
117
137
 
118
138
  self.prerender = prerender
119
139
  self.replay_console = replay_console
@@ -39,14 +39,23 @@ module ReactOnRails
39
39
  end
40
40
 
41
41
  def locale_files
42
- @locale_files ||=
43
- (Rails.application && Rails.application.config.i18n.load_path).presence
42
+ @locale_files ||= begin
43
+ if i18n_yml_dir.present?
44
+ Dir["#{i18n_yml_dir}/**/*.yml"]
45
+ else
46
+ (Rails.application && Rails.application.config.i18n.load_path).presence
47
+ end
48
+ end
44
49
  end
45
50
 
46
51
  def i18n_dir
47
52
  @i18n_dir ||= ReactOnRails.configuration.i18n_dir
48
53
  end
49
54
 
55
+ def i18n_yml_dir
56
+ @i18n_yml_dir ||= ReactOnRails.configuration.i18n_yml_dir
57
+ end
58
+
50
59
  def default_locale
51
60
  @default_locale ||= I18n.default_locale.to_s || "en"
52
61
  end
@@ -6,7 +6,6 @@ module ReactOnRails
6
6
  include Utils::Required
7
7
 
8
8
  NO_PROPS = {}.freeze
9
- HIDDEN = "display:none".freeze
10
9
 
11
10
  def initialize(name: required("name"), options: required("options"))
12
11
  @name = name
@@ -14,7 +13,8 @@ module ReactOnRails
14
13
  end
15
14
 
16
15
  def props
17
- options.fetch(:props) { NO_PROPS }
16
+ props = options.fetch(:props) { NO_PROPS }
17
+ props.is_a?(String) ? JSON.parse(ERB::Util.json_escape(props)) : props
18
18
  end
19
19
 
20
20
  def name
@@ -54,11 +54,6 @@ module ReactOnRails
54
54
  }
55
55
  end
56
56
 
57
- def style
58
- return nil if ReactOnRails.configuration.skip_display_none
59
- HIDDEN
60
- end
61
-
62
57
  private
63
58
 
64
59
  attr_reader :options
@@ -1,3 +1,3 @@
1
1
  module ReactOnRails
2
- VERSION = "6.8.2".freeze
2
+ VERSION = "6.9.0".freeze
3
3
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "6.8.2",
3
+ "version": "6.9.0",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
data/rakelib/release.rake CHANGED
@@ -43,6 +43,8 @@ task :release, [:gem_version, :dry_run, :tools_install] do |_t, args|
43
43
 
44
44
  # Having the examples prevents publishing
45
45
  Rake::Task["examples:clobber"].invoke
46
+ # Delete any react_on_rails.gemspec except the root one
47
+ sh_in_dir(gem_root, "find . -mindepth 2 -name 'react_on_rails.gemspec' -delete")
46
48
 
47
49
  # See https://github.com/svenfuchs/gem-release
48
50
  sh_in_dir(gem_root, "git pull --rebase")
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: 6.8.2
4
+ version: 6.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-25 00:00:00.000000000 Z
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool