apitest 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9c932efea1742c420d8d73ec4982d99ff9fb8ed
4
- data.tar.gz: 96916744dcf87a1518ca7c5adefedcc9655b502a
3
+ metadata.gz: 81fc56ffb2514081bf6f44b460f844c922f148b5
4
+ data.tar.gz: 002c7eddb0329509034747a287b19ba04cd3fb2d
5
5
  SHA512:
6
- metadata.gz: 345924cb41f29583ec7ca0f00788940dc88f80599d9f5a0f0fdc56a567d4678e2f401c11b238911b130c6f09f7a2a0dbe9268eb118bbdb784a6c50d7080b46bc
7
- data.tar.gz: be819f5df9595df40196f32b53b9aa995c801c6a9cc57d7d779c45ebe4f2bba9f1ddf1105c6ca7c207b7db4e9c28160c0c64ad0cf5bc8275e36563e2ba2b3e90
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.4
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
- mount apitest到指定url,比如:
48
+ 在routes.rb 配置apitest 目录,比如:
49
49
 
50
50
  ```ruby
51
- mount Apitest::Engine => "/apitest"
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
- - [ ] 可自定义api目录
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 .css
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.css.
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 get_doc
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 get_version_doc(path_root)
33
-
34
- docs = {
29
+ def docs_base
30
+ {
35
31
  '业务API' => [] ,
36
32
  '工具API' => [] ,
37
33
  '辅助API' => []
38
34
  }
39
- dirs = []
40
- Dir.glob("#{path_root}*_controller.rb").each do |path|
41
- controller_name_base = path.gsub(path_root , '').gsub('.rb' , '').singularize.camelize
42
- controller_class = "Api::V1::#{controller_name_base}".constantize
43
- if defined? controller_class::APIDOC
44
- token_need = {
45
- token: {
46
- text: 'token' ,
47
- required: true ,
48
- }
49
- }
50
- doc = controller_class::APIDOC
51
- doc[:sort] = 99 if doc[:sort].blank?
52
- doc[:apis].each do |k,v|
53
- doc[:apis][k][:params] = token_need.merge doc[:apis][k][:params] unless v[:token] == false
54
- end
55
- docs[doc[:type]] = [] if docs[doc[:type]].blank?
56
- docs[doc[:type]].push doc
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.skin-purple-light.sidebar-mini
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
@@ -1,5 +1,5 @@
1
1
  Apitest::Engine.routes.draw do
2
- resources :apitest
2
+ # resources :apitest
3
3
  root to: 'apitest#index'
4
4
  get '/:id' , to: 'apitest#show'
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module Apitest
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
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
- class Reader < EventMachine::FileTail
14
- def initialize(path, startpos=-1, &block)
15
- super(path, startpos)
16
- @buffer = BufferedTokenizer.new
17
- @block = block
18
- end
13
+ @api_dir
14
+ @theme
19
15
 
20
- def receive_data(data)
21
- @buffer.extract(data).each { |line| @block.call(line) }
22
- end
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
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-07 00:00:00.000000000 Z
11
+ date: 2017-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails