Skip to content

Commit 83089cd

Browse files
implement all of jonas' feedback so far
1 parent 2e8da21 commit 83089cd

File tree

8 files changed

+77
-45
lines changed

8 files changed

+77
-45
lines changed

lib/generators/matestack_app/USAGE

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
Description:
2-
This generator scaffolds a matestack app for your Rails application!
3-
Mandatory input: NAME
4-
Optional input to add an app controller: controller
2+
Stubs out a new matestack app. Pass the app name under_scored.
53

6-
Examples:
7-
rails generate matestack_app example_app (--controller)
4+
If you want so, pass the option '--all_inclusive' to also create
5+
a corresponding matestack example_page, a controller, its action
6+
and the route in 'config/routes.rb'.
7+
8+
Example 1:
9+
`rails generate matestack_app example_app`
10+
11+
This will create:
12+
app/matestack/apps/example_app.rb
13+
14+
Example 2:
15+
`rails generate matestack_app example_app --all_inclusive`
816

917
This will create:
1018
app/matestack/apps/example_app.rb
11-
(app/controllers/example_app_controller.rb)
19+
app/matestack/pages/example_app/example_page.rb
20+
app/controllers/example_app_controller.rb
21+
route get 'example_app/example_page', to: 'example_app#example_page'
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
class MatestackAppGenerator < Rails::Generators::NamedBase
22
source_root File.expand_path('templates', __dir__)
33

4-
class_option :controller, type: :boolean, default: false
4+
class_option :all_inclusive, type: :boolean, default: false
55

66
def create_matestack_app
77

88
generator_path = "app/matestack/apps/#{file_name}.rb"
99

1010
template 'matestack_app.erb', generator_path
1111

12-
create_matestack_app_controller if options[:controller] == true
12+
if options[:all_inclusive] == true
13+
controller_path = "app/controllers/#{file_name}_controller.rb"
14+
template 'matestack_app_controller.erb', controller_path
1315

14-
end
16+
route %{get '#{file_name}/example_page', to: '#{file_name}\#example_page'}
17+
18+
generate "matestack_page example_page --app_name #{file_name} --called_by_app_generator=true"
19+
20+
puts "You can visit your new matestack apps' example page under http://localhost:3000/#{file_name}/example_page"
21+
22+
end
1523

16-
def create_matestack_app_controller
17-
controller_path = "app/controllers/#{file_name}_controller.rb"
18-
template 'matestack_app_controller.erb', controller_path
1924
end
2025

2126
end

lib/generators/matestack_app/templates/matestack_app.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ end
1414

1515
# OPTIONAL: Use partials to render stuff like layout components
1616
# def partial_one
17-
# components {
17+
# partial {
1818
# # your components go here
1919
# }
2020
# end

lib/generators/matestack_app/templates/matestack_app_controller.erb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
class <%= class_name %>Controller < ApplicationController
22

3-
# This is what the controller action for an ExamplePage for
4-
# your <%= class_name %> matestack app looks like
5-
def show
3+
def example_page
64
responder_for(Pages::<%= class_name %>::ExamplePage)
75
end
86

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
Description:
2-
Generates matestack components to app/matestack/components
2+
Stubs out a new matestack component. Pass the component name, under_scored.
33

4-
Example:
5-
rails generate matestack_component NAME --(no-)dynamic --(no-)haml --(no-)scss
4+
To create a dynamic component, specify it using the --dynamic option.
5+
6+
To place this component within a namespace, specify the namespace name under_scored and it
7+
will get generated into 'app/matestack/components/namespace/*'.
8+
9+
Example 1:
10+
`rails generate matestack_component NAME`
611

712
This will create:
813
app/matestack/components/NAME.rb
9-
(app/matestack/components/NAME.js if --dynamic)
10-
(app/matestack/components/NAME.haml if --haml)
11-
(app/matestack/components/NAME.scss if --scss)
14+
15+
Example 2:
16+
`rails generate matestack_component NAME --dynamic --namespace sample_namespace`
17+
18+
This will create:
19+
app/matestack/components/sample_namespace/NAME.rb
20+
app/matestack/components/sample_namespace/NAME.js

lib/generators/matestack_page/USAGE

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
Description:
2-
This generator scaffolds a matestack page for your Rails application!
3-
Mandatory input: NAME and APP_NAME
4-
Optional input to specify routing: controller_action
2+
Stubs out a new matestack page and its route. Pass the page name and --app-name, both under_scored.
3+
4+
To place the page within a namespace, specify the namespace name under_scored and it
5+
will get generated into 'app/matestack/pages/namespace/*'.
6+
7+
To create a custom controller#action to use in the created route, specify it as
8+
under_scored_controller#under_scored_action
9+
10+
This generates a matestack page class in app/matestack/pages/ and adds a route to config/routes.rb
511

