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
a8975486
Commit
a8975486
authored
Aug 25, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tempalte_controller
parent
1db78141
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
23 additions
and
176 deletions
+23
-176
controllers_generator.rb
lib/generators/shotengai/controllers_generator.rb
+9
-4
orders_controller.rb
...ators/templates/controllers/customer/orders_controller.rb
+0
-4
product_series_controller.rb
...mplates/controllers/customer/product_series_controller.rb
+0
-4
products_controller.rb
...ors/templates/controllers/customer/products_controller.rb
+0
-3
orders_controller.rb
...ators/templates/controllers/merchant/orders_controller.rb
+0
-4
product_series_controller.rb
...mplates/controllers/merchant/product_series_controller.rb
+0
-4
products_controller.rb
...ors/templates/controllers/merchant/products_controller.rb
+0
-4
template_controller.rb
lib/generators/templates/controllers/template_controller.rb
+3
-0
controller.rb
lib/shotengai/controller.rb
+11
-3
product.rb
lib/shotengai/controller_helper/product.rb
+0
-78
series.rb
lib/shotengai/controller_helper/series.rb
+0
-68
user_order.rb
lib/shotengai/controller_helper/user_order.rb
+0
-0
No files found.
lib/generators/shotengai/controllers_generator.rb
View file @
a8975486
...
@@ -12,7 +12,7 @@ module Shotengai
...
@@ -12,7 +12,7 @@ module Shotengai
For example:
For example:
rails generate shotengai:controllers merchant -n
store
--product MyProduct --order MyOrder
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
For example:
For example:
...
@@ -40,13 +40,17 @@ module Shotengai
...
@@ -40,13 +40,17 @@ module Shotengai
{
{
'products'
=>
options
[
:product
],
'products'
=>
options
[
:product
],
'orders'
=>
options
[
:order
],
'orders'
=>
options
[
:order
],
'product_series'
=>
"
#{
options
[
:product
]
}
Series"
'product_series'
=>
"
#{
options
[
:product
]
}
Series"
,
}.
each
do
|
key
,
klass_name
|
}.
each
do
|
key
,
klass_name
|
@key
,
@klass_name
=
key
,
klass_nam
e
@key
,
@klass_name
,
@role
=
key
,
klass_name
,
rol
e
template
"
#{
role
}
/
#{
@key
}
_controller.rb"
,
template
"
template
_controller.rb"
,
"app/controllers/
#{
options
[
:namespace
]
}
/
#{
klass_name
.
underscore
.
pluralize
}
_controller.rb"
"app/controllers/
#{
options
[
:namespace
]
}
/
#{
klass_name
.
underscore
.
pluralize
}
_controller.rb"
end
end
end
end
end
end
end
end
end
end
\ No newline at end of file
lib/generators/templates/controllers/customer/orders_controller.rb
deleted
100644 → 0
View file @
1db78141
class
<
%= @controller_prefix%><%=
@klass_name
.
pluralize
%>Controller < Shotengai::Customer::OrdersController
self.resource = '<%= @klass_name %>
'
end
lib/generators/templates/controllers/customer/product_series_controller.rb
deleted
100644 → 0
View file @
1db78141
class
<
%= @controller_prefix%><%=
@klass_name
.
pluralize
%>Controller < Shotengai::Customer::ProductSeriesController
self.resource = '<%= @klass_name %>
'
end
lib/generators/templates/controllers/customer/products_controller.rb
deleted
100644 → 0
View file @
1db78141
class
<
%= @controller_prefix%><%=
@klass_name
.
pluralize
%>Controller < Shotengai::Controller::Customer::ProductsController
self.resource = '<%= @klass_name %>
'
end
lib/generators/templates/controllers/merchant/orders_controller.rb
deleted
100644 → 0
View file @
1db78141
class
<
%= @controller_prefix%><%=
@klass_name
.
pluralize
%>Controller < Shotengai::Merchant::OrdersController
self.resource = '<%= @klass_name %>
'
end
lib/generators/templates/controllers/merchant/product_series_controller.rb
deleted
100644 → 0
View file @
1db78141
class
<
%= @controller_prefix%><%=
@klass_name
.
pluralize
%>Controller < Shotengai::Merchant::ProductSeriesController
self.resource = '<%= @klass_name %>
'
end
lib/generators/templates/controllers/merchant/products_controller.rb
deleted
100644 → 0
View file @
1db78141
class
<
%= @controller_prefix%><%=
@klass_name
.
pluralize
%>Controller < Shotengai::Customer::ProductsController
self.resource = '<%= @klass_name %>
'
end
lib/generators/templates/controllers/template_controller.rb
0 → 100644
View file @
a8975486
class
<
%= @controller_prefix %><%=
@klass_name
.
pluralize
%>Controller < Shotengai::Controller::<%= "#{@role}/#{@key}".camelize %>
Controller
self
.
resources
=
'<%= @klass_name %>'
end
lib/shotengai/controller.rb
View file @
a8975486
module
Shotengai
module
Shotengai
class
Controller
<
ApplicationController
class
Controller
<
ApplicationController
# The resources of this controller
# ActiveRecord::Relation or ActiveRecord::Base
# ActiveRecord::Relation or ActiveRecord::Base
cattr_accessor
:resources
cattr_accessor
:resources
# The view template dir
# respond_with @products, template: "#{self.class.template_dir}/index"
# respond_with @products, template: "#{self.class.template_dir}/index"
cattr_accessor
:template_dir
#{ 'shoutengai/merchant/product_series/' }
cattr_accessor
:template_dir
class
<<
self
class
<<
self
# Add the index query to custom the @@index_resouces on the base of @@resources
# Add the index query to custom the @@index_resouces on the base of @@resources
...
@@ -25,6 +27,7 @@ module Shotengai
...
@@ -25,6 +27,7 @@ module Shotengai
end
end
before_action
:set_resource
,
except:
[
:index
,
:create
]
before_action
:set_resource
,
except:
[
:index
,
:create
]
respond_to
:json
def
index
def
index
page
=
params
[
:page
]
||
1
page
=
params
[
:page
]
||
1
...
@@ -48,7 +51,7 @@ module Shotengai
...
@@ -48,7 +51,7 @@ module Shotengai
end
end
def
destroy
def
destroy
@resourc
.
destroy!
@resourc
e
.
destroy!
head
204
head
204
end
end
...
@@ -61,12 +64,16 @@ module Shotengai
...
@@ -61,12 +64,16 @@ module Shotengai
self
.
class
.
resources
self
.
class
.
resources
end
end
def
resource_key
(
default_resources
.
try
(
:klass
)
||
default_resources
).
model_name
.
singular
.
to_sym
end
def
set_resource
def
set_resource
@resource
=
default_resources
.
find
(
params
[
:id
])
@resource
=
default_resources
.
find
(
params
[
:id
])
end
end
def
resource_params
def
resource_params
params
.
requrie
(
resource_key
)
end
end
end
end
end
end
\ No newline at end of file
lib/shotengai/controller_helper/product.rb
deleted
100644 → 0
View file @
1db78141
module
Shotengai
module
ControllerHelper
module
Product
included
do
cattr_accessor
:resource
{
'Product'
}
# 默认值
# respond_with @products, template: "#{self.template_dir}/index"
cattr_accessor
:template_dir
{
'products/'
}
end
class_methods
do
def
resource
=
resource_name
klass
=
Object
.
const_get
resource_name
raise
ArgumentError
.
new
(
'The resource of Product Controller should be a class inherited from Shotengai::Product'
)
unless
Shotengai
::
Product
===
klass
@@resource
=
klass
end
# def template_dir dir
# self.template_dir = dir
# end
end
before_action
:set_product
,
expect:
[
:index
,
:create
]
respond_to
:json
def
index
@products
=
self
.
resource
.
all
respond_with
@products
,
template:
"
#{
self
.
template_dir
}
/index"
end
def
show
@product
=
self
.
resource
.
find
(
params
[
:id
])
respond_with
@product
,
template:
"
#{
self
.
template_dir
}
/show"
# need series list here
end
def
create
self
.
resource
.
create!
(
product_params
)
head
201
end
def
update
self
.
resource
.
update!
(
product_params
)
head
200
end
resource
.
aasm
.
state_machine
.
events
.
map
(
&
:first
).
each
do
|
event
|
define_method
(
event
)
do
@product
.
send
(
"
#{
event
}
!"
)
head
200
end
end
private
def
set_resource
@product
=
self
.
resource
.
find
(
params
[
:id
])
end
def
product_params
resource_key
=
self
.
resource
.
model_name
.
singular
.
to_sym
# QUESTION: need these ?
spec
=
params
.
require
(
resource_key
).
fetch
(
:spec
,
nil
).
try
(
:permit!
)
datail
=
params
.
require
(
resource_key
).
fetch
(
:datail
,
nil
).
try
(
:permit!
)
meta
=
params
.
require
(
resource_key
).
fetch
(
:meta
,
nil
).
try
(
:permit!
)
params
.
requrie
().
permit
(
:title
,
:default_series_id
,
:need_express
,
:need_time_attr
,
:cover_image
,
banners:
[]
).
merge
(
{
spec:
spec
,
detail:
detail
,
meta:
meta
}
)
end
end
end
end
\ No newline at end of file
lib/shotengai/controller_helper/series.rb
deleted
100644 → 0
View file @
1db78141
module
Shotengai
module
ControllerHelper
module
Product
included
do
# cattr_accessor :resource
end
class_methods
do
def
product_as
resource_name
self
.
cattr_accessor
:resource
self
.
resource
=
Object
.
const_get
resource_name
end
end
before_action
:set_product
,
expect:
[
:index
,
:create
]
respond_to
:json
def
index
@products
=
self
.
resource
.
all
respond_with
@products
end
def
show
@product
=
self
.
resource
.
find
(
params
[
:id
])
respond_with
@product
end
def
create
self
.
resource
.
create!
(
product_params
)
head
201
end
def
update
self
.
resource
.
update!
(
product_params
)
head
200
end
resource
.
aasm
.
state_machine
.
events
.
map
(
&
:first
).
each
do
|
event
|
define_method
(
event
)
do
@product
.
send
(
"
#{
event
}
!"
)
head
200
end
end
private
def
set_resource
@product
=
self
.
resource
.
find
()
end
def
product_params
resource_key
=
self
.
resource
.
model_name
.
singular
.
to_sym
# QUESTION: need these ?
spec
=
params
.
require
(
resource_key
).
fetch
(
:spec
,
nil
).
try
(
:permit!
)
datail
=
params
.
require
(
resource_key
).
fetch
(
:datail
,
nil
).
try
(
:permit!
)
meta
=
params
.
require
(
resource_key
).
fetch
(
:meta
,
nil
).
try
(
:permit!
)
params
.
requrie
().
permit
(
:title
,
:default_series_id
,
:need_express
,
:need_time_attr
,
:cover_image
,
banners:
[]
).
merge
(
{
spec:
spec
,
detail:
detail
,
meta:
meta
}
)
end
end
end
end
\ No newline at end of file
lib/shotengai/controller_helper/user_order.rb
deleted
100644 → 0
View file @
1db78141
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