reactive_rails_generator 0.1.4 → 0.1.5

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: dd400b8d05f2940350b712ef6d59e33c3fb454a9
4
- data.tar.gz: 6846868648782263335a299501f55ab2d4acfd8f
3
+ metadata.gz: eb7a49b852c9ae54932e33c50bad1c656e7a48d8
4
+ data.tar.gz: e3a63831077b57f88bdd6d76073f3f63520d3b94
5
5
  SHA512:
6
- metadata.gz: dce3d4e680b0878f56a7ded3b35746730e291c018ed424d31ae93fc99b4e685bb0c69c6624824988859520ccc18e8222d6cd6e59847c860c4eb76d8e17f5b0af
7
- data.tar.gz: e9c20199e2aa797378ee630c988085ee90b28076fbc82680e1867ddf800fcc972e01319336ab8ac35ba5742d453efe8929648d7fe5fdf0508faa9dd6a211c137
6
+ metadata.gz: 27043fb182f71f7c1422f4e1dff86be27722eaeb4bcc1e47a697beba8278f1a8e2b46d1a612d5ee93b0069589abbe238edb3d582f4f97d760e5d13750b75a844
7
+ data.tar.gz: 0d6ca20a140ce8fded5d60648782e4e77509b7678f6ae6f3ba86a53a4e065f577706eff94953fd9c4e4b60220eb8ae6dad624ef2e4c6aa3365110e2abe62f05f
@@ -0,0 +1,16 @@
1
+ require "rails/generators"
2
+ module Reactrb
3
+ class Router < Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
5
+ argument :components, :type => :array
6
+ def create_component_file()
7
+ self.components.each do |component|
8
+ component_array = component.split("::")
9
+ @modules = component_array[0..-2]
10
+ @file_name = component_array.last
11
+ @indet = 1
12
+ template "router_template.rb", File.join('app/react/components', @modules.map(&:downcase).join("/"), "#{@file_name.underscore}.rb")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,44 @@
1
+ module Components
2
+ <%- @modules.each do |module_name| %><%= " "* @indet %>module <%= module_name.camelize %><%- @indet += 1 %>
3
+ <%- end %><%=" "* @indet %>class <%= @file_name %>
4
+
5
+ <%=" "* @indet %>include React::Router
6
+
7
+ <%=" "* @indet %>routes(path: "/") do # change path to be the base path
8
+ <%=" "* @indet %> # you will probably want to update your config/routes.rb file so that it matches all
9
+ <%=" "* @indet %> # subroutes: i.e. get '(*subroutes)' => "<%= (@modules.last || 'home').underscore %>#<%= @file_name.underscore %>"
10
+ <%=" "* @indet %> # basic route has:
11
+ <%=" "* @indet %> # a path
12
+ <%=" "* @indet %> # a name - used to reference the route in methods like redirect, and link)
13
+ <%=" "* @indet %> # a handler - the component that will be mounted on this route
14
+ <%=" "* @indet %> route(path: "subroute1-path", name: :subroute1, handler: Subroute1Component)
15
+ <%=" "* @indet %> route(path: "subroute2-path", name: :subroute2, handler: Subroute2Component)
16
+ <%=" "* @indet %> # routes can take parameters designated with a colon:
17
+ <%=" "* @indet %> route(path: "subroute3-path/:user_id", name: subroute3, handler: Subroute3Component)
18
+ <%=" "* @indet %> # the redirect method will transition any incoming matching routes to a new route
19
+ <%=" "* @indet %> redirect(from: "/", to: :subroute1)
20
+ <%=" "* @indet %> # the not_found method indicates which component to load if no route matches:
21
+ <%=" "* @indet %> not_found(handler: NotFound)
22
+ <%=" "* @indet %>end
23
+
24
+ <%=" "* @indet %>router_param :user_id, as: :user do |id|
25
+ <%=" "* @indet %> # Translate incoming route params to internal values.
26
+ <%=" "* @indet %> # In this case we will refer to the translated user_id as user.
27
+ <%=" "* @indet %> # The block param (id) will have the value of the param.
28
+ <%=" "* @indet %> # This is useful for looking up ActiveRecord models by ids, etc.
29
+ <%=" "* @indet %>end
30
+
31
+ <%=" "* @indet %>def show # note that the top level router has a show method NOT render
32
+ <%=" "* @indet %> div do
33
+ <%=" "* @indet %> # content to display on every route
34
+ <%=" "* @indet %> # link generates an anchor tag.
35
+ <%=" "* @indet %> link(to: :subroute3, params: {user_id: 12}, class: "link-class") { "Click to go to subroute3" }
36
+ <%=" "* @indet %> # within an event handler use transition_to to move to a new route
37
+ <%=" "* @indet %> # the route_handler method will display the current route, it can be called in the
38
+ <%=" "* @indet %> # router, or in some child component.
39
+ <%=" "* @indet %> route_handler
40
+ <%=" "* @indet %> end
41
+ <%=" "* @indet %>end
42
+ <%=" "* @indet %>end
43
+ <%- @modules.each do %><%- @indet -= 1 %><%=" "* @indet %>end
44
+ <%- end %>end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactive_rails_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loic Boutet
@@ -32,9 +32,11 @@ extra_rdoc_files: []
32
32
  files:
33
33
  - lib/generators/reactrb/component_generator.rb
34
34
  - lib/generators/reactrb/install_generator.rb
35
+ - lib/generators/reactrb/router_generator.rb
35
36
  - lib/generators/reactrb/templates/component_template.rb
37
+ - lib/generators/reactrb/templates/router_template.rb
36
38
  - lib/reactive_rails_generator.rb
37
- homepage: http://rubygems.org/gems/hola
39
+ homepage: https://github.com/loicboutet/reactive-rails-generator
38
40
  licenses:
39
41
  - MIT
40
42
  metadata: {}