Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shotengai
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
shotengai
Commits
502e1edc
Commit
502e1edc
authored
Aug 24, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add generator for controller
parent
746ebe7b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
0 deletions
+69
-0
controllers_generator.rb
lib/generators/shotengai/controllers_generator.rb
+41
-0
products_controller.rb
...ors/templates/controllers/customer/products_controller.rb
+28
-0
No files found.
lib/generators/shotengai/controllers_generator.rb
0 → 100644
View file @
502e1edc
require
'rails/generators/base'
module
Shotengai
module
Generators
class
ControllersGenerator
<
Rails
::
Generators
::
Base
CONTROLLERS
=
%w(products )
.
freeze
desc
<<-
DESC
.
strip_heredoc
Create inherited Devise controllers in your app/controllers folder.
Use -n to add the namespec folder, default nil.
For example:
rails generate devise:controllers merchant -n=store
This will create serveral controller classes inherited from merchant product and order class
For example:
app/controllers/store/product_controller.rb like this:
class Store::ProductsController < Shotengai::MerchantProductsController
content...
end
DESC
source_root
File
.
expand_path
(
"../../templates/controllers/"
,
__FILE__
)
argument
:role
,
required:
true
,
desc:
"The role to create controllers in merchant or customer"
class_option
:namespace
,
aliases:
"-n"
,
type: :string
,
desc:
"Add namespace to controller"
def
create_controllers
raise
'Illegal role. Only merchant or customer'
unless
role
.
in?
([
'merchant'
,
'customer'
])
@namespace
=
options
[
:namespace
].
blank?
?
''
:
(
options
[
:namespace
].
camelize
+
'::'
)
CONTROLLERS
.
each
do
|
name
|
template
"
#{
role
}
/
#{
name
}
_controller.rb"
,
"app/controllers/
#{
options
[
:namespace
]
}
/
#{
name
}
_controller.rb"
end
end
end
end
end
lib/generators/templates/controllers/customer/products_controller.rb
0 → 100644
View file @
502e1edc
class
<
%= @namespace %>ProductController < Shotengai:Customer::ProductsController
# GET /resource/confirmation/new
# def new
# super
# end
# POST /resource/confirmation
# def create
# super
# end
# GET /resource/confirmation?confirmation_token=
abcdef
# def show
# super
# end
# protected
# The path used after resending confirmation instructions.
# def after_resending_confirmation_instructions_path_for(resource_name)
# super(resource_name)
# end
# The path used after confirmation.
# def after_confirmation_path_for(resource_name, resource)
# super(resource_name, resource)
# end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment