react-rails 1.8.2 → 1.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: 05bdf78ad02169578227f8c9d3ea5f1c5e48924d
4
- data.tar.gz: 70964006fa4e5ffc253df1f1f632e49eb938f0ee
3
+ metadata.gz: 908ecff764f2cb0ca4c4f3bfd190473b2aa25843
4
+ data.tar.gz: 6b3262ab4494e36f51185c6dbbfa23c6dfc5e936
5
5
  SHA512:
6
- metadata.gz: 99a66d4d850b409390205d7362797d2c71f9e59341e8c3452d4e76f01e2d3cc5371de9f1ad6fbae0da5170c6072dd343d18278cac4624f8839fe87da98c04e2e
7
- data.tar.gz: b283b0cc9a0e77c93358f24f6c3ff24aecd899424d772e97149666151a3383ca6e9c0eacbe3abb43224d0c70ea5a698702dc6143fece4407393cfc2a12fd9f52
6
+ metadata.gz: 2884a67467eb7f64fb7e7cd3875d63cfe26398d1c0fac87391f726ba4bbd6a6a3498d550fbb465f49359537df5ace2ccc53acb07dca00da2eb468e3a2966e983
7
+ data.tar.gz: 5abf1e17ce029213a45697e5a7d7a51f16d3db7ced7971acc82e7ac5aa138e33d2e37b3d738542463d9c99d799aa7b98992d91db7123f20cc670b55e90b8dcb5
data/CHANGELOG.md CHANGED
@@ -8,6 +8,29 @@
8
8
 
9
9
  #### Bug Fixes
10
10
 
11
+ ## 1.9.0 (October 6, 2016)
12
+
13
+ #### Breaking Changes
14
+
15
+ #### New Features
16
+
17
+ - Accept extra JS code in `code:` option for SprocketsRenderer #604
18
+
19
+ #### Bug Fixes
20
+
21
+ - Use `asset_prefix` for YamlContainer #598
22
+ - Fix requiring `.js` from `.es6.jsx` #591
23
+
24
+ ## 1.8.2 (August 9, 2016)
25
+
26
+ #### New Features
27
+
28
+ - Update to React 15.3.0 #583
29
+
30
+ #### Bug Fixes
31
+
32
+ - Fix `//= require` on Sprockets 3.7+ #582
33
+
11
34
  ## 1.8.1 (July 29, 2016)
12
35
 
13
36
  #### New Features
data/lib/react/jsx.rb CHANGED
@@ -3,6 +3,7 @@ require 'react/jsx/processor'
3
3
  require 'react/jsx/template'
4
4
  require 'react/jsx/jsx_transformer'
5
5
  require 'react/jsx/babel_transformer'
6
+ require 'react/jsx/sprockets_strategy'
6
7
  require 'rails'
7
8
 
8
9
  module React
@@ -0,0 +1,53 @@
1
+ module React
2
+ module JSX
3
+ # Depending on the Sprockets version,
4
+ # attach JSX transformation the the Sprockets environment.
5
+ #
6
+ # You can override it with `config.sprockets_strategy`
7
+ # @example Specifying a Sprockets strategy
8
+ # app.config.react.sprockets_strategy = :register_engine
9
+ #
10
+ # @example Opting out of any Sprockets strategy
11
+ # app.config.react.sprockets_strategy = false
12
+ #
13
+ module SprocketsStrategy
14
+ module_function
15
+
16
+ # @param [Sprockets::Environment] the environment to attach JSX to
17
+ # @param [Symbol, Nil] A strategy name, or `nil` to detect a strategy
18
+ def attach_with_strategy(sprockets_env, strategy_or_nil)
19
+ strategy = strategy_or_nil || detect_strategy
20
+ self.public_send(strategy, sprockets_env)
21
+ end
22
+
23
+ # @return [Symbol] based on the environment, return a method name to call with the sprockets environment
24
+ def detect_strategy
25
+ sprockets_version = Gem::Version.new(Sprockets::VERSION)
26
+ if sprockets_version >= Gem::Version.new("4.x")
27
+ :register_processors
28
+ elsif sprockets_version >= Gem::Version.new("3.0.0")
29
+ :register_engine_with_mime_type
30
+ else
31
+ :register_engine
32
+ end
33
+ end
34
+
35
+ def register_engine(sprockets_env)
36
+ sprockets_env.register_engine(".jsx", React::JSX::Template)
37
+ end
38
+
39
+ def register_engine_with_mime_type(sprockets_env)
40
+ sprockets_env.register_engine(".jsx", React::JSX::Processor, mime_type: "application/javascript", silence_deprecation: true)
41
+ end
42
+
43
+ def register_processors(sprockets_env)
44
+ sprockets_env.register_mime_type("application/jsx", extensions: [".jsx", ".js.jsx", ".es.jsx", ".es6.jsx"])
45
+ sprockets_env.register_mime_type("application/jsx+coffee", extensions: [".jsx.coffee", ".js.jsx.coffee"])
46
+ sprockets_env.register_transformer("application/jsx", "application/javascript", React::JSX::Processor)
47
+ sprockets_env.register_transformer("application/jsx+coffee", "application/jsx", Sprockets::CoffeeScriptProcessor)
48
+ sprockets_env.register_preprocessor("application/jsx", Sprockets::DirectiveProcessor.new(comments: ["//", ["/*", "*/"]]))
49
+ sprockets_env.register_preprocessor("application/jsx+coffee", Sprockets::DirectiveProcessor.new(comments: ["#", ["###", "###"]]))
50
+ end
51
+ end
52
+ end
53
+ end
@@ -10,6 +10,7 @@ module React
10
10
  config.react.jsx_transform_options = {}
