repres-dosser 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +30 -0
- data/Rakefile +24 -0
- data/app/assets/javascripts/repres/dosser/application.js +13 -0
- data/app/assets/stylesheets/repres/dosser/application.css +15 -0
- data/app/controllers/repres/dosser/application_controller.rb +2 -0
- data/app/controllers/repres/dosser/concerns/resource_presentation.rb +132 -0
- data/app/helpers/repres/dosser/application_helper.rb +2 -0
- data/app/views/layouts/repres/dosser/application.html.erb +14 -0
- data/config/routes.rb +2 -0
- data/lib/repres/dosser.rb +6 -0
- data/lib/repres/dosser/engine.rb +23 -0
- data/lib/repres/dosser/version.rb +5 -0
- data/lib/tasks/dosser_tasks.rake +4 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fb97dc4a3abaf0e284039001f0109caad69abad5
|
4
|
+
data.tar.gz: 424747fa8803fb1ca26f57556f5f3787bc2b269d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d8d4304c26fe93ca8c7df9346cbac2b0a78e78e57f18f6419cc62bb06ea3ddbd4bfaa654df0594f7bc615f19d6cd8aef80326ba77c8a2e939891af5893271169
|
7
|
+
data.tar.gz: 8d0fafe8985be64dbd52ec1f418ca26f30e05e2301455e64d2e08a6c142fe12c73330fc4e1963f0efdc091898c978b69c9f9e3f099532c819722fa0da1a728f1
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Topbit Du
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Repres Dosser 领域特定语意表现引擎
|
2
|
+
|
3
|
+
[![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/repres-dosser.svg)](https://badge.fury.io/rb/repres-dosser)
|
5
|
+
|
6
|
+
Repres (REsource PRESentation) is a series of resource presentation engines. The Dosser (DOmain-Specific SEmantic Representation) resource presentation engine includes JSON and XML resource presentation templates.
|
7
|
+
Repres (资源表现)是一系列的资源表现引擎。Dosser (领域特定语意表现) 资源表现引擎包括JSON和XML表现模版。
|
8
|
+
|
9
|
+
## Why Use Repres Dosser
|
10
|
+
Dosser pre-defined some glossaries for RESTful Web API, which follows the Template Method design pattern.
|
11
|
+
Dosser 预定义了一些适用于 RESTful Web API 的词汇,并且采用了“模版方法”设计模式。
|
12
|
+
|
13
|
+
## Recent Update
|
14
|
+
Check out the [Road Map](ROADMAP.md) to find out what's the next.
|
15
|
+
Check out the [Change Log](CHANGELOG.md) to find out what's new.
|
16
|
+
|
17
|
+
## Usage in Gemfile
|
18
|
+
```ruby
|
19
|
+
gem 'repres-dosser'
|
20
|
+
```
|
21
|
+
|
22
|
+
## Include the Concern in Controllers & Respond the Calls
|
23
|
+
```ruby
|
24
|
+
include Repres::Dosser::Concerns::ResourcePresentation
|
25
|
+
|
26
|
+
def index
|
27
|
+
self.criteria = { page: params[:page] }
|
28
|
+
render_ok [ { name: 'Topbit' }, { name: 'Roland' } ]
|
29
|
+
end
|
30
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Repres Dosser'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
load 'rails/tasks/statistics.rake'
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
Bundler::GemHelper.install_tasks
|
24
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,132 @@
|
|
1
|
+
module Repres::Dosser::Concerns::ResourcePresentation
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
CODE_SUCCESS = 'success'.freeze
|
6
|
+
CODE_FAILURE = 'failure'.freeze
|
7
|
+
|
8
|
+
CODE_FAILURE_NOT_FOUND = 'failure-not-found'.freeze
|
9
|
+
CODE_FAILURE_WRONG_PARAMETER = 'failure-wrong-parameter'.freeze
|
10
|
+
CODE_FAILURE_WRONG_STATE = 'failure-wrong-state'.freeze
|
11
|
+
|
12
|
+
self.included do |includer|
|
13
|
+
|
14
|
+
attr_writer :criteria
|
15
|
+
|
16
|
+
# 200
|
17
|
+
def render_ok(collection, size = collection.size, message = nil)
|
18
|
+
result = {
|
19
|
+
success: true,
|
20
|
+
code: self.class::CODE_SUCCESS,
|
21
|
+
message: message||'成功。',
|
22
|
+
collection: collection,
|
23
|
+
size: size,
|
24
|
+
errors: {}
|
25
|
+
}
|
26
|
+
respond_result :ok, result
|
27
|
+
end
|
28
|
+
|
29
|
+
# 201
|
30
|
+
def render_created(collection, size = collection.size, message = nil)
|
31
|
+
result = {
|
32
|
+
success: true,
|
33
|
+
code: self.class::CODE_SUCCESS,
|
34
|
+
message: message||'创建成功。',
|
35
|
+
collection: collection,
|
36
|
+
size: size,
|
37
|
+
errors: {}
|
38
|
+
}
|
39
|
+
respond_result :created, result
|
40
|
+
end
|
41
|
+
|
42
|
+
# 400
|
43
|
+
def render_bad_request(errors, code = nil, message = nil, collection = [], size = 0)
|
44
|
+
result = {
|
45
|
+
success: false,
|
46
|
+
code: code||self.class::CODE_FAILURE_WRONG_PARAMETER,
|
47
|
+
message: message||'参数出错。',
|
48
|
+
collection: collection,
|
49
|
+
size: size,
|
50
|
+
errors: errors
|
51
|
+
}
|
52
|
+
respond_result :bad_request, result
|
53
|
+
end
|
54
|
+
|
55
|
+
# 400 bad request - blank parameter
|
56
|
+
def render_blank_parameter(parameter_name)
|
57
|
+
result = {
|
58
|
+
success: false,
|
59
|
+
code: self.class::CODE_FAILURE_WRONG_PARAMETER,
|
60
|
+
message: "#{parameter_name}参数不能为空。",
|
61
|
+
collection: [],
|
62
|
+
size: 0,
|
63
|
+
errors: { parameter_name => [ '不能为空' ] }
|
64
|
+
}
|
65
|
+
respond_result :bad_request, result
|
66
|
+
end
|
67
|
+
|
68
|
+
# 404
|
69
|
+
def render_not_found(errors, message = nil, collection = [], size = 0)
|
70
|
+
result = {
|
71
|
+
success: false,
|
72
|
+
code: self.class::CODE_FAILURE_NOT_FOUND,
|
73
|
+
message: message||'没有找到符合条件的信息。',
|
74
|
+
collection: collection,
|
75
|
+
size: size,
|
76
|
+
errors: errors
|
77
|
+
}
|
78
|
+
respond_result :not_found, result
|
79
|
+
end
|
80
|
+
|
81
|
+
# 404 not found - inexistent
|
82
|
+
def render_inexistent(parameter_name, message)
|
83
|
+
result = {
|
84
|
+
success: false,
|
85
|
+
code: self.class::CODE_FAILURE_NOT_FOUND,
|
86
|
+
message: message,
|
87
|
+
collection: [],
|
88
|
+
size: 0,
|
89
|
+
errors: { parameter_name => [ '不存在' ] }
|
90
|
+
}
|
91
|
+
respond_result :not_found, result
|
92
|
+
end
|
93
|
+
|
94
|
+
# 409
|
95
|
+
def render_conflict(errors, message, collection = [], size = 0)
|
96
|
+
result = {
|
97
|
+
success: false,
|
98
|
+
code: self.class::CODE_FAILURE_WRONG_STATE,
|
99
|
+
message: message,
|
100
|
+
collection: collection,
|
101
|
+
size: size,
|
102
|
+
errors: errors
|
103
|
+
}
|
104
|
+
respond_result :conflict, result
|
105
|
+
end
|
106
|
+
|
107
|
+
# 409 conflict - wrong parameter
|
108
|
+
def render_wrong_parameter(errors, message, collection = [], size = 0)
|
109
|
+
result = {
|
110
|
+
success: false,
|
111
|
+
code: self.class::CODE_FAILURE_WRONG_PARAMETER,
|
112
|
+
message: message,
|
113
|
+
collection: collection,
|
114
|
+
size: size,
|
115
|
+
errors: errors
|
116
|
+
}
|
117
|
+
respond_result :conflict, result
|
118
|
+
end
|
119
|
+
|
120
|
+
def respond_result(status, result)
|
121
|
+
result[:meta] = { request_id: request.uuid, criteria: @criteria }
|
122
|
+
respond_to do |format|
|
123
|
+
format.json do render status: status, json: result end
|
124
|
+
format.xml do render status: status, xml: result end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
private :respond_result
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dosser</title>
|
5
|
+
<%= stylesheet_link_tag "dosser/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "dosser/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Repres
|
2
|
+
module Dosser
|
3
|
+
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
|
6
|
+
config.autoload_paths += %W(
|
7
|
+
#{config.root}/lib
|
8
|
+
#{config.root}/app/controllers/repres/dosser/concerns
|
9
|
+
#{config.root}/app/models/repres/dosser/concerns
|
10
|
+
)
|
11
|
+
|
12
|
+
config.eager_load_paths += %W(
|
13
|
+
#{config.root}/lib
|
14
|
+
#{config.root}/app/controllers/repres/dosser/concerns
|
15
|
+
#{config.root}/app/models/repres/dosser/concerns
|
16
|
+
)
|
17
|
+
|
18
|
+
isolate_namespace Repres::Dosser
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: repres-dosser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Topbit Du
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
description: Repres (REsource PRESentation) is a series of resource presentation engines.
|
28
|
+
The Dosser (DOmain-Specific SEmantic Representation) resource presentation engine
|
29
|
+
includes JSON and XML resource presentation templates. Repres (资源表现)是一系列的资源表现引擎。Dosser
|
30
|
+
(领域特定语意表现) 资源表现引擎包括JSON和XML表现模版。
|
31
|
+
email:
|
32
|
+
- topbit.du@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- MIT-LICENSE
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- app/assets/javascripts/repres/dosser/application.js
|
41
|
+
- app/assets/stylesheets/repres/dosser/application.css
|
42
|
+
- app/controllers/repres/dosser/application_controller.rb
|
43
|
+
- app/controllers/repres/dosser/concerns/resource_presentation.rb
|
44
|
+
- app/helpers/repres/dosser/application_helper.rb
|
45
|
+
- app/views/layouts/repres/dosser/application.html.erb
|
46
|
+
- config/routes.rb
|
47
|
+
- lib/repres/dosser.rb
|
48
|
+
- lib/repres/dosser/engine.rb
|
49
|
+
- lib/repres/dosser/version.rb
|
50
|
+
- lib/tasks/dosser_tasks.rake
|
51
|
+
homepage: https://github.com/topbitdu/repres-dosser
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.4.5.1
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Dosser Resource Presentation Engine 领域特定语意表现资源表现引擎
|
75
|
+
test_files: []
|