hyper-router 4.1.1 → 4.2.6.lap22

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: cdd67209abe4796f00f93341e2cade73a89450b5
4
- data.tar.gz: a9a01054f1f528518234836a7b4068e7e815f5d0
3
+ metadata.gz: fadc957c6b724c58a23a188aa45851dcef486324
4
+ data.tar.gz: 1f8e828dab34572bcaa53e18d42b67538b63337f
5
5
  SHA512:
6
- metadata.gz: 6f23a61bc404a5ec208bd6a1dfe8d6e08d39446fac5411cf83eb644a4b594451f6e060b64e73025e173bea63c2ecf4946dc79ef404e7f2ade7b514f64e9df38f
7
- data.tar.gz: 74be482b96d8aca1fc0d38f55be6cb90297cd9d00231e8b9a1af7b338dc24818587c96bf09abfce2d9da480e971b28fd827d31bd586701cdae6cff00ac8b1126
6
+ metadata.gz: db0b782f9ec8817c46f6c96bf09f07a9493e8ce11816395a25cf2924ec1c9b51261a7e78b279f2a1a1edc2c57ed416848cd623f50c50d008aaf25c55a7e56ae7
7
+ data.tar.gz: 3e795b7a3ff0bb79fd35317f2be4754781b6e8d342f66bf7bc9355544bfb524994b7f0e5240e0a086d4ecae8a6f31f04d4bb62b49100758d080c9e183a948314
data/README.md CHANGED
@@ -1,458 +1,79 @@
1
- <p align="center">
2
- <a href="http://ruby-hyperloop.io/" alt="Hyperloop" title="Hyperloop">
3
- <img src="https://github.com/ruby-hyperloop/ruby-hyperloop.io/blob/source/source/images/HyperRouter.png" width="150px"/>
4
- </a>
5
- </p>
6
-
7
- <h1 align="center">
8
- HyperRouter
9
- </h1>
1
+ <div class="githubhyperloopheader">
10
2
 
11
3
  <p align="center">
