repres-dosser 1.5 → 1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +43 -0
- data/lib/generators/repres/dosser/platform/USAGE +18 -0
- data/lib/generators/repres/dosser/platform/platform_generator.rb +84 -0
- data/lib/generators/repres/dosser/platform/templates/app/controllers/portals_controller.rb +16 -0
- data/lib/generators/repres/dosser/platform/templates/app/controllers/presentation_controller.rb +17 -0
- data/lib/generators/repres/dosser/platform/templates/config/routes.rb +3 -0
- data/lib/generators/repres/dosser/swagger/USAGE +15 -0
- data/lib/generators/repres/dosser/swagger/swagger_generator.rb +84 -0
- data/lib/generators/repres/dosser/swagger/templates/lib/swagger/api.json +118 -0
- data/lib/repres/dosser/version.rb +1 -1
- metadata +10 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e0b1d905f477b752c5cfcc27c1c0e88963cd14bd
|
|
4
|
+
data.tar.gz: fd1a3124526d4bb596371169e335acef5c07af33
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d500648a0b6e31a235ecf2f6901b4ed1f3382e1cc79a40bff325628b2e833f2ec2fe1aa3b14333c28c368674944aa42c6f6e186e28b96e7e3d0c4c023860a6f8
|
|
7
|
+
data.tar.gz: 9b743cd575964bfda3c6859777abb126f3e9d874505167887223477b586bfc583a7c884e724219f7f8e7a934733ff45f33fd61a60120d3ab023b2ab0156bfd17
|
data/README.md
CHANGED
|
@@ -62,3 +62,46 @@ onIndexResourceSuccess: function(data, textStatus, jqXHR)
|
|
|
62
62
|
console.info('The item index is from '+pagination.min_item_on_current_page+' to '+pagination.max_item_on_current_page+' on the current page.');
|
|
63
63
|
}
|
|
64
64
|
```
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## Generators
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
### Platform generator
|
|
73
|
+
|
|
74
|
+
```shell
|
|
75
|
+
rails generate repres:dosser:platform administration --version 2
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
This will insert the following routings into the config/routes.rb file:
|
|
79
|
+
```ruby
|
|
80
|
+
scope '/administration-api/v2', module: 'administration/dosser/v2', as: 'administration_dosser_v2' do
|
|
81
|
+
resources :portals, only: :show
|
|
82
|
+
end
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
and create the following files:
|
|
86
|
+
```shell
|
|
87
|
+
app/controllers/administration/dosser/v2/presentation_controller.rb
|
|
88
|
+
app/controllers/administration/dosser/v2/portals_controller.rb
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### Swagger generator
|
|
94
|
+
|
|
95
|
+
```shell
|
|
96
|
+
rails generate repres:dosser:swagger administration --version 2
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
This will call the following command:
|
|
100
|
+
```shell
|
|
101
|
+
rails generate repres:dosser:platform administration --version 2
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
before insert the swagger_engine & the latest repres-dosser gem into the Gemfile file and will create the following file:
|
|
105
|
+
```shell
|
|
106
|
+
lib/swagger/administration_api_v2.json
|
|
107
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
|
|
3
|
+
Generates the Dosser platform scaffold.
|
|
4
|
+
|
|
5
|
+
Example:
|
|
6
|
+
|
|
7
|
+
rails generate repres:dosser:platform administration --version 2
|
|
8
|
+
|
|
9
|
+
This will insert the following routings into the config/routes.rb file:
|
|
10
|
+
|
|
11
|
+
scope '/administration-api/v2', module: 'administration/dosser/v2', as: 'administration_dosser_v2' do
|
|
12
|
+
resources :portals, only: :show
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
and create the following files:
|
|
16
|
+
|
|
17
|
+
app/controllers/administration/dosser/v2/presentation_controller.rb
|
|
18
|
+
app/controllers/administration/dosser/v2/portals_controller.rb
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# rails generate repres:dosser:platform administration --version 2
|
|
2
|
+
|
|
3
|
+
class Repres::Dosser::PlatformGenerator < Rails::Generators::NamedBase
|
|
4
|
+
|
|
5
|
+
# https://github.com/erikhuda/thor/blob/master/lib/thor/base.rb#L273
|
|
6
|
+
class_option :version, type: :numeric, required: false, default: 1, desc: 'a positive integer, the default value is 1'
|
|
7
|
+
|
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
9
|
+
|
|
10
|
+
def produce
|
|
11
|
+
|
|
12
|
+
@platform_name = file_name.downcase
|
|
13
|
+
@version_number = options['version'].to_i
|
|
14
|
+
|
|
15
|
+
generate_controller
|
|
16
|
+
generate_route
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def define_namespace(content)
|
|
21
|
+
content.gsub! /PlatformModuleName/, platform_module_name
|
|
22
|
+
content.gsub! /VersionModuleName/, version_module_name
|
|
23
|
+
content.gsub! /platform_name/, platform_name
|
|
24
|
+
content.gsub! /version_name/, version_name
|
|
25
|
+
content.gsub! /version_number/, version_number.to_s
|
|
26
|
+
content
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# controller
|
|
30
|
+
#
|
|
31
|
+
# app/controllers/platform/version/presentation_controller.rb
|
|
32
|
+
# app/controllers/platform/version/portals_controller.rb
|
|
33
|
+
#
|
|
34
|
+
def generate_controller
|
|
35
|
+
copy_file('app/controllers/presentation_controller.rb', "app/controllers/#{platform_name}/dosser/#{version_name}/presentation_controller.rb") { |content| define_namespace content }
|
|
36
|
+
copy_file('app/controllers/portals_controller.rb', "app/controllers/#{platform_name}/dosser/#{version_name}/portals_controller.rb" ) { |content| define_namespace content }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# route
|
|
40
|
+
#
|
|
41
|
+
# config/routes.rb
|
|
42
|
+
#
|
|
43
|
+
def generate_route
|
|
44
|
+
source = File.expand_path find_in_source_paths('config/routes.rb')
|
|
45
|
+
File.open(source, 'rb') { |f| route define_namespace(f.read.to_s.strip) }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Administration
|
|
49
|
+
def platform_module_name
|
|
50
|
+
#@platform_name.capitalize
|
|
51
|
+
@platform_name.camelize
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# administration
|
|
55
|
+
def platform_name
|
|
56
|
+
@platform_name
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Administration::V1
|
|
60
|
+
def platform_version_module_name
|
|
61
|
+
"#{platform_module_name}::Dosser::#{version_module_name}"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# V1
|
|
65
|
+
def version_module_name
|
|
66
|
+
"V#{version_number}"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# v1
|
|
70
|
+
def version_name
|
|
71
|
+
"v#{version_number}"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# 1
|
|
75
|
+
def version_number
|
|
76
|
+
@version_number
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
private :define_namespace,
|
|
80
|
+
:generate_controller, :generate_route,
|
|
81
|
+
:platform_module_name, :platform_name, :platform_version_module_name,
|
|
82
|
+
:version_module_name, :version_name, :version_number
|
|
83
|
+
|
|
84
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class PlatformModuleName::Dosser::VersionModuleName::PortalsController < PlatformModuleName::Dosser::VersionModuleName::PresentationController
|
|
2
|
+
|
|
3
|
+
def show
|
|
4
|
+
render_ok collection: [
|
|
5
|
+
{
|
|
6
|
+
name: 'PlatformModuleName API version_name',
|
|
7
|
+
links: [
|
|
8
|
+
{ rel: 'self', href: platform_name_dosser_version_name_portal_url(Unidom::Common::SELF, format: request.format.symbol) },
|
|
9
|
+
{ rel: 'canonial', href: platform_name_dosser_version_name_portal_url(Unidom::Common::SELF, format: :json ) },
|
|
10
|
+
{ rel: 'alternate', href: platform_name_dosser_version_name_portal_url(Unidom::Common::SELF, format: :xml ) }
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
data/lib/generators/repres/dosser/platform/templates/app/controllers/presentation_controller.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'unidom'
|
|
2
|
+
|
|
3
|
+
class PlatformModuleName::Dosser::VersionModuleName::PresentationController < ActionController::Base
|
|
4
|
+
|
|
5
|
+
clear_helpers
|
|
6
|
+
|
|
7
|
+
include Repres::Dosser::Concerns::ResourcePresentation
|
|
8
|
+
|
|
9
|
+
layout nil
|
|
10
|
+
|
|
11
|
+
before_action :load_unidom
|
|
12
|
+
|
|
13
|
+
def load_unidom
|
|
14
|
+
initialize_unidom
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
|
|
3
|
+
Generates the Dosser Swagger scaffold.
|
|
4
|
+
|
|
5
|
+
Example:
|
|
6
|
+
|
|
7
|
+
rails generate repres:dosser:swagger administration --version 2
|
|
8
|
+
|
|
9
|
+
This will call the following command:
|
|
10
|
+
|
|
11
|
+
rails generate repres:dosser:platform administration --version 2
|
|
12
|
+
|
|
13
|
+
before insert the swagger_engine & the latest repres-dosser gem into the Gemfile file and will create the following file:
|
|
14
|
+
|
|
15
|
+
lib/swagger/administration_api_v2.json
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# rails generate repres:dosser:swagger administration --version 2
|
|
2
|
+
|
|
3
|
+
class Repres::Dosser::SwaggerGenerator < Rails::Generators::NamedBase
|
|
4
|
+
|
|
5
|
+
# https://github.com/erikhuda/thor/blob/master/lib/thor/base.rb#L273
|
|
6
|
+
class_option :version, type: :numeric, required: false, default: 1, desc: 'a positive integer, the default value is 1'
|
|
7
|
+
|
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
9
|
+
|
|
10
|
+
def produce
|
|
11
|
+
|
|
12
|
+
@platform_name = file_name.downcase
|
|
13
|
+
@version_number = options['version'].to_i
|
|
14
|
+
|
|
15
|
+
generate 'repres:dosser:platform', "#{@platform_name} --version #{@version_number}"
|
|
16
|
+
|
|
17
|
+
generate_gemfile
|
|
18
|
+
generate_swagger
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def define_namespace(content)
|
|
23
|
+
content.gsub! /PlatformModuleName/, platform_module_name
|
|
24
|
+
content.gsub! /VersionModuleName/, version_module_name
|
|
25
|
+
content.gsub! /platform_name/, platform_name
|
|
26
|
+
content.gsub! /version_name/, version_name
|
|
27
|
+
content.gsub! /version_number/, version_number.to_s
|
|
28
|
+
content
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# gemfile
|
|
32
|
+
#
|
|
33
|
+
# Gemfile
|
|
34
|
+
#
|
|
35
|
+
def generate_gemfile
|
|
36
|
+
gem 'swagger_engine'
|
|
37
|
+
gem 'repres-dosser', ">= #{Repres::Dosser::VERSION}"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# swagger
|
|
41
|
+
#
|
|
42
|
+
# lib/swagger/administration_api_v1.json
|
|
43
|
+
#
|
|
44
|
+
def generate_swagger
|
|
45
|
+
copy_file('lib/swagger/api.json', "lib/swagger/#{platform_name}_api_#{version_name}.json") { |content| define_namespace content }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Administration
|
|
49
|
+
def platform_module_name
|
|
50
|
+
#@platform_name.capitalize
|
|
51
|
+
@platform_name.camelize
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# administration
|
|
55
|
+
def platform_name
|
|
56
|
+
@platform_name
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Administration::V1
|
|
60
|
+
def platform_version_module_name
|
|
61
|
+
"#{platform_module_name}::Dosser::#{version_module_name}"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# V1
|
|
65
|
+
def version_module_name
|
|
66
|
+
"V#{version_number}"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# v1
|
|
70
|
+
def version_name
|
|
71
|
+
"v#{version_number}"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# 1
|
|
75
|
+
def version_number
|
|
76
|
+
@version_number
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
private :define_namespace,
|
|
80
|
+
:generate_gemfile, :generate_swagger,
|
|
81
|
+
:platform_module_name, :platform_name, :platform_version_module_name,
|
|
82
|
+
:version_module_name, :version_name, :version_number
|
|
83
|
+
|
|
84
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
{
|
|
2
|
+
"swagger": "2.0",
|
|
3
|
+
"info": {
|
|
4
|
+
"title": "PlatformModuleName Web API",
|
|
5
|
+
"description": "PlatformModuleName RESTful Web API version_name",
|
|
6
|
+
"contact": { "name": "Your Name", "email": "user@company.com" },
|
|
7
|
+
"version": "version_number"
|
|
8
|
+
},
|
|
9
|
+
"schemes": [ "https", "http" ],
|
|
10
|
+
"basePath": "/platform_name-api/version_name",
|
|
11
|
+
"produces": [ "application/json" ],
|
|
12
|
+
"consumes": [ "application/json" ],
|
|
13
|
+
"paths": {
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
"/portals/~": {
|
|
18
|
+
"get": {
|
|
19
|
+
"summary": "Platform Portal",
|
|
20
|
+
"description": "The Mobile client or Browsers should access this Web API before get the links of the other resources.",
|
|
21
|
+
"tags": [ "元数据" ],
|
|
22
|
+
"parameters": [
|
|
23
|
+
{
|
|
24
|
+
"name": "open_id",
|
|
25
|
+
"in": "query",
|
|
26
|
+
"description": "Open ID of the current user",
|
|
27
|
+
"required": false,
|
|
28
|
+
"type": "string",
|
|
29
|
+
"format": "uuid"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"responses": {
|
|
33
|
+
"200": {
|
|
34
|
+
"description": "移动端应用获取其他Web API链接的返回。",
|
|
35
|
+
"schema": { "$ref": "#/definitions/LoadPortalResponseBody" }
|
|
36
|
+
},
|
|
37
|
+
"default": {
|
|
38
|
+
"description": "出现错误。",
|
|
39
|
+
"schema": { "$ref": "#/definitions/ErrorResponseBody" }
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
"definitions": {
|
|
50
|
+
|
|
51
|
+
"Date": { "type": "string", "format": "date" },
|
|
52
|
+
"Second": { "type": "integer", "format": "int64" },
|
|
53
|
+
|
|
54
|
+
"LinkList": { "type": "array", "items": { "type": "object", "properties": { "rel": { "type": "string" }, "href": { "type": "string" }, "title": { "type": "string" } } } },
|
|
55
|
+
|
|
56
|
+
"ResponseBodyCommonProperties": {
|
|
57
|
+
"type": "object",
|
|
58
|
+
"properties": {
|
|
59
|
+
|
|
60
|
+
"success": { "type": "boolean" },
|
|
61
|
+
"code": { "type": "string" },
|
|
62
|
+
"message": { "type": "string" },
|
|
63
|
+
"size": { "type": "integer", "format": "int32" },
|
|
64
|
+
"errors": { "type": "string", "additionalProperties": { "type": "array", "items": { "type": "string" } } },
|
|
65
|
+
|
|
66
|
+
"meta": {
|
|
67
|
+
"type": "object",
|
|
68
|
+
"properties": {
|
|
69
|
+
"timestamp": { "type": "integer", "format": "int32" },
|
|
70
|
+
"request_id": { "type": "string", "format": "uuid" },
|
|
71
|
+
"criteria": { "type": "object", "additionalProperties": { "type": "string" } },
|
|
72
|
+
"pagination": { "type": "object",
|
|
73
|
+
"properties": {
|
|
74
|
+
"total_items": { "type": "integer", "format": "int32" },
|
|
75
|
+
"per_page": { "type": "integer", "format": "int32" },
|
|
76
|
+
"current_page": { "type": "integer", "format": "int32" },
|
|
77
|
+
"total_pages": { "type": "integer", "format": "int32" },
|
|
78
|
+
"min_item_on_current_page": { "type": "integer", "format": "int32" },
|
|
79
|
+
"max_item_on_current_page": { "type": "integer", "format": "int32" },
|
|
80
|
+
"items_on_current_page": { "type": "integer", "format": "int32" }
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
"ErrorResponseBody": {
|
|
90
|
+
"description": "出现错误时的响应体",
|
|
91
|
+
"allOf": [
|
|
92
|
+
{ "$ref": "#/definitions/ResponseBodyCommonProperties" },
|
|
93
|
+
{ "type": "object", "properties": { "collection": { "type": "array", "items": { "type": "object", "additionalProperties": { "type": "string" } } } } }
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
"LoadPortalResponseBody": {
|
|
100
|
+
"description": "元数据的响应体",
|
|
101
|
+
"allOf": [
|
|
102
|
+
{ "$ref": "#/definitions/ResponseBodyCommonProperties" },
|
|
103
|
+
{ "type": "object", "properties": { "collection": { "type": "array", "items": { "$ref": "#/definitions/LoadPortalResponseItem" } } } }
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
"LoadPortalResponseItem": {
|
|
108
|
+
"type": "object",
|
|
109
|
+
"properties": {
|
|
110
|
+
"name": { "type": "string" },
|
|
111
|
+
"links": { "$ref": "#/definitions/LinkList" }
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
}
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: repres-dosser
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '1.
|
|
4
|
+
version: '1.6'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Topbit Du
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-08-
|
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -44,6 +44,14 @@ files:
|
|
|
44
44
|
- app/helpers/repres/dosser/application_helper.rb
|
|
45
45
|
- app/views/layouts/repres/dosser/application.html.erb
|
|
46
46
|
- config/routes.rb
|
|
47
|
+
- lib/generators/repres/dosser/platform/USAGE
|
|
48
|
+
- lib/generators/repres/dosser/platform/platform_generator.rb
|
|
49
|
+
- lib/generators/repres/dosser/platform/templates/app/controllers/portals_controller.rb
|
|
50
|
+
- lib/generators/repres/dosser/platform/templates/app/controllers/presentation_controller.rb
|
|
51
|
+
- lib/generators/repres/dosser/platform/templates/config/routes.rb
|
|
52
|
+
- lib/generators/repres/dosser/swagger/USAGE
|
|
53
|
+
- lib/generators/repres/dosser/swagger/swagger_generator.rb
|
|
54
|
+
- lib/generators/repres/dosser/swagger/templates/lib/swagger/api.json
|
|
47
55
|
- lib/repres/dosser.rb
|
|
48
56
|
- lib/repres/dosser/engine.rb
|
|
49
57
|
- lib/repres/dosser/version.rb
|