Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 469f7b3

Browse files
Merge pull request #18 from elthariel/fix/component_template_indent_and_typo
Fix typo and base indentation
2 parents 31932e2 + db72bf2 commit 469f7b3

File tree

4 files changed

+72
-72
lines changed

4 files changed

+72
-72
lines changed

lib/generators/hyper/component_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def create_component_file
99
component_array = component.split('::')
1010
@modules = component_array[0..-2]
1111
@file_name = component_array.last
12-
@indet = 1
12+
@indent = 0
1313
template 'component_template.rb',
1414
File.join('app/hyperloop/components',
1515
@modules.map(&:downcase).join('/'),

lib/generators/hyper/router_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# component_array = component.split('::')
99
# @modules = component_array[0..-2]
1010
# @file_name = component_array.last
11-
# @indet = 1
11+
# @indent = 0
1212
# template 'router_template.rb',
1313
# File.join('app/views/components',
1414
# @modules.map(&:downcase).join('/'),
Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
<%- @modules.each do |module_name| %><%= " "* @indet %>module <%= module_name.camelize %><%- @indet += 1 %>
2-
<%- end %><%=" "* @indet %>class <%= @file_name %> < Hyperloop::Component
1+
<%- @modules.each do |module_name| %><%= " "* @indent %>module <%= module_name.camelize %><%- @indent += 1 %>
2+
<%- end %><%=" "* @indent %>class <%= @file_name %> < Hyperloop::Component
33
4-
<%=" "* @indet %># param :my_param
5-
<%=" "* @indet %># param param_with_default: "default value"
6-
<%=" "* @indet %># param :param_with_default2, default: "default value" # alternative syntax
7-
<%=" "* @indet %># param :param_with_type, type: Hash
8-
<%=" "* @indet %># param :array_of_hashes, type: [Hash]
9-
<%=" "* @indet %># collect_other_params_as :attributes # collects all other params into a hash
4+
<%=" "* @indent %># param :my_param
5+
<%=" "* @indent %># param param_with_default: "default value"
6+
<%=" "* @indent %># param :param_with_default2, default: "default value" # alternative syntax
7+
<%=" "* @indent %># param :param_with_type, type: Hash
8+
<%=" "* @indent %># param :array_of_hashes, type: [Hash]
9+
<%=" "* @indent %># collect_other_params_as :attributes # collects all other params into a hash
1010
11-
<%=" "* @indet %># The following are the most common lifecycle call backs,
12-
<%=" "* @indet %># the following are the most common lifecycle call backs# delete any that you are not using.
13-
<%=" "* @indet %># call backs may also reference an instance method i.e. before_mount :my_method
11+
<%=" "* @indent %># The following are the most common lifecycle call backs,
12+
<%=" "* @indent %># the following are the most common lifecycle call backs# delete any that you are not using.
13+
<%=" "* @indent %># call backs may also reference an instance method i.e. before_mount :my_method
1414
15-
<%=" "* @indet %>before_mount do
16-
<%=" "* @indet %> # any initialization particularly of state variables goes here.
17-
<%=" "* @indet %> # this will execute on server (prerendering) and client.
18-
<%=" "* @indet %>end
15+
<%=" "* @indent %>before_mount do
16+
<%=" "* @indent %> # any initialization particularly of state variables goes here.
17+
<%=" "* @indent %> # this will execute on server (prerendering) and client.
18+
<%=" "* @indent %>end
1919
20-
<%=" "* @indet %>after_mount do
21-
<%=" "* @indet %> # any client only post rendering initialization goes here.
22-
<%=" "* @indet %> # i.e. start timers, HTTP requests, and low level jquery operations etc.
23-
<%=" "* @indet %>end
20+
<%=" "* @indent %>after_mount do
21+
<%=" "* @indent %> # any client only post rendering initialization goes here.
22+
<%=" "* @indent %> # i.e. start timers, HTTP requests, and low level jquery operations etc.
23+
<%=" "* @indent %>end
2424
25-
<%=" "* @indet %>before_update do
26-
<%=" "* @indet %> # called whenever a component will be re-rerendered
27-
<%=" "* @indet %>end
25+
<%=" "* @indent %>before_update do
26+
<%=" "* @indent %> # called whenever a component will be re-rerendered
27+
<%=" "* @indent %>end
2828

29-
<%=" "* @indet %>before_unmount do
30-
<%=" "* @indet %> # cleanup any thing (i.e. timers) before component is destroyed
31-
<%=" "* @indet %>end
29+
<%=" "* @indent %>before_unmount do
30+
<%=" "* @indent %> # cleanup any thing (i.e. timers) before component is destroyed
31+
<%=" "* @indent %>end
3232

33-
<%=" "* @indet %>def render
34-
<%=" "* @indet %> DIV do
35-
<%=" "* @indet %> "<%= (@modules+[@file_name]).join('::') %>"
36-
<%=" "* @indet %> end
37-
<%=" "* @indet %>end
38-
<%=" "* @indet %>end
39-
<%- @modules.each do %><%- @indet -= 1 %><%=" "* @indet %>end
33+
<%=" "* @indent %>def render
34+
<%=" "* @indent %> DIV do
35+
<%=" "* @indent %> "<%= (@modules+[@file_name]).join('::') %>"
36+
<%=" "* @indent %> end
37+
<%=" "* @indent %>end
38+
<%=" "* @indent %>end
39+
<%- @modules.each do %><%- @indent -= 1 %><%=" "* @indent %>end
4040
<%- end %>
Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
module Components
2-
<%- @modules.each do |module_name| %><%= " "* @indet %>module <%= module_name.camelize %><%- @indet += 1 %>
3-
<%- end %><%=" "* @indet %>class <%= @file_name %>
2+
<%- @modules.each do |module_name| %><%= " "* @indent %>module <%= module_name.camelize %><%- @indent += 1 %>
3+
<%- end %><%=" "* @indent %>class <%= @file_name %>
44
5-
<%=" "* @indet %>include React::Router
5+
<%=" "* @indent %>include React::Router
66
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
7+
<%=" "* @indent %>routes(path: "/") do # change path to be the base path
8+
<%=" "* @indent %> # you will probably want to update your config/routes.rb file so that it matches all
9+
<%=" "* @indent %> # subroutes: i.e. get '(*subroutes)' => "<%= (@modules.last || 'home').underscore %>#<%= @file_name.underscore %>"
10+
<%=" "* @indent %> # basic route has:
11+
<%=" "* @indent %> # a path
12+
<%=" "* @indent %> # a name - used to reference the route in methods like redirect, and link)
13+
<%=" "* @indent %> # a handler - the component that will be mounted on this route
14+
<%=" "* @indent %> route(path: "subroute1-path", name: :subroute1, handler: Subroute1Component)
15+
<%=" "* @indent %> route(path: "subroute2-path", name: :subroute2, handler: Subroute2Component)
16+
<%=" "* @indent %> # routes can take parameters designated with a colon:
17+
<%=" "* @indent %> route(path: "subroute3-path/:user_id", name: subroute3, handler: Subroute3Component)
18+
<%=" "* @indent %> # the redirect method will transition any incoming matching routes to a new route
19+
<%=" "* @indent %> redirect(from: "/", to: :subroute1)
20+
<%=" "* @indent %> # the not_found method indicates which component to load if no route matches:
21+
<%=" "* @indent %> not_found(handler: NotFound)
22+
<%=" "* @indent %>end
2323

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
24+
<%=" "* @indent %>router_param :user_id, as: :user do |id|
25+
<%=" "* @indent %> # Translate incoming route params to internal values.
26+
<%=" "* @indent %> # In this case we will refer to the translated user_id as user.
27+
<%=" "* @indent %> # The block param (id) will have the value of the param.
28+
<%=" "* @indent %> # This is useful for looking up ActiveRecord models by ids, etc.
29+
<%=" "* @indent %>end
3030

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
31+
<%=" "* @indent %>def show # note that the top level router has a show method NOT render
32+
<%=" "* @indent %> DIV do
33+
<%=" "* @indent %> # content to display on every route
34+
<%=" "* @indent %> # link generates an anchor tag.
35+
<%=" "* @indent %> link(to: :subroute3, params: {user_id: 12}, class: "link-class") { "Click to go to subroute3" }
36+
<%=" "* @indent %> # within an event handler use transition_to to move to a new route
37+
<%=" "* @indent %> # the route_handler method will display the current route, it can be called in the
38+
<%=" "* @indent %> # router, or in some child component.
39+
<%=" "* @indent %> route_handler
40+
<%=" "* @indent %> end
41+
<%=" "* @indent %>end
42+
<%=" "* @indent %>end
43+
<%- @modules.each do %><%- @indent -= 1 %><%=" "* @indent %>end
4444
<%- end %>end

0 commit comments

Comments
 (0)