unirer-dosser 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5e17b4b841672f76a1372713c7b95aba7ea25e48
4
+ data.tar.gz: b95f4af6de1114be1d834548c0a4cbf871c59ab0
5
+ SHA512:
6
+ metadata.gz: c0dc4043a64236df41bf4bf0ba9b46859c56b89f0547e852481754904b3465b4d354881c69586dd0d47dd510fe1918b35c743ae78a2f9011009ab65edb276ef0
7
+ data.tar.gz: 80ab42489319968c14a3e4b1ded0de6c16f1c0d6a688a2abcb179bf89c66f06a7904e6ef1c473b53dfa946166bc47bce67316c124ca9d54f5e20dae7423cae9e
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,18 @@
1
+ = Dosser
2
+
3
+ Unirer (UNIfied REsource Representation) is a series of resource representation engines. The Dosser (DOmain-Specific SEmantic Representation) resource representation engine includes JSON and XML resource representation templates.
4
+ Unirer (统一资源表现)是一系列的资源表现引擎。Dosser (领域特定语意表现) 资源表现引擎包括JSON和XML表现模版。
5
+
6
+ ## Usage in Gemfile:
7
+ ```ruby
8
+ gem 'unirer-dosser'
9
+ ```
10
+
11
+ ## Include the Concern in Controllers & Respond the Calls:
12
+ ```ruby
13
+ include Unirer::Dosser::Concerns::ResourceRepresentation
14
+
15
+ def index
16
+ render_ok [ { name: 'Topbit' }, { name: 'Roland' } ]
17
+ end
18
+ ```
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 = 'Unirer 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,2 @@
1
+ class Unirer::Dosser::ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,139 @@
1
+ module Unirer::Dosser::Concerns::ResourceRepresentation
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_accessor :meta
15
+
16
+ # 200
17
+ def render_ok(collection, size = collection.size, message = nil)
18
+ result = {
19
+ meta: meta,
20
+ success: true,
21
+ code: self.class::CODE_SUCCESS,
22
+ message: message||'成功。',
23
+ collection: collection,
24
+ size: size,
25
+ errors: {}
26
+ }
27
+ respond_result :ok, result
28
+ end
29
+
30
+ # 201
31
+ def render_created(collection, size = collection.size, message = nil)
32
+ result = {
33
+ meta: meta,
34
+ success: true,
35
+ code: self.class::CODE_SUCCESS,
36
+ message: message||'创建成功。',
37
+ collection: collection,
38
+ size: size,
39
+ errors: {}
40
+ }
41
+ respond_result :created, result
42
+ end
43
+
44
+ # 400
45
+ def render_bad_request(errors, code = nil, message = nil, collection = [], size = 0)
46
+ result = {
47
+ meta: meta,
48
+ success: false,
49
+ code: code||self.class::CODE_FAILURE_WRONG_PARAMETER,
50
+ message: message||'参数出错。',
51
+ collection: collection,
52
+ size: size,
53
+ errors: errors
54
+ }
55
+ respond_result :bad_request, result
56
+ end
57
+
58
+ # 400 bad request - blank parameter
59
+ def render_blank_parameter(parameter_name)
60
+ result = {
61
+ meta: meta,
62
+ success: false,
63
+ code: self.class::CODE_FAILURE_WRONG_PARAMETER,
64
+ message: "#{parameter_name}参数不能为空。",
65
+ collection: [],
66
+ size: 0,
67
+ errors: { parameter_name => [ '不能为空' ] }
68
+ }
69
+ respond_result :bad_request, result
70
+ end
71
+
72
+ # 404
73
+ def render_not_found(errors, message = nil, collection = [], size = 0)
74
+ result = {
75
+ meta: meta,
76
+ success: false,
77
+ code: self.class::CODE_FAILURE_NOT_FOUND,
78
+ message: message||'没有找到符合条件的信息。',
79
+ collection: collection,
80
+ size: size,
81
+ errors: errors
82
+ }
83
+ respond_result :not_found, result
84
+ end
85
+
86
+ # 404 not found - inexistent
87
+ def render_inexistent(parameter_name, message)
88
+ result = {
89
+ meta: meta,
90
+ success: false,
91
+ code: self.class::CODE_FAILURE_NOT_FOUND,
92
+ message: message,
93
+ collection: [],
94
+ size: 0,
95
+ errors: { parameter_name => [ '不存在' ] }
96
+ }
97
+ respond_result :not_found, result
98
+ end
99
+
100
+ # 409
101
+ def render_conflict(errors, message, collection = [], size = 0)
102
+ result = {
103
+ meta: meta,
104
+ success: false,
105
+ code: self.class::CODE_FAILURE_WRONG_STATE,
106
+ message: message,
107
+ collection: collection,
108
+ size: size,
109
+ errors: errors
110
+ }
111
+ respond_result :conflict, result
112
+ end
113
+
114
+ # 409 conflict - wrong parameter
115
+ def render_wrong_parameter(errors, message, collection = [], size = 0)
116
+ result = {
117
+ meta: meta,
118
+ success: false,
119
+ code: self.class::CODE_FAILURE_WRONG_PARAMETER,
120
+ message: message,
121
+ collection: collection,
122
+ size: size,
123
+ errors: errors
124
+ }
125
+ respond_result :conflict, result
126
+ end
127
+
128
+ def respond_result(status, result)
129
+ respond_to do |format|
130
+ format.json do render status: status, json: result end
131
+ format.xml do render status: status, xml: result end
132
+ end
133
+ end
134
+
135
+ private :respond_result
136
+
137
+ end
138
+
139
+ end
@@ -0,0 +1,2 @@
1
+ module Unirer::Dosser::ApplicationHelper
2
+ 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,2 @@
1
+ Unirer::Dosser::Engine.routes.draw do
2
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :dosser do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,6 @@
1
+ require 'unirer/dosser/engine'
2
+
3
+ module Unirer
4
+ module Dosser
5
+ end
6
+ end
@@ -0,0 +1,23 @@
1
+ module Unirer
2
+ module Dosser
3
+
4
+ class Engine < ::Rails::Engine
5
+
6
+ config.autoload_paths += %W(
7
+ #{config.root}/lib
8
+ #{config.root}/app/controllers/unirer/dosser/concerns
9
+ #{config.root}/app/models/unirer/dosser/concerns
10
+ )
11
+
12
+ config.eager_load_paths += %W(
13
+ #{config.root}/lib
14
+ #{config.root}/app/controllers/unirer/dosser/concerns
15
+ #{config.root}/app/models/unirer/dosser/concerns
16
+ )
17
+
18
+ isolate_namespace Unirer::Dosser
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Unirer
2
+ module Dosser
3
+ VERSION = '0.1'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unirer-dosser
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Topbit Du
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-22 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: Unirer (UNIfied Resource Representation) is a series of resource representation
28
+ engines. The Dosser (DOmain-Specific SEmantic Representation) resource representation
29
+ engine includes JSON and XML resource representation templates. Unirer (统一资源表现)是一系列的资源表现引擎。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/unirer/dosser/application.js
41
+ - app/assets/stylesheets/unirer/dosser/application.css
42
+ - app/controllers/unirer/dosser/application_controller.rb
43
+ - app/controllers/unirer/dosser/concerns/resource_representation.rb
44
+ - app/helpers/unirer/dosser/application_helper.rb
45
+ - app/views/layouts/unirer/dosser/application.html.erb
46
+ - config/routes.rb
47
+ - lib/tasks/dosser_tasks.rake
48
+ - lib/unirer/dosser.rb
49
+ - lib/unirer/dosser/engine.rb
50
+ - lib/unirer/dosser/version.rb
51
+ homepage: https://github.com/topbitdu/unirer-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: The Dosser resource representation engine includes JSON and XML resource
75
+ representation templates.
76
+ test_files: []