react-router-rails 0.11.6 → 0.11.6.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d72ad34f48bc662329a91dfae33007998a9accfc
4
- data.tar.gz: 9acca7f0f94fa759292a784c56aab7d9ce65ded8
3
+ metadata.gz: e07cf28306d1d239726cc55899f915debdfb561d
4
+ data.tar.gz: 51e18933b73b2b4d2713797dad291b4fcb56dc48
5
5
  SHA512:
6
- metadata.gz: 3d5beb7f413194b17873d8ff435392f9c135320f844834c2037685752a088688903f070d330e2b289e2045c163a2308c56bfebeebe55dbb46d80e58029ff93f8
7
- data.tar.gz: 2e457caa3607b621f351c1af0bb3e49c700e59c1ce338dc1075a34051ca87db53ddd785d95289ad6d74ab0814c1c81abcff79d53180a786f7ccf7331c873aa17
6
+ metadata.gz: ffb52fb0fe227097da416a3dfc4d0b8879e5eb260ddfb15177f20e7d6521b222810aca7b81f1dda8821f017146115135cc14d00c966180e4975b92c19938d35e
7
+ data.tar.gz: 644b2270f47b15caffbca27abbb76feec2809fef64c9cbb610904e18e0ece3af0c528a1a8daea3892e6e15848d9a0b92d9fd2e29212ad4884d5be2bfe3f2a84c
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # react-router-rails
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/react-router-rails.svg)](https://badge.fury.io/rb/react-router-rails.svg)
4
+
3
5
  [React Router](https://github.com/rackt/react-router/) for Rails asset pipeline
4
6
 
5
7
  - React Router version: [0.11.6](https://github.com/rackt/react-router/tree/v0.11.6)
@@ -30,9 +32,37 @@
30
32
  #= require react_router
31
33
  #OR
32
34
  #= require react_router.min
35
+
36
+ #Optional. Gives you the ability to use the view helper in your template
37
+ #= require react_router_ujs
38
+ ```
39
+ 3. Using the view helper:
40
+
41
+ Define your routes 'MyRoutes' in any javascript file like you would normally do:
42
+
43
+ ```coffeescript
44
+ Route = ReactRouter.Route
45
+
46
+ @AppRoutes = (
47
+ <Route handler={App}>
48
+ <Route name='home' handler={Home} path='/' />
49
+ </Route>
50
+ )
33
51
  ```
34
52
 
35
- 3. Using React Router in your javascript:
53
+ In the view helper set the name of your routes component
54
+
55
+ ```erb
56
+ <%= react_router 'MyRoutes' %>
57
+ ```
58
+
59
+ Optionally set the location handler (defaults to HashLocation):
60
+
61
+ ```erb
62
+ <%= react_router 'MyRoutes', 'HistoryLocation' %>
63
+ ```
64
+
65
+ 4. Using React Router in your javascript :
36
66
 
37
67
  ```js
38
68
  ReactRouter.run(routes, function (Handler) {
@@ -50,6 +80,8 @@
50
80
 
51
81
  ## Acknowledgements
52
82
 
53
- [React Router](https://github.com/rackt/react-router/) by Ryan Florence, Michael Jackson licensed under the [MIT license](https://github.com/rackt/react-router/blob/master/LICENSE)
83
+ This gem is highly inspired and based on [React Rails](https://github.com/reactjs/react-rails) code. Thanks!
84
+
85
+ [React Router](https://github.com/rackt/react-router/) by [Ryan Florence](https://github.com/rpflorence), [Michael Jackson](https://github.com/mjackson) licensed under the [MIT license](https://github.com/rackt/react-router/blob/master/LICENSE)
54
86
 
55
87
  Copyright [Mario Peixoto](https://github.com/mariopeixoto), released under the [MIT license](https://github.com/mariopeixoto/react-router-rails/LICENSE).
@@ -1,2 +1,4 @@
1
1
  require "react/router/rails/version"
2
- require "react/router/rails/engine"
2
+ require 'react/router/rails/railtie'
3
+ require "react/router/rails/engine"
4
+ require 'react/router/rails/view_helper'
@@ -0,0 +1,18 @@
1
+ require 'rails'
2
+
3
+ module React
4
+ module Router
5
+ module Rails
6
+ class Railtie < ::Rails::Railtie
7
+
8
+ # Include the react-router-rails view helper lazily
9
+ initializer "react_router_rails.setup_view_helpers" do |app|
10
+ ActiveSupport.on_load(:action_view) do
11
+ include ::React::Router::Rails::ViewHelper
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,7 +1,7 @@
1
1
  module React
2
2
  module Router
3
3
  module Rails
4
- VERSION = "0.11.6"
4
+ VERSION = "0.11.6.1"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,17 @@
1
+ module React
2
+ module Router
3
+ module Rails
4
+ module ViewHelper
5
+ def react_router(routes, location = 'HashLocation', &block)
6
+ html_options = {
7
+ :'data-react-router-class' => routes,
8
+ :'data-react-router-location' => location
9
+ }
10
+
11
+ content_tag(:div, '', html_options, &block)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,69 @@
1
+ // Unobtrusive scripting adapter for React Router based on react-rails gem.
2
+ // https://github.com/reactjs/react-rails/blob/master/lib/assets/javascripts/react_ujs.js
3
+ (function(document, window, React, ReactRouter) {
4
+ var ROUTER_CLASS_NAME = 'data-react-router-class';
5
+ var LOCATION_CLASS_NAME = 'data-react-router-location';
6
+
7
+ // jQuery is optional. Use it to support legacy browsers.
8
+ var $ = (typeof jQuery !== 'undefined') && jQuery;
9
+
10
+ var findReactRouterDOMNodes = function() {
11
+ var SELECTOR = '[' + ROUTER_CLASS_NAME + ']';
12
+ if ($) {
13
+ return $(SELECTOR);
14
+ } else {
15
+ return document.querySelectorAll(SELECTOR);
16
+ }
17
+ };
18
+
19
+ var mountReactRouter = function() {
20
+ var nodes = findReactRouterDOMNodes();
21
+ if (nodes.length >= 1) {
22
+ if (nodes.length > 1) {
23
+ console.warn('React Router is designed to have a single root router. ' + nodes.length + ' routers were found on the html. Using the first one.');
24
+ }
25
+ var routerNode = nodes[0];
26
+
27
+ // Assume className is simple and can be found at top-level (window).
28
+ // Fallback to eval to handle cases like 'My.React.ComponentName'.
29
+ var className = routerNode.getAttribute(ROUTER_CLASS_NAME);
30
+ var routes = window[className] || eval.call(window, className);
31
+
32
+ var locationName = routerNode.getAttribute(LOCATION_CLASS_NAME);
33
+ var location = ReactRouter[locationName] ;
34
+
35
+ ReactRouter.run(routes, location, function (Handler) {
36
+ React.render(React.createElement(Handler), routerNode);
37
+ });
38
+ }
39
+ };
40
+
41
+ var handleTurbolinksEvents = function() {
42
+ var handleEvent;
43
+ if ($) {
44
+ handleEvent = function(eventName, callback) {
45
+ $(document).on(eventName, callback);
46
+ }
47
+ } else {
48
+ handleEvent = function(eventName, callback) {
49
+ document.addEventListener(eventName, callback);
50
+ }
51
+ }
52
+ handleEvent('page:change', mountReactRouter);
53
+ };
54
+
55
+ var handleNativeEvents = function() {
56
+ if ($) {
57
+ $(mountReactRouter);
58
+ } else {
59
+ document.addEventListener('DOMContentLoaded', mountReactRouter);
60
+ }
61
+ };
62
+
63
+ if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) {
64
+ handleTurbolinksEvents();
65
+ } else {
66
+ handleNativeEvents();
67
+ }
68
+
69
+ })(document, window, React, ReactRouter);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react-router-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.6
4
+ version: 0.11.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Peixoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-22 00:00:00.000000000 Z
11
+ date: 2015-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -63,9 +63,12 @@ files:
63
63
  - README.md
64
64
  - lib/react/router/rails.rb
65
65
  - lib/react/router/rails/engine.rb
66
+ - lib/react/router/rails/railtie.rb
66
67
  - lib/react/router/rails/version.rb
68
+ - lib/react/router/rails/view_helper.rb
67
69
  - vendor/assets/javascripts/react_router.js
68
70
  - vendor/assets/javascripts/react_router.min.js
71
+ - vendor/assets/javascripts/react_router_ujs.js
69
72
  homepage: https://github.com/mariopeixoto/react-router-rails
70
73
  licenses:
71
74
  - MIT