11
11
  config.react.jsx_transformer_class = nil # defaults to BabelTransformer
12
12
  config.react.camelize_props = false # pass in an underscored hash but get a camelized hash
13
+ config.react.sprockets_strategy = nil # how to attach JSX to the asset pipeline (or `false` for none)
13
14
 
14
15
  # Server rendering:
15
16
  config.react.server_renderer_pool_size = 1 # increase if you're on JRuby
@@ -100,19 +101,12 @@ module React
100
101
  # Sprockets 3.x expects this in a different place
101
102
  sprockets_env = app.assets || defined?(Sprockets) && Sprockets
102
103
 
103
- if !sprockets_env.nil?
104
- if Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new("3.7.0")
105
- sprockets_env.register_mime_type("application/jsx", extensions: [".jsx", ".js.jsx", ".es.jsx", ".es6.jsx"])
106
- sprockets_env.register_mime_type("application/jsx+coffee", extensions: [".jsx.coffee", ".js.jsx.coffee"])
107
- sprockets_env.register_transformer("application/jsx", "application/javascript", React::JSX::Processor)
108
- sprockets_env.register_transformer("application/jsx+coffee", "application/jsx", Sprockets::CoffeeScriptProcessor)
109
- sprockets_env.register_preprocessor("application/jsx", Sprockets::DirectiveProcessor.new(comments: ["//", ["/*", "*/"]]))
110
- sprockets_env.register_preprocessor("application/jsx+coffee", Sprockets::DirectiveProcessor.new(comments: ["#", ["###", "###"]]))
111
- elsif Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new("3.0.0")
112
- sprockets_env.register_engine(".jsx", React::JSX::Processor, mime_type: "application/javascript")
113
- else
114
- sprockets_env.register_engine(".jsx", React::JSX::Template)
115
- end
104
+ if app.config.react.sprockets_strategy == false
105
+ # pass, Sprockets opt-out
106
+ elsif sprockets_env.present?
107
+ React::JSX::SprocketsStrategy.attach_with_strategy(sprockets_env, app.config.react.sprockets_strategy)
108
+ else
109
+ # pass, Sprockets is not preset
116
110
  end
117
111
  end
118
112
  end
@@ -2,6 +2,6 @@ module React
2
2
  module Rails
3
3
  # If you change this, make sure to update VERSIONS.md
4
4
  # And the version hint in README.md, if needed
5
- VERSION = "1.8.2"
5
+ VERSION = "1.9.0"
6
6
  end
7
7
  end
@@ -17,6 +17,7 @@ module React
17
17
  @replay_console = options.fetch(:replay_console, true)
18
18
  filenames = options.fetch(:files, ["react-server.js", "components.js"])
19
19
  js_code = CONSOLE_POLYFILL.dup
20
+ js_code << options.fetch(:code, '')
20
21
 
21
22
  filenames.each do |filename|
22
23
  js_code << asset_container.find_asset(filename)
@@ -6,12 +6,12 @@ module React
6
6
  # but sometimes, they're compiled to other directories (or other servers)
7
7
  class YamlManifestContainer
8
8
  def initialize
9
- @assets = YAML.load_file(::Rails.root.join("public/assets/manifest.yml"))
9
+ @assets = YAML.load_file(::Rails.root.join("public", ::Rails.application.config.assets.prefix, "manifest.yml"))
10
10
  end
11
11
 
12
12
  def find_asset(logical_path)
13
13
  asset_path = @assets[logical_path] || raise("No compiled asset for #{logical_path}, was it precompiled?")
14
- asset_full_path = ::Rails.root.join("public", "assets", asset_path)
14
+ asset_full_path = ::Rails.root.join("public", ::Rails.application.config.assets.prefix, asset_path)
15
15
  File.read(asset_full_path)
16
16
  end
17
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul O’Shannessy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-09 00:00:00.000000000 Z
11
+ date: 2016-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -315,6 +315,7 @@ files:
315
315
  - lib/react/jsx/babel_transformer.rb
316
316
  - lib/react/jsx/jsx_transformer.rb
317
317
  - lib/react/jsx/processor.rb
318
+ - lib/react/jsx/sprockets_strategy.rb
318
319
  - lib/react/jsx/template.rb
319
320
  - lib/react/rails.rb
320
321
  - lib/react/rails/asset_variant.rb