12
- HyperRouter allows you write and use the React Router in Ruby through Opal.
13
- </p>
14
-
15
-
16
- ## Installation
17
-
18
- Add this line to your application's Gemfile:
19
- ```ruby
20
- gem 'hyper-router'
21
- ```
22
- Or execute:
23
- ```bash
24
- gem install hyper-router
25
- ```
26
-
27
- Then add this to your components.rb:
28
- ```ruby
29
- require 'hyper-router'
30
- ```
31
-
32
- ### Using the included source
33
- Add this to your component.rb:
34
- ```ruby
35
- require 'hyper-router/react-router-source'
36
- require 'hyper-router'
37
- ```
38
-
39
- ### Using with NPM/Webpack
40
- react-router has now been split into multiple packages, so make sure they are all installed
41
- ```bash
42
- npm install react-router react-router-dom history --save
43
- ```
44
-
45
- Add these to your webpack js file:
46
- ```javascript
47
- ReactRouter = require('react-router')
48
- ReactRouterDOM = require('react-router-dom')
49
- History = require('history')
50
- ```
51
-
52
- ## Usage
53
-
54
- This is simply a DSL wrapper on [react-router](https://github.com/ReactTraining/react-router)
55
-
56
- ## Warning!!
57
- The folks over at react-router have gained a reputation for all their API rewrites, so with V4 we have made some changes to follow.
58
- This version is **incompatible** with previous versions' DSL.
59
-
60
- ### DSL
61
-
62
- Here is the basic example that is used on the [react-router site](https://reacttraining.com/react-router/)
63
-
64
- ```javascript
65
- import React from 'react'
66
- import {
67
- BrowserRouter as Router,
68
- Route,
69
- Link
70
- } from 'react-router-dom'
71
-
72
- const BasicExample = () => (
73
- <Router>
74
- <div>
75
- <ul>
76
- <li><Link to="/">Home</Link></li>
77
- <li><Link to="/about">About</Link></li>
78
- <li><Link to="/topics">Topics</Link></li>
79
- </ul>
80
-
81
- <hr/>
82
-
83
- <Route exact path="/" component={Home}/>
84
- <Route path="/about" component={About}/>
85
- <Route path="/topics" component={Topics}/>
86
- </div>
87
- </Router>
88
- )
89
-
90
- const Home = () => (
91
- <div>
92
- <h2>Home</h2>
93
- </div>
94
- )
95
-
96
- const About = () => (
97
- <div>
98
- <h2>About</h2>
99
- </div>
100
- )
101
-
102
- const Topics = ({ match }) => (
103
- <div>
104
- <h2>Topics</h2>
105
- <ul>
106
- <li><Link to={`${match.url}/rendering`}>Rendering with React</Link></li>
107
- <li><Link to={`${match.url}/components`}>Components</Link></li>
108
- <li><Link to={`${match.url}/props-v-state`}>Props v. State</Link></li>
109
- </ul>
110
-
111
- <Route path={`${match.url}/:topicId`} component={Topic}/>
112
- <Route exact path={match.url} render={() => (
113
- <h3>Please select a topic.</h3>
114
- )}/>
115
- </div>
116
- )
117
-
118
- const Topic = ({ match }) => (
119
- <div>
120
- <h3>{match.params.topicId}</h3>
121
- </div>
122
- )
123
-
124
- export default BasicExample
125
- ```
126
-
127
- Here is what it looks like for us:
128
- ```ruby
129
- class BasicExample < Hyperloop::Router
130
- history :browser
131
-
132
- route do
133
- DIV do
134
- UL do
135
- LI { Link('/') { 'Home' } }
136
- LI { Link('/about') { 'About' } }
137
- LI { Link('/topics') { 'Topics' } }
138
- end
139
-
140
- Route('/', exact: true, mounts: Home)
141
- Route('/about', mounts: About)
142
- Route('/topics', mounts: Topics)
143
- end
144
- end
145
- end
146
-
147
- class Home < Hyperloop::Router::Component
148
- render(:div) do
149
- H2 { 'Home' }
150
- end
151
- end
152
-
153
- class About < Hyperloop::Router::Component
154
- render(:div) do
155
- H2 { 'About' }
156
- end
157
- end
158
-
159
- class Topics < Hyperloop::Router::Component
160
- render(:div) do
161
- H2 { 'Topics' }
162
- UL() do
163
- LI { Link("#{match.url}/rendering") { 'Rendering with React' } }
164
- LI { Link("#{match.url}/components") { 'Components' } }
165
- LI { Link("#{match.url}/props-v-state") { 'Props v. State' } }
166
- end
167
- Route("#{match.url}/:topic_id", mounts: Topic)
168
- Route(match.url, exact: true) do
169
- H3 { 'Please select a topic.' }
170
- end
171
- end
172
- end
173
-
174
- class Topic < Hyperloop::Router::Component
175
- render(:div) do
176
- H3 { match.params[:topic_id] }
177
- end
178
- end
179
- ```
180
-
181
- Since react-router migrated back to everything being a component,
182
- this makes the DSL very easy to follow if you have already used react-router v4.
183
-
184
- ### Router
185
-
186
- This is the base Router class, it can either be inherited or included:
187
- ```ruby
188
- class MyRouter < Hyperloop::Router
189
- end
190
-
191
- class MyRouter < React::Component::Base
192
- include Hyperloop::Router::Base
193
- end
194
- ```
195
4
 
196
- With the base Router class, you must specify the history you want to use.
5
+ <a href="http://ruby-hyperloop.org/" alt="Hyperloop" title="Hyperloop">
6
+ <img width="350px" src="http://ruby-hyperloop.org/images/hyperloop-github-logo.png">
7
+ </a>
197
8
 
198
- This can be done either using a macro:
199
- ```ruby
200
- class MyRouter < Hyperloop::Router
201
- history :browser
202
- end
203
- ```
204
- The macro accepts three options: `:browser`, `:hash`, or `:memory`.
205
-
206
- Or defining the `history` method:
207
- ```ruby
208
- class MyRouter < Hyperloop::Router
209
- def history
210
- self.class.browser_history
211
- end
212
- end
213
- ```
214
-
215
- ### BrowserRouter, HashRouter, MemoryRouter
216
-
217
- Using one of these classes automatically takes care of the history for you,
218
- so you don't need to specify one.
219
- They also can be used by inheritance or inclusion:
220
-
221
- ```ruby
222
- class MyRouter < Hyperloop::HashRouter
223
- end
224
-
225
- class MyRouter < React::Component::Base
226
- include Hyperloop::Router::Hash
227
- end
228
- ```
229
-
230
- ### StaticRouter
231
-
232
- Static router is a little different, since it doesn't actually have a history.
233
- These are used under-the-hood for any other Router during prerendering.
234
-
235
- ```ruby
236
- class MyRouter < Hyperloop::StaticRouter
237
- route do
238
- DIV do
239
- Route('/:name', mounts: Greet)
240
- end
241
- end
242
- end
243
- ```
244
-
245
- ### Rendering a Router
246
-
247
- To render children/routes use the `route` macro, it is the equivalent to `render` of a component.
248
- ```ruby
249
- class MyRouter < Hyperloop::Router
250
- ...
251
-
252
- route do
253
- DIV do
254
- H1 { 'Hello world!' }
255
- end
256
- end
257
- end
258
- ```
259
-
260
-
261
- ### Routes
262
-
263
- Routes are no longer defined separately, but are just components you call inside the router/components.
264
-
265
- ```ruby
266
- class MyRouter < Hyperloop::Router
267
- ...
268
-
269
- route do
270
- DIV do
271
- Route('/', mounts: HelloWorld)
272
- end
273
- end
274
- end
275
-
276
- class HelloWorld < React::Component::Base
277
- render do
278
- H1 { 'Hello world!' }
279
- end
280
- end
281
- ```
282
-
283
- The `Route` method takes a url path, and these options:
284
- - `mounts: Component` The component you want to mount when routed to
285
- - `exact: Boolean` When true, the path must match the location exactly
286
- - `strict: Boolean` When true, the path will only match if the location and path **both** have/don't have a trailing slash
287
- It can also take a block instead of the `mounts` option.
288
-
289
- ```ruby
290
- class MyRouter < Hyperloop::Router
291
- ...
292
-
293
- route do
294
- DIV do
295
- Route('/', exact: true) do
296
- H1 { 'Hello world!' }
297
- end
298
- end
299
- end
300
- end
301
- ```
302
- The block will give you the match, location, and history data:
303
- ```ruby
304
- class MyRouter < Hyperloop::Router
305
- ...
306
-
307
- route do
308
- DIV do
309
- Route('/:name') do |match, location, history|
310
- H1 { "Hello #{match.params[:foo]} from #{location.pathname}, click me to go back!" }
311
- .on(:click) { history.go_back }
312
- end
313
- end
314
- end
315
- end
316
- ```
9
+ </p>
317
10
 
318
- It is recommended to inherit from `Hyperloop::Router::Component` for components mounted by routes.
319
- This automatically sets the `match`, `location`, and `history` params,
320
- and also gives you instance methods with those names.
321
- You can use either `params.match` or just `match`.
322
- and gives you access to the Route method and more.
323
- This allows you to create inner routes as you need them.
324
- ```ruby
325
- class MyRouter < Hyperloop::Router
326
- ...
11
+ <h2 align="center">The Complete Isomorphic Ruby Framework</h2>
327
12
 
328
- route do
329
- DIV do
330
- Route('/:name', mounts: Greet)
331
- end
332
- end
333
- end
13
+ <br>
334
14
 
335
- class Greet < Hyperloop::Router::Component
336
- render(DIV) do
337
- H1 { "Hello #{match.params[:foo]}!" }
338
- Route(match.url, exact: true) do
339
- H2 { 'What would you like to do?' }
340
- end
341
- Route("#{match.url}/:activity", mounts: Activity)
342
- end
343
- end
15
+ <a href="http://ruby-hyperloop.org/" alt="Hyperloop" title="Hyperloop">
16
+ <img src="http://ruby-hyperloop.org/images/githubhyperloopbadge.png">
17
+ </a>
344
18
 
345
- class Activity < Hyperloop::Router::Component
346
- render(DIV) do
347
- H2 { params.match.params[:activity] }
348
- end
349
- end
350
- ```
19
+ <a href="https://gitter.im/ruby-hyperloop/chat" alt="Gitter chat" title="Gitter chat">
20
+ <img src="http://ruby-hyperloop.org/images/githubgitterbadge.png">
21
+ </a>
351
22
 
352
- Routes will **always** render alongside sibling routes that match as well.
23
+ [![Codeship Status for ruby-hyperloop/hyper-store](https://app.codeship.com/projects/4454c560-d4ea-0134-7c96-362b4886dd22/status?branch=master)](https://app.codeship.com/projects/202301)
24
+ [![Gem Version](https://badge.fury.io/rb/hyper-router.svg)](https://badge.fury.io/rb/hyper-router)
353
25
 
354
- ```ruby
355
- class MyRouter < Hyperloop::Router
356
- ...
26
+ <p align="center">
27
+ <img src="http://ruby-hyperloop.org/images/HyperRouter.png" width="100" alt="Hyper-router">
28
+ </p>
357
29
 
358
- route do
359
- DIV do
360
- Route('/goodbye', mounts: Goodbye)
361
- Route('/:name', mounts: Greet)
362
- end
363
- end
364
- end
365
- ```
30
+ </div>
366
31
 
367
- ### Switch
32
+ ## Hyper-Router GEM is part of Hyperloop GEMS family
368
33
 
369
- Going to `/goodbye` would match `/:name` as well and render `Greet` with the `name` param with the value 'goodbye'.
370
- To avoid this behavior and only render one matching route at a time, use a `Switch` component.
34
+ Build interactive Web applications quickly. Hyperloop encourages rapid development with clean, pragmatic design. With developer productivity as our highest goal, Hyperloop takes care of much of the hassle of Web development, so you can focus on innovation and delivering end-user value.
371
35
 
372
- ```ruby
373
- class MyRouter < Hyperloop::Router
374
- ...
36
+ One language. One model. One set of tests. The same business logic and domain models running on the clients and the server. Hyperloop is fully integrated with Rails and also gives you unfettered access to the complete universe of JavaScript libraries (including React) from within your Ruby code. Hyperloop lets you build beautiful interactive user interfaces in Ruby.
375
37
 
376
- route do
377
- DIV do
378
- Switch do
379
- Route('/goodbye', mounts: Goodbye)
380
- Route('/:name', mounts: Greet)
381
- end
382
- end
383
- end
384
- end
385
- ```
38
+ Everything has a place in our architecture. Components deliver interactive user experiences, Operations encapsulate business logic, Models magically synchronize data between clients and servers, Policies govern authorization and Stores hold local state.
386
39
 
387
- Now, going to `/goodbye` would match the `Goodbye` route first and only render that component.
40
+ **Hyper-router** allows you write and use the React Router in Ruby through Opal.
388
41
 
389
- ### Links
390
42
 
391
- Links are available to Routers, classes that inherit from `HyperLoop::Router::Component`,
392
- or by including `Hyperloop::Router::Mixin`.
43
+ ## Getting Started
393
44
 
394
- The `Link` method takes a url path, and these options:
395
- - `search: String` adds the specified string to the search query
396
- - `hash: String` adds the specified string to the hash location
397
- It can also take a block of children to render inside it.
45
+ 1. Update your Gemfile:
46
+
398
47
  ```ruby
399
- class MyRouter < Hyperloop::Router
400
- ...
48
+ #Gemfile
401
49
 
402
- route do
403
- DIV do
404
- Link('/Gregor Clegane')
405
-
406
- Route('/', exact: true) { H1() }
407
- Route('/:name') do |match|
408
- H1 { "Will #{match.params[:name]} eat all the chickens?" }
409
- end
410
- end
411
- end
412
- end
50
+ gem 'hyperloop'
413
51
  ```
414
52
 
415
- ### NavLinks
53
+ 2. At the command prompt, update your bundle :
416
54
 
417
- NavLinks are the same as Links, but will add styling attributes when it matches the current url
418
- - `active_class: String` adds the class to the link when the url matches
419
- - `active_style: String` adds the style to the link when the url matches
420
- - `active: Proc` A proc that will add extra logic to determine if the link is active
421
- ```ruby
422
- class MyRouter < Hyperloop::Router
423
- ...
55
+ $ bundle update
424
56
 
425
- route do
426
- DIV do
427
- NavLink('/Gregor Clegane', active_class: 'active-link')
428
- NavLink('/Rodrik Cassel', active_style: { color: 'grey' })
429
- NavLink('/Oberyn Martell',
430
- active: ->(match, location) {
431
- match && match.params[:name] && match.params[:name] =~ /Martell/
432
- })
57
+ 3. Run the hyperloop install generator:
433
58
 
434
- Route('/', exact: true) { H1() }
435
- Route('/:name') do |match|
436
- H1 { "Will #{match.params[:name]} eat all the chickens?" }
437
- end
438
- end
439
- end
440
- end
441
- ```
59
+ $ rails g hyperloop:install
442
60
 
443
- ### Pre-rendering
61
+ 4. Follow the guidelines to start developing your application. You may find
62
+ the following resources handy:
63
+ * [Getting Started with Hyperloop](http://ruby-hyperloop.org/start/components/)
64
+ * [Hyperloop Guides](http://ruby-hyperloop.org/docs/architecture)
65
+ * [Hyperloop Tutorial](http://ruby-hyperloop.org/tutorials)
444
66
 
445
- Pre-rendering is automatically taken care for you unde the hood, no more need to pass in the url.
67
+ ## Community
446
68
 
69
+ #### Getting Help
70
+ Please **do not post** usage questions to GitHub Issues. For these types of questions use our [Gitter chatroom](https://gitter.im/ruby-hyperloop/chat) or [StackOverflow](http://stackoverflow.com/questions/tagged/hyperloop).
447
71
 
448
- ## Development
72
+ #### Submitting Bugs and Enhancements
73
+ [GitHub Issues](https://github.com/ruby-hyperloop/hyperloop/issues) is for suggesting enhancements and reporting bugs. Before submiting a bug make sure you do the following:
74
+ * Check out our [contributing guide](https://github.com/ruby-hyperloop/hyperloop/blob/master/CONTRIBUTING.md) for info on our release cycle.
449
75
 
450
- `bundle exec rake` runs test suite
76
+ ## License
451
77
 
452
- ## Contributing
78
+ Hyperloop is released under the [MIT License](http://www.opensource.org/licenses/MIT).
453
79
 
454
- 1. Fork it ( https://github.com/ruby-hyperloop/reactrb-router/tree/hyper-router/fork )
455
- 2. Create your feature branch (`git checkout -b my-new-feature`)
456
- 3. Commit your changes (`git commit -am 'Add some feature'`)
457
- 4. Push to the branch (`git push origin my-new-feature`)
458
- 5. Create a new Pull Request