612
Example 1:
7-
rails generate matestack_page example_page example_app
13+
`rails generate matestack_page example_page --app_name example_app`
814

915
This will create:
1016
app/matestack/pages/example_app/example_page.rb
@@ -13,7 +19,7 @@ Example 1:
1319
get 'example_app/example_page', to: 'example_app#example_page'
1420

1521
Example 2:
16-
rails generate matestack_page example_page example_app --controller_action=static#second
22+
`rails generate matestack_page example_page --app_name example_app --controller_action=static#second`
1723

1824
This will create:
1925
app/matestack/pages/example_app/example_page.rb
Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
class MatestackPageGenerator < Rails::Generators::NamedBase
22
source_root File.expand_path('templates', __dir__)
33

4-
argument :app_name, type: :string, required: true
5-
4+
class_option :app_name, type: :string, required: true
5+
class_option :namespace, type: :string
66
class_option :controller_action, type: :string
7+
class_option :called_by_app_generator, type: :boolean, default: false
78

89
def create_matestack_page
9-
@app_name = app_name
10+
@app_name = options[:app_name]
11+
@namespace = options[:namespace]
1012

1113
if options[:controller_action].nil?
1214
@controller_action = "#{@app_name}\##{file_name}"
1315
else
1416
@controller_action = options[:controller_action]
1517
end
1618

17-
matestack_page_dir_path = "app/matestack/pages/#{@app_name}"
19+
matestack_page_dir_path = "app/matestack/pages"
20+
matestack_page_dir_path << "/#{@app_name}" unless @app_name.nil?
21+
matestack_page_dir_path << "/#{@namespace}" unless @namespace.nil?
1822

1923
generator_path = matestack_page_dir_path + "/#{file_name}.rb"
2024

2125
template "matestack_page.erb", generator_path
2226

23-
route %{get '#{@app_name}/#{file_name}', to: '#{@controller_action}'}
24-
25-
puts "Make sure to add responder_for(Pages::#{@app_name.camelize}::#{file_name.camelize}) to #{@controller_action}"
27+
unless options[:called_by_app_generator]
28+
route %{get '#{@app_name}/#{@namespace}/#{file_name}', to: '#{@controller_action}'} unless @namespace.nil?
29+
route %{get '#{@app_name}/#{file_name}', to: '#{@controller_action}'} if @namespace.nil?
30+
puts "Page created! Make sure to modify"
31+
puts ""
32+
puts "def controller_action"
33+
puts " responder_for(Pages::#{@app_name.camelize}::#{@namespace.camelize}::#{file_name.camelize})" unless @namespace.nil?
34+
puts " responder_for(Pages::#{@app_name.camelize}::#{file_name.camelize})" if @namespace.nil?
35+
puts "end"
36+
puts ""
37+
puts "and add it to the desired controller!"
38+
end
2639

27-
# todo
28-
# swap app and page input order
29-
# - scaffold failing rspec test cases per default via options[:rspec]
30-
# - check if spec/ folder exists in host system => if not, puts 'rspec test suite not found'
31-
# - how-to https://relishapp.com/rspec/rspec-rails/docs/generators
32-
# talk to jonas: do pages always belong to apps?
33-
# - if yes: generate corresponding app if it does not exist
34-
# - if yes: invoce `generate matestack_app` with ARGS => should create controller_action and view aswell
35-
# generate "scaffold", "forums title:string description:text"
3640
end
3741
end

lib/generators/matestack_page/templates/matestack_page.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Pages::<% if @app_name.present? %><%= @app_name.camelize %>::<% end %><%= class_name %> < Matestack::Ui::Page
1+
class Pages::<% unless @namespace.nil? %><%= @namespace.camelize %>::<% end %><% unless @app_name.nil? %><%= @app_name.camelize %>::<% end %><%= class_name %> < Matestack::Ui::Page
22

33
# OPTIONAL: Prepare data for the response method
44
# def prepare
@@ -14,7 +14,7 @@ end
1414

1515
# OPTIONAL: Partials come after the response
1616
# def partial_one
17-
# components {
17+
# partial {
1818
# # your components go here
1919
# }
2020
# end

0 commit comments

Comments
 (0)