apitest 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -4
- data/app/assets/config/apitest_manifest.js +1 -1
- data/app/assets/stylesheets/apitest/application.scss +1 -1
- data/app/controllers/apitest/apitest_controller.rb +41 -32
- data/app/views/layouts/apitest/application.slim +1 -1
- data/config/routes.rb +1 -1
- data/lib/apitest/version.rb +1 -1
- data/lib/apitest.rb +33 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81fc56ffb2514081bf6f44b460f844c922f148b5
|
4
|
+
data.tar.gz: 002c7eddb0329509034747a287b19ba04cd3fb2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e4b74aebaeb67a44a9b7bfe8b51c07c8265684bfdc9e4714b32b17e26b5fd16db3f7624c6d1beafcde041af168ce28d451f3ea6f27a3b764536c59f0aeaf63d
|
7
|
+
data.tar.gz: ef145628b987cab510cf778c7157d5d55dcb63983bfac399b2f338f140b4776a02afdc27d4d53167ab9d219a187405fa283815c6a7e5325158a99a0463fbd4d9
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
Short description and motivation.
|
3
3
|
|
4
4
|
## Version
|
5
|
-
0.1.
|
5
|
+
0.1.5
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
添加如下代码到 Gemfile:
|
@@ -45,20 +45,56 @@ $ brew install lsof #MacOS
|
|
45
45
|
│ │ ├── barfoo_controller.rb
|
46
46
|
```
|
47
47
|
|
48
|
-
|
48
|
+
在routes.rb 配置apitest 目录,比如:
|
49
49
|
|
50
50
|
```ruby
|
51
|
-
|
51
|
+
apitest_for '/apitest'
|
52
52
|
|
53
53
|
```
|
54
54
|
|
55
55
|
浏览器中访问apitest 的url
|
56
56
|
|
57
|
+
默认api目录为controllers/api,目录可指定
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
apitest_for '/apitest' do
|
61
|
+
Apitest::api_dir 'api'
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
默认使用blue-theme,可指定theme ,theme使用 AdminLTE,直接指定AdminLTE的theme即可:
|
66
|
+
|
67
|
+
``` ruby
|
68
|
+
apitest_for '/apitest' do
|
69
|
+
Apitest::theme 'purple-light'
|
70
|
+
end
|
71
|
+
```
|
72
|
+
theme列表如下
|
73
|
+
```
|
74
|
+
black-light
|
75
|
+
black
|
76
|
+
blue-light
|
77
|
+
blue
|
78
|
+
green-light
|
79
|
+
green
|
80
|
+
purple-light
|
81
|
+
purple
|
82
|
+
red-light
|
83
|
+
red
|
84
|
+
yellow-light
|
85
|
+
yellow
|
86
|
+
```
|
57
87
|
|
58
88
|
|
59
89
|
|
60
90
|
## TODO
|
61
|
-
- [
|
91
|
+
- [x] 可自定义api目录
|
92
|
+
- [x] 可自定义theme
|
93
|
+
- [ ] ERROR类工具
|
94
|
+
- [ ] APIDOC美化
|
95
|
+
- [ ] 权限控制
|
96
|
+
- [ ] 测试数据准备,测试用例
|
97
|
+
- [ ] 测试中心
|
62
98
|
|
63
99
|
## Contributing
|
64
100
|
|
@@ -1,2 +1,2 @@
|
|
1
1
|
//= link_directory ../javascripts/apitest .js
|
2
|
-
//= link_directory ../stylesheets/apitest
|
2
|
+
//= link_directory ../stylesheets/apitest
|
@@ -1,5 +1,5 @@
|
|
1
1
|
// Place all the styles related to the apitest/v1 controller here.
|
2
|
-
// They will automatically be included in application.
|
2
|
+
// They will automatically be included in application.
|
3
3
|
// You can use Sass (SCSS) here: http://sass-lang.com/
|
4
4
|
//= require_directory .
|
5
5
|
//= require bootstrap
|
@@ -2,7 +2,11 @@ require_dependency "apitest/application_controller"
|
|
2
2
|
|
3
3
|
module Apitest
|
4
4
|
class ApitestController < ApplicationController
|
5
|
-
before_action :get_doc
|
5
|
+
before_action :get_doc ,:root_url
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
@apidocs = {}
|
9
|
+
end
|
6
10
|
def index
|
7
11
|
respond_to do |format|
|
8
12
|
format.json { render json: @apidocs}
|
@@ -17,43 +21,48 @@ module Apitest
|
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
20
|
-
private
|
21
|
-
def
|
22
|
-
path_root = "app/controllers/api/"
|
23
|
-
@apidocs = {}
|
24
|
-
Dir.glob("#{path_root}*").map do |path|
|
25
|
-
if File.directory?(path)
|
26
|
-
@apidocs[path.gsub("#{path_root}" , '')] = get_version_doc "#{path}/"
|
27
|
-
end
|
28
|
-
end
|
24
|
+
private
|
25
|
+
def root_url
|
29
26
|
@root_url = main_app.root_url[0,main_app.root_url.length - 1]
|
30
|
-
end
|
27
|
+
end
|
31
28
|
|
32
|
-
def
|
33
|
-
|
34
|
-
docs = {
|
29
|
+
def docs_base
|
30
|
+
{
|
35
31
|
'业务API' => [] ,
|
36
32
|
'工具API' => [] ,
|
37
33
|
'辅助API' => []
|
38
34
|
}
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
if
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
35
|
+
end
|
36
|
+
def get_doc(path_root = nil)
|
37
|
+
path_root ||= "app/controllers/#{Apitest.api_dir}/"
|
38
|
+
Dir.glob("#{path_root}*").each do |path|
|
39
|
+
@apidocs[path.gsub("#{path_root}" , '')] = get_version_doc "#{path}/" if File.directory?(path) && !path.gsub("#{path_root}" , '').blank?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_version_doc(path_root)
|
44
|
+
docs = docs_base
|
45
|
+
Dir.glob("#{path_root}/*").each do |path|
|
46
|
+
if File.directory?(path)
|
47
|
+
docs = docs.merge get_version_doc(path)
|
48
|
+
else
|
49
|
+
class_match = File.open(path).read.match(/class (.*) </)
|
50
|
+
controller_class = class_match[1].constantize if class_match && class_match[1]
|
51
|
+
if defined? controller_class::APIDOC
|
52
|
+
token_need = {
|
53
|
+
token: {
|
54
|
+
text: 'token' ,
|
55
|
+
required: true ,
|
56
|
+
}
|
57
|
+
}
|
58
|
+
doc = controller_class::APIDOC
|
59
|
+
doc[:sort] = 99 if doc[:sort].blank?
|
60
|
+
doc[:apis].each do |k,v|
|
61
|
+
doc[:apis][k][:params] = token_need.merge doc[:apis][k][:params] unless v[:token] == false
|
62
|
+
end
|
63
|
+
docs[doc[:type]] = [] if docs[doc[:type]].blank?
|
64
|
+
docs[doc[:type]].push doc
|
65
|
+
end
|
57
66
|
end
|
58
67
|
end
|
59
68
|
docs
|
@@ -5,7 +5,7 @@ html
|
|
5
5
|
= csrf_meta_tags
|
6
6
|
= stylesheet_link_tag 'apitest/application', 'data-turbolinks-track': 'reload' , media: 'all'
|
7
7
|
= javascript_include_tag 'apitest/application', 'data-turbolinks-track': 'reload'
|
8
|
-
body.hold-transition.
|
8
|
+
body.hold-transition.sidebar-mini class="skin-#{Apitest::theme}"
|
9
9
|
.wrapper id="apitest_#{params[:action]}"
|
10
10
|
header.main-header
|
11
11
|
a.logo href="#{root_path}"
|
data/config/routes.rb
CHANGED
data/lib/apitest/version.rb
CHANGED
data/lib/apitest.rb
CHANGED
@@ -10,17 +10,19 @@ require 'eventmachine-tail'
|
|
10
10
|
require 'websocket-eventmachine-server'
|
11
11
|
|
12
12
|
module Apitest
|
13
|
-
|
14
|
-
|
15
|
-
super(path, startpos)
|
16
|
-
@buffer = BufferedTokenizer.new
|
17
|
-
@block = block
|
18
|
-
end
|
13
|
+
@api_dir
|
14
|
+
@theme
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
def self.api_dir(dir = nil)
|
17
|
+
@api_dir = dir if dir
|
18
|
+
@api_dir
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.theme(theme = nil)
|
22
|
+
@theme = theme if theme
|
23
|
+
@theme
|
23
24
|
end
|
25
|
+
|
24
26
|
def self.start_server_log_listen
|
25
27
|
Process.detach(
|
26
28
|
fork do
|
@@ -44,7 +46,28 @@ module Apitest
|
|
44
46
|
end
|
45
47
|
)
|
46
48
|
end
|
47
|
-
end
|
48
49
|
|
50
|
+
class Reader < EventMachine::FileTail
|
51
|
+
def initialize(path, startpos=-1, &block)
|
52
|
+
super(path, startpos)
|
53
|
+
@buffer = BufferedTokenizer.new
|
54
|
+
@block = block
|
55
|
+
end
|
49
56
|
|
57
|
+
def receive_data(data)
|
58
|
+
@buffer.extract(data).each { |line| @block.call(line) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
module ActionDispatch::Routing
|
64
|
+
class Mapper
|
65
|
+
def apitest_for(path , &block)
|
66
|
+
mount Apitest::Engine => path
|
67
|
+
Apitest::api_dir 'api'
|
68
|
+
Apitest::theme 'blue-light'
|
69
|
+
block.call
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
50
73
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apitest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyuubi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|