react_webpack_rails 0.0.5 → 0.1.0

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.
@@ -1,3 +1,3 @@
1
1
  module ReactWebpackRails
2
- VERSION = '0.0.5'.freeze
2
+ VERSION = '0.1.0'
3
3
  end
@@ -1,21 +1,33 @@
1
1
  module ReactWebpackRails
2
2
  module ViewHelpers
3
- # based on https://github.com/reactjs/react-rails/blob/master/lib/react/rails/view_helper.rb
4
- def react_component(name, props = {}, options = {}, &block)
5
- html_options = options.reverse_merge(data: {})
6
- html_options[:data].tap do |data|
7
- data[:react_class] = name
8
- data[:react_props] = (props.is_a?(String) ? props : props.to_json)
9
- data[:react_router] = options.delete(:react_router)
10
- end
11
- html_tag = html_options[:tag] || :div
12
- html_options.except!(:tag)
13
-
3
+ def react_element(integration_name, payload = {}, html_options = {}, &block)
4
+ data = {
5
+ integration_name: integration_name,
6
+ payload: payload,
7
+ react_element: true
8
+ }
9
+ html_options = html_options.merge(data: data)
10
+ html_tag = html_options.delete(:tag) || :div
14
11
  content_tag(html_tag, '', html_options, &block)
15
12
  end
16
13
 
14
+ def react_component(name, props = {}, options = { ssr: false })
15
+ props = camelize_props_key(props) if Rails.application.config.react.camelize_props
16
+ react_element('react-component', { props: props, name: name }, options)
17
+ end
18
+
17
19
  def react_router(name)
18
- react_component(name, {}, react_router: true)
20
+ react_element('react-router', name: name)
21
+ end
22
+
23
+ private
24
+
25
+ def camelize_props_key(props)
26
+ return props unless props.is_a?(Hash)
27
+ props.each_with_object({}) do |h, (k, v)|
28
+ h[k.to_s.camelize(:lower)] = v.is_a?(Hash) ? camelize_props_key(v) : v
29
+ h
30
+ end
19
31
  end
20
32
  end
21
33
  end
data/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "react-webpack-rails",
3
+ "version": "0.1.0",
4
+ "description": "Js part of react_webpack_rails - webpack based React & Rails integration.",
5
+ "main": "js/lib/index.js",
6
+ "files": [
7
+ "js/lib"
8
+ ],
9
+ "scripts": {
10
+ "compile": "babel --presets es2015 -d js/lib/ js/src/",
11
+ "prepublish": "npm run compile",
12
+ "test": "mocha js/test --ui bdd --recursive --require babel-core/register"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/netguru/react_webpack_rails.git"
17
+ },
18
+ "keywords": [
19
+ "react",
20
+ "rails",
21
+ "webpack",
22
+ "react_webpack_rails"
23
+ ],
24
+ "author": "Rafał Gawlik",
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/netguru/react_webpack_rails/issues"
28
+ },
29
+ "homepage": "https://github.com/netguru/react_webpack_rails#readme",
30
+ "peerDependencies": {
31
+ "react": "^0.14.0",
32
+ "react-dom": "^0.14.0"
33
+ },
34
+ "dependencies": {
35
+ "babel-polyfill": "^6.3.0"
36
+ },
37
+ "devDependencies": {
38
+ "babel-cli": "^6.4.0",
39
+ "babel-core": "^6.4.0",
40
+ "babel-preset-es2015": "^6.3.0",
41
+ "babel-preset-react": "^6.3.0",
42
+ "eslint": "^1.10.3",
43
+ "eslint-config-airbnb": "^3.1.0",
44
+ "eslint-plugin-react": "^3.15.0",
45
+ "expect": "^1.13.4",
46
+ "history": "^1.17.0",
47
+ "mocha": "^2.3.4"
48
+ }
49
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_webpack_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafał Gawlik
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-11-25 00:00:00.000000000 Z
12
+ date: 2016-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -75,7 +75,9 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
+ - ".babelrc"
78
79
  - ".gitignore"
80
+ - ".npmignore"
79
81
  - ".rspec"
80
82
  - ".travis.yml"
81
83
  - CHANGELOG.md
@@ -88,6 +90,19 @@ files:
88
90
  - docs/README.md
89
91
  - docs/api.md
90
92
  - docs/deployment.md
93
+ - js/.eslintrc
94
+ - js/src/env.js
95
+ - js/src/index.js
96
+ - js/src/integrations-manager.js
97
+ - js/src/integrations/react-router.js
98
+ - js/src/integrations/react.js
99
+ - js/src/nodes.js
100
+ - js/src/version.js
101
+ - js/test/env.spec.js
102
+ - js/test/integrations-manager.spec.js
103
+ - js/test/integrations/react-router.spec.js
104
+ - js/test/integrations/react.spec.js
105
+ - js/test/nodes.spec.js
91
106
  - lib/assets/javascripts/react_integration.js.erb
92
107
  - lib/generators/react_webpack_rails/install_generator.rb
93
108
  - lib/generators/react_webpack_rails/templates/.babelrc
@@ -107,6 +122,7 @@ files:
107
122
  - lib/react_webpack_rails/railtie.rb
108
123
  - lib/react_webpack_rails/version.rb
109
124
  - lib/react_webpack_rails/view_helpers.rb
125
+ - package.json
110
126
  - react_webpack_rails.gemspec
111
127
  homepage: https://github.com/netguru/react_webpack_rails
112
128
  licenses:
@@ -128,9 +144,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
144
  version: '0'
129
145
  requirements: []
130
146
  rubyforge_project:
131
- rubygems_version: 2.4.5
147
+ rubygems_version: 2.4.5.1
132
148
  signing_key:
133
149
  specification_version: 4
134
150
  summary: React and Rails integration done with webpack
135
151
  test_files: []
136
- has_rdoc: