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
acd094ef
Commit
acd094ef
authored
Aug 30, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add generator for routes in controller generator
parent
04acffc3
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
10 deletions
+60
-10
README.md
README.md
+3
-2
controllers_generator.rb
lib/generators/shotengai/controllers_generator.rb
+57
-1
shotengai.rb
lib/shotengai.rb
+0
-1
engine.rb
lib/shotengai/engine.rb
+0
-6
No files found.
README.md
View file @
acd094ef
...
...
@@ -38,7 +38,7 @@ For example:
create app/models/my_order.rb
create app/models/my_catalog.rb
#Controller Generator:
#Controller
& Routes
Generator:
```
ruby
# attr:
# role ( merchant | customer )
...
...
@@ -51,7 +51,8 @@ For example:
```
shell
$
rails g shotengai:controllers merchant
-n
my_merchant
--product
MyProduct
--order
MyOrder
```
This will create serveral controller classes inherited from merchant product and order class
This will create serveral controller classes inherited from merchant product and order class,
and add routes to your config/routes.rb.
For example:
app/controllers/store/product_controller.rb like this:
...
...
lib/generators/shotengai/controllers_generator.rb
View file @
acd094ef
...
...
@@ -5,6 +5,7 @@ module Shotengai
class
ControllersGenerator
<
Rails
::
Generators
::
Base
desc
<<-
DESC
.
strip_heredoc
Create inherited Shotengai controllers in your app/controllers folder.
And add routes to your config/routes.rb.
Use -n to add the namespec folder, default nil.
Use --produt to custom your own product class
...
...
@@ -14,7 +15,9 @@ module Shotengai
rails generate shotengai:controllers merchant -n my_merchant --product MyProduct --order MyOrder
This will create serveral controller classes inherited from merchant product and order class
This will create serveral controller classes inherited from merchant product and order class,
and add all routes about merchant.
For example:
app/controllers/store/product_controller.rb like this:
...
...
@@ -50,6 +53,59 @@ module Shotengai
template
"template_controller.rb"
,
"app/controllers/
#{
@namespace
}
/
#{
@klass_name
.
underscore
.
pluralize
}
_controller.rb"
end
create_routes
end
def
create_routes
route
(
@role
==
'merchant'
?
merchant_routes
:
customer_routes
)
end
def
merchant_routes
product
,
order
=
@product
.
underscore
,
@order
.
underscore
"
namespace :
#{
@namespace
.
to_sym
}
do
resources :
#{
product
.
pluralize
}
do
member do
post :put_on_shelf
post :sold_out
end
resources :
#{
product
}
_series
end
resources :
#{
order
.
pluralize
}
, only: [:index, :show, :update] do
member do
post :send_out
end
resources :
#{
product
}
_snapshots, only: [:index, :show, :update]
end
resources :
#{
product
}
_series do #, excpet: :index
resources :
#{
product
}
_snapshots, only: [:index, :show, :update]
end
end
"
end
def
customer_routes
product
,
order
=
@product
.
underscore
,
@order
.
underscore
"
namespace :
#{
@namespace
.
to_sym
}
do
resources :
#{
product
.
pluralize
}
, only: [:index, :show] do
resources :
#{
product
}
_series, only: [:index, :show]
end
resources :
#{
product
}
_snapshots, only: [:index, :show]
resources :
#{
order
.
pluralize
}
do
member do
post :pay
post :cancel
post :get_it
end
collection do
get :cart
post :create_directly
post :add_to_cart
end
resources :
#{
product
}
_snapshots, only: [:index, :create]
end
end"
end
end
end
...
...
lib/shotengai.rb
View file @
acd094ef
...
...
@@ -12,7 +12,6 @@ module Shotengai
autoload
:Catalog
,
'shotengai/catalog'
autoload
:AASM_DLC
,
'shotengai/aasm_dlc'
autoload
:WebError
,
'shotengai/web_error'
autoload
:Engine
,
'shotengai/engine'
module
Controller
autoload
:Base
,
'shotengai/controllers/base'
...
...
lib/shotengai/engine.rb
deleted
100644 → 0
View file @
04acffc3
module
Shotengai
require
'rails/engine'
class
Engine
<
::
Rails
::
Engine
end
end
\ No newline at end of file
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