react_on_rails 11.3.1 → 12.0.0.pre.beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +320 -0
  3. data/.eslintignore +2 -1
  4. data/.eslintrc +23 -1
  5. data/.github/FUNDING.yml +1 -0
  6. data/.gitignore +3 -1
  7. data/.prettierignore +10 -1
  8. data/.prettierrc +3 -0
  9. data/.rubocop.yml +37 -11
  10. data/.travis.yml +9 -20
  11. data/CHANGELOG.md +44 -19
  12. data/CONTRIBUTING.md +60 -71
  13. data/Gemfile +3 -4
  14. data/{COMM-LICENSE → REACT-ON-RAILS-PRO-LICENSE} +6 -9
  15. data/README.md +102 -69
  16. data/Rakefile +0 -7
  17. data/SUMMARY.md +7 -11
  18. data/book.json +5 -5
  19. data/docs/additional-reading/asset-pipeline.md +8 -16
  20. data/docs/additional-reading/react-helmet.md +30 -10
  21. data/docs/additional-reading/react-router.md +52 -75
  22. data/docs/additional-reading/server-rendering-tips.md +12 -7
  23. data/docs/api/javascript-api.md +3 -3
  24. data/docs/api/redux-store-api.md +4 -2
  25. data/docs/api/view-helpers-api.md +6 -7
  26. data/docs/basics/configuration.md +60 -57
  27. data/docs/basics/deployment.md +1 -2
  28. data/docs/basics/i18n.md +44 -22
  29. data/docs/basics/installation-into-an-existing-rails-app.md +2 -2
  30. data/docs/basics/react-server-rendering.md +1 -1
  31. data/docs/basics/{generator-functions-and-railscontext.md → render-functions-and-railscontext.md} +59 -21
  32. data/docs/basics/upgrading-react-on-rails.md +50 -2
  33. data/docs/basics/webpack-configuration.md +15 -1
  34. data/docs/contributor-info/errors-with-hooks.md +45 -0
  35. data/docs/contributor-info/pull-requests.md +44 -0
  36. data/docs/misc/doctrine.md +1 -1
  37. data/docs/{misc-pending → outdated}/code-splitting.md +12 -8
  38. data/docs/{additional-reading → outdated}/heroku-deployment.md +0 -6
  39. data/docs/{basics → outdated}/how-react-on-rails-works.md +2 -2
  40. data/docs/{misc-pending → outdated}/manual-installation-overview.md +5 -5
  41. data/docs/{additional-reading → outdated}/rails-assets-relative-paths.md +3 -3
  42. data/docs/{misc-pending → outdated}/rails-assets.md +4 -7
  43. data/docs/{misc → outdated}/rails3.md +0 -0
  44. data/docs/tutorial.md +54 -34
  45. data/jest.config.js +4 -0
  46. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
  47. data/lib/generators/react_on_rails/generator_helper.rb +4 -6
  48. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +9 -8
  49. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +1 -8
  50. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +4 -8
  51. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js +1 -3
  52. data/lib/react_on_rails.rb +3 -1
  53. data/lib/react_on_rails/configuration.rb +13 -22
  54. data/lib/react_on_rails/error.rb +2 -0
  55. data/lib/react_on_rails/helper.rb +41 -91
  56. data/lib/react_on_rails/json_parse_error.rb +2 -0
  57. data/lib/react_on_rails/locales/base.rb +142 -0
  58. data/lib/react_on_rails/locales/to_js.rb +37 -0
  59. data/lib/react_on_rails/locales/to_json.rb +27 -0
  60. data/lib/react_on_rails/prerender_error.rb +11 -15
  61. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +41 -46
  62. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +7 -8
  63. data/lib/react_on_rails/utils.rb +14 -19
  64. data/lib/react_on_rails/version.rb +1 -1
  65. data/lib/react_on_rails/version_checker.rb +1 -0
  66. data/lib/react_on_rails/webpacker_utils.rb +13 -2
  67. data/lib/tasks/assets.rake +5 -45
  68. data/lib/tasks/locale.rake +8 -2
  69. data/package-scripts.yml +11 -8
  70. data/package.json +29 -28
  71. data/rakelib/dummy_apps.rake +1 -9
  72. data/rakelib/example_type.rb +3 -1
  73. data/rakelib/examples.rake +3 -0
  74. data/rakelib/lint.rake +2 -7
  75. data/rakelib/node_package.rake +2 -2
  76. data/rakelib/run_rspec.rake +5 -18
  77. data/react_on_rails.gemspec +3 -5
  78. data/tsconfig.json +14 -0
  79. data/webpackConfigLoader.js +3 -2
  80. data/yarn.lock +4170 -2197
  81. metadata +30 -55
  82. data/Gemfile.rails32 +0 -73
  83. data/docs/additional-reading/babel.md +0 -5
  84. data/docs/additional-reading/hot-reloading-rails-development-asset-pipeline.md +0 -47
  85. data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
  86. data/lib/react_on_rails/assets_precompile.rb +0 -153
  87. data/lib/react_on_rails/locales_to_js.rb +0 -138
@@ -1,138 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "erb"
4
-
5
- module ReactOnRails
6
- class LocalesToJs
7
- def initialize
8
- return if i18n_dir.nil?
9
- return unless obsolete?
10
-
11
- @translations, @defaults = generate_translations
12
- convert
13
- end
14
-
15
- private
16
-
17
- def obsolete?
18
- return true if exist_js_files.empty?
19
-
20
- js_files_are_outdated
21
- end
22
-
23
- def exist_js_files
24
- @exist_js_files ||= js_files.select(&File.method(:exist?))
25
- end
26
-
27
- def js_files_are_outdated
28
- latest_yml = locale_files.map(&File.method(:mtime)).max
29
- earliest_js = exist_js_files.map(&File.method(:mtime)).min
30
- latest_yml > earliest_js
31
- end
32
-
33
- def js_file_names
34
- %w[translations default]
35
- end
36
-
37
- def js_files
38
- @js_files ||= js_file_names.map { |n| js_file(n) }
39
- end
40
-
41
- def js_file(name)
42
- "#{i18n_dir}/#{name}.js"
43
- end
44
-
45
- def locale_files
46
- @locale_files ||= begin
47
- if i18n_yml_dir.present?
48
- Dir["#{i18n_yml_dir}/**/*.yml"]
49
- else
50
- ReactOnRails::Utils.truthy_presence(
51
- Rails.application && Rails.application.config.i18n.load_path
52
- ).presence
53
- end
54
- end
55
- end
56
-
57
- def i18n_dir
58
- @i18n_dir ||= ReactOnRails.configuration.i18n_dir
59
- end
60
-
61
- def i18n_yml_dir
62
- @i18n_yml_dir ||= ReactOnRails.configuration.i18n_yml_dir
63
- end
64
-
65
- def default_locale
66
- @default_locale ||= I18n.default_locale.to_s || "en"
67
- end
68
-
69
- def convert
70
- js_file_names.each do |name|
71
- template = send("template_#{name}")
72
- path = js_file(name)
73
- generate_js_file(template, path)
74
- end
75
- end
76
-
77
- def generate_js_file(template, path)
78
- result = ERB.new(template).result()
79
- File.open(path, "w") do |f|
80
- f.write(result)
81
- end
82
- end
83
-
84
- def generate_translations
85
- translations = {}
86
- defaults = {}
87
- locale_files.each do |f|
88
- translation = YAML.safe_load(File.open(f))
89
- key = translation.keys[0]
90
- val = flatten(translation[key])
91
- translations = translations.deep_merge(key => val)
92
- defaults = defaults.deep_merge(flatten_defaults(val)) if key == default_locale
93
- end
94
- [translations.to_json, defaults.to_json]
95
- end
96
-
97
- def format(input)
98
- input.to_s.tr(".", "_").camelize(:lower).to_sym
99
- end
100
-
101
- def flatten_defaults(val)
102
- flatten(val).each_with_object({}) do |(k, v), h|
103
- key = format(k)
104
- h[key] = { id: k, defaultMessage: v }
105
- end
106
- end
107
-
108
- def flatten(translations)
109
- translations.each_with_object({}) do |(k, v), h|
110
- if v.is_a? Hash
111
- flatten(v).map { |hk, hv| h["#{k}.#{hk}".to_sym] = hv }
112
- elsif v.is_a?(String)
113
- h[k] = v.gsub("%{", "{")
114
- elsif !v.is_a?(Array)
115
- h[k] = v
116
- end
117
- end
118
- end
119
-
120
- def template_translations
121
- <<-JS.strip_heredoc
122
- export const translations = #{@translations};
123
- JS
124
- end
125
-
126
- def template_default
127
- <<-JS.strip_heredoc
128
- import { defineMessages } from 'react-intl';
129
-
130
- const defaultLocale = \'#{default_locale}\';
131
-
132
- const defaultMessages = defineMessages(#{@defaults});
133
-
134
- export { defaultMessages, defaultLocale };
135
- JS
136
- end
137
- end
138
- end