react_on_rails 6.10.0 → 6.10.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
  SHA1:
3
- metadata.gz: 469a8ff901950ef0d6b78f656e2171745ba38692
4
- data.tar.gz: 53d686b193981bfc42b256f8f37092a025b34a87
3
+ metadata.gz: 1b8e8a575ac81a5b58a9fdb4d28efd3e88c04fc7
4
+ data.tar.gz: 8dae777aa4200fa6c0c55a242d2162ce0f9175fa
5
5
  SHA512:
6
- metadata.gz: af358a7afeebd6dab050233da74ba44c2f92ad2445ea0ca6c07874d1809392b77c8c1c74075756c71ea365210da26c8e9ef7013b2d531c78aca1dc43126c930d
7
- data.tar.gz: f3f5dfb830d68e6aa8638301267f0697a9940812663f125e848b5533489e26e0fddc279a4c8b23cf153e8fd1806a1972cea5a14a038a4f4db2bb2e398cf1daeb
6
+ metadata.gz: 143e5f35ed703170d068f6befe68df596219b8264195ee2e2b2a0b829d9f2cdcfff8452131a64c05cd2960a030c5114741b2dd5947264b42146f52d9b7ae7708
7
+ data.tar.gz: 68da88fa5969e6e497cfcf8ccfeb068a5bb162793cb55a8b978cb00a400f469e2a2c656e1aaa01d47d8809680e91a908fe7311536b9505cbb5622f7886eb76a9
@@ -4,8 +4,12 @@ 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
+ ## [6.10.1] - 2017-04-23
8
+ ### Fixed
9
+ - Improve json conversion with tests and support for older Rails 3.x. [#787](https://github.com/shakacode/react_on_rails/pull/787) by [cheremukhin23](https://github.com/cheremukhin23) and [Ynote](https://github.com/Ynote).
7
10
 
8
11
  ## [6.10.0] - 2017-04-13
12
+
9
13
  ### Added
10
14
  - Add an ability to return multiple HTML strings in a `Hash` as a result of `react_component` method call. Allows to build `<head>` contents with [React Helmet](https://github.com/nfl/react-helmet). [#800](https://github.com/shakacode/react_on_rails/pull/800) by [udovenko](https://github.com/udovenko).
11
15
 
@@ -530,7 +534,8 @@ Best done with Object destructing:
530
534
  ##### Fixed
531
535
  - Fix several generator related issues.
532
536
 
533
- [Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.10.0...master
537
+ [Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.10.1...master
538
+ [6.10.1]: https://github.com/shakacode/react_on_rails/compare/6.10.0...6.10.1
534
539
  [6.10.0]: https://github.com/shakacode/react_on_rails/compare/6.9.3...6.10.0
535
540
  [6.9.3]: https://github.com/shakacode/react_on_rails/compare/6.9.1...6.9.3
536
541
  [6.9.2]: https://github.com/shakacode/react_on_rails/compare/6.9.1...6.9.2
@@ -1,6 +1,6 @@
1
1
  # Projects using React on Rails
2
2
 
3
- *Please add your project to this list.*
3
+ *Please support the project by [emailing Justin Gordon](mailto:justin@shakacode.com) of any projects, yours or others, that use React on Rails. You can confirm a project uses React on Rails as the source will contain **`js-react-on-rails`**.*
4
4
 
5
5
  ## Commercial Products Live
6
6
  * **[Friends and Guests](https://www.friendsandguests.com/)**, the signature product of [ShakaCode](http://www.shakacode.com), which is a "Network Connecting Hosts and Guests".
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  **For a complete example of this gem, see our live demo at [www.reactrails.com](http://www.reactrails.com). ([Source Code](https://github.com/shakacode/react-webpack-rails-tutorial))**
4
4
 
5
- Aloha from Justin Gordon ([bio](http://www.railsonmaui.com/about)) and the [ShakaCode](http://www.shakacode.com) Team! We're actively looking for new projects involving React, React-Native, and Rails, including conversion of AngularJs to React. Please [contact me](mailto:justin@shakacode.com) if we could potentially help you in any way. Besides consulting on bigger projects, [ShakaCode](http://www.shakacode.com) is doing ScreenHero plus Slack/Github based coaching for React on Rails. See our blog post [Can ShakaCode Help You?](https://blog.shakacode.com/can-shakacode-help-you-4a5b1e5a8a63#.jex6tg9w9) for more information.
5
+ **Speaking!**: Justin is speaking [GORUCO](http://goruco.com/#speakers) on Saturday, June 24, 2017 in NYC: "Front-End Sadness to Happiness: The React on Rails Story". [Email Justin](mailto:justin@shakacode.com) to give this talk at your local meetup or company. [Subscribe](https://app.mailerlite.com/webforms/landing/l1d9x5) to be notified of local and *online* presentations of this talk.
6
+
7
+ **Aloha from Justin Gordon** ([bio](http://www.railsonmaui.com/about)) and the [ShakaCode](http://www.shakacode.com) Team! We're actively looking for new projects involving React, React-Native, and Rails, including conversion of AngularJs to React. Please [contact me](mailto:justin@shakacode.com) if we could potentially help you in any way. Besides consulting on bigger projects, [ShakaCode](http://www.shakacode.com) is doing ScreenHero plus Slack/Github based [coaching](http://www.shakacode.com/work/shakacode-coaching-plan.pdf) for React on Rails. See our blog post [Can ShakaCode Help You?](https://blog.shakacode.com/can-shakacode-help-you-4a5b1e5a8a63#.jex6tg9w9) for more information.
6
8
 
7
9
  I'm offering a free half-hour project consultation, on anything from React on Rails to any aspect of web application development for both consumer and enterprise products. In addition to React.js and Rails, we're doing React-Native iOS and Android apps!
8
10
 
@@ -6,6 +6,7 @@
6
6
  require "react_on_rails/prerender_error"
7
7
  require "addressable/uri"
8
8
  require "react_on_rails/utils"
9
+ require "react_on_rails/json_output"
9
10
 
10
11
  module ReactOnRailsHelper
11
12
  include ReactOnRails::Utils::Required
@@ -224,6 +225,17 @@ module ReactOnRailsHelper
224
225
  # rubocop:enable Style/RaiseArgs
225
226
  end
226
227
 
228
+ def json_safe_and_pretty(hash_or_string)
229
+ unless hash_or_string.class.in?([Hash, String])
230
+ raise "#{__method__} only accepts String or Hash as argument "\
231
+ "(#{hash_or_string.class} given)."
232
+ end
233
+
234
+ json_value = hash_or_string.is_a?(String) ? hash_or_string : hash_or_string.to_json
235
+
236
+ ReactOnRails::JsonOutput.escape(json_value)
237
+ end
238
+
227
239
  private
228
240
 
229
241
  def build_react_component_result_for_server_rendered_string(
@@ -290,26 +302,6 @@ module ReactOnRailsHelper
290
302
  HTML
291
303
  end
292
304
 
293
- def json_safe_and_pretty(hash_or_string)
294
- # if Rails.env.development?
295
- # # TODO: for json_safe_and_pretty
296
- # # 1. Add test
297
- # # 2. Add error handler if cannot parse the string with nice message
298
- # # 3. Consider checking that if not a string then a Hash
299
- # hash_value = hash_or_string.is_a?(String) ? JSON.parse(hash_or_string) : hash_or_string
300
- # ERB::Util.json_escape(JSON.pretty_generate(hash_value))
301
- # else
302
- #
303
- # Temp fix given that a hash may contain active record objects and that crashed with the new
304
- # code to JSON.pretty_generate
305
-
306
- # If to_json is called on a String, then the quotes are escaped.
307
- json_value = hash_or_string.is_a?(String) ? hash_or_string : hash_or_string.to_json
308
-
309
- ERB::Util.json_escape(json_value)
310
- # end
311
- end
312
-
313
305
  # prepend the rails_context if not yet applied
314
306
  def prepend_render_rails_context(render_value)
315
307
  return render_value if @rendered_rails_context
@@ -0,0 +1,26 @@
1
+ require "active_support/core_ext/string/output_safety"
2
+
3
+ module ReactOnRails
4
+ class JsonOutput
5
+ ESCAPE_REPLACEMENT = {
6
+ "&" => '\u0026',
7
+ ">" => '\u003e',
8
+ "<" => '\u003c',
9
+ "\u2028" => '\u2028',
10
+ "\u2029" => '\u2029'
11
+ }.freeze
12
+ ESCAPE_REGEXP = /[\u2028\u2029&><]/u
13
+
14
+ def self.escape(json)
15
+ return escape_without_erb_util(json) if Utils.rails_version_less_than_4_1_1
16
+
17
+ ERB::Util.json_escape(json)
18
+ end
19
+
20
+ def self.escape_without_erb_util(json)
21
+ # https://github.com/rails/rails/blob/60257141462137331387d0e34931555cf0720886/activesupport/lib/active_support/core_ext/string/output_safety.rb#L113
22
+
23
+ json.to_s.gsub(ESCAPE_REGEXP, ESCAPE_REPLACEMENT)
24
+ end
25
+ end
26
+ end
@@ -24,6 +24,22 @@ module ReactOnRails
24
24
  (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
25
25
  end
26
26
 
27
+ def self.rails_version_less_than(version)
28
+ @rails_version_less_than ||= {}
29
+
30
+ if @rails_version_less_than.key?(version)
31
+ return @rails_version_less_than[version]
32
+ end
33
+
34
+ @rails_version_less_than[version] = begin
35
+ Gem::Version.new(Rails.version) < Gem::Version.new(version)
36
+ end
37
+ end
38
+
39
+ def self.rails_version_less_than_4_1_1
40
+ rails_version_less_than("4.1.1")
41
+ end
42
+
27
43
  module Required
28
44
  def required(arg_name)
29
45
  raise ArgumentError, "#{arg_name} is required"
@@ -1,3 +1,3 @@
1
1
  module ReactOnRails
2
- VERSION = "6.10.0".freeze
2
+ VERSION = "6.10.1".freeze
3
3
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "6.10.0",
3
+ "version": "6.10.1",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
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.10.0
4
+ version: 6.10.1
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-04-13 00:00:00.000000000 Z
11
+ date: 2017-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -401,6 +401,7 @@ files:
401
401
  - lib/react_on_rails/controller.rb
402
402
  - lib/react_on_rails/engine.rb
403
403
  - lib/react_on_rails/git_utils.rb
404
+ - lib/react_on_rails/json_output.rb
404
405
  - lib/react_on_rails/locales_to_js.rb
405
406
  - lib/react_on_rails/prerender_error.rb
406
407
  - lib/react_on_rails/react_component/options.rb