api_doc_generation 0.4.0 → 0.4.3

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: 81d519ebc01140cc7b74d66069a3b6eb3f8a07c7
4
- data.tar.gz: 47b6f328b09fc166044e4236ee927890d8527691
3
+ metadata.gz: dc466cb2612dc05d4675097c536b541a3c1c74a6
4
+ data.tar.gz: 40f6398342e3aa43b3aaa443ed686b751c13b3ab
5
5
  SHA512:
6
- metadata.gz: 06f370284d952468cf80dd44eeb0854264310913aacc96a7a9b80dd7d3dd755331252fe83906968320ce34662743a38b669704064fa9f5ce9f0dcfbbc0d6f800
7
- data.tar.gz: ea5d24152928832e48c56e6406cb89b70928b30e94247afe10c5a2c4cac9a005b1271d8878953b99b951b606adf065c812c2525c92eecc2c933aef7d28341a20
6
+ metadata.gz: 0011170b68b8d86def142ac90396720bae4174ec8a72a31f9648e896b681f09e8b97b12c9fa5c2570167862c896ec23408a5a00e1820875096cb22dc5dfc2458
7
+ data.tar.gz: 7d6d9cf957b5c7b13e76b642416781138b390c70bd27feb5ad66e32d5d56622a965d174b0870ef64f773ce42d599297a4a33c107182abc8af57ebf1a2d9f724c
data/README.md CHANGED
@@ -18,13 +18,22 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- `rake doc:api [CODES_PATH=app/controllers/api] [OUT_FORMAT=simple_html|detailed_html]`
21
+ `rake doc:api [opts=xxx]`
22
22
 
23
- __代码注释格式:__
23
+ __参数说明:__
24
24
 
25
- ```
25
+ * CODES_PATH
26
+ 指定生成代码路径,默认为app/controllers/api
27
+ * OUT_FORMAT
28
+ simple_html 或者 detailed_html, 默认使用detailed_html 模板
29
+ * SHOW_BASE
30
+ 是否为*BaseController结尾的controller生成文档,默认为false
26
31
 
27
- # About: 文件说明
32
+ __代码注释格式:__
33
+ d
34
+
35
+ # 文件说明
36
+ # About: xxxx
28
37
  # Host: 定义api host
29
38
  # Other: ...
30
39
  class Api::UsersController < class Api::BaseController
@@ -74,19 +83,22 @@ __代码注释格式:__
74
83
 
75
84
  __总的来说,注释格式有三种__
76
85
 
77
- 1.
86
+ 1. 只一层
87
+
78
88
  ```
79
89
  # 层级1: 说明
80
90
  ```
81
91
 
82
- 2.
92
+ 2. 两层
93
+
83
94
  ```
84
95
  # 层级1:
85
96
  # 层级2: 说明
86
97
  # 层级2: 说明
87
98
  ```
88
99
 
89
- 3.
100
+ 3. 超过两层
101
+
90
102
  ```
91
103
  # 层级1:
92
104
  # 层级2: 说明
@@ -108,6 +120,13 @@ __总的来说,注释格式有三种__
108
120
 
109
121
 
110
122
 
123
+ ## 注意
124
+ 为加强文档规范化,以下情况的controller将不再生成显示出来:
125
+
126
+ 1. 当前Controller没有文件说明
127
+ 2. 当前controller的actions数量为0
128
+ 3. 当前action没有Return说明
129
+
111
130
  ## Contributing
112
131
 
113
132
  1. Fork it
@@ -8,6 +8,7 @@ module ApiDocGeneration; module FormatFile; class << self
8
8
  klass = class_name.safe_constantize
9
9
  filelines = File.readlines(path)
10
10
  actions = klass.action_methods - klass.superclass.action_methods
11
+ ctrl_about = get_controller_about(filelines, klass.to_s)
11
12
 
12
13
  actions = actions.map do |action|
13
14
  method = klass.instance_method action
@@ -16,7 +17,13 @@ module ApiDocGeneration; module FormatFile; class << self
16
17
  note = FormatNote.analyze(filelines, line - 2)
17
18
  note["Level"] ||= ''
18
19
  note['Name'] = action.to_s
19
- note = get_routes(klass, action).merge(note) unless note['Path']
20
+
21
+ unless note['Path']
22
+ note = get_routes(klass, action).merge(note)
23
+ else
24
+ note['Path'] = note['Path'][0]['desc']
25
+ note['Method'] = note['Method'][0]['desc'] rescue nil
26
+ end
20
27
 
21
28
  note
22
29
  end
@@ -25,11 +32,10 @@ module ApiDocGeneration; module FormatFile; class << self
25
32
  val['Return'].nil?
26
33
  end
27
34
 
28
-
29
35
  {
30
36
  'Path' => path,
31
37
  'Klass' => klass.to_s,
32
- 'About' => get_controller_about(filelines, klass.to_s),
38
+ 'About' => ctrl_about,
33
39
  'Actions' => actions
34
40
  }
35
41
  end
@@ -7,13 +7,17 @@ require 'api_doc_generation/format_note'
7
7
  module ApiDocGeneration; class Generation
8
8
  attr_reader :controller_documents
9
9
 
10
- def initialize(codes_path = nil, title = '')
10
+ def initialize(codes_path = nil, title = '', opts = {})
11
11
  codes_path ||= File.expand_path('app/controllers/api', Rails.root)
12
12
  @controller_documents = []
13
13
  @title = title
14
+ @opts = opts
14
15
 
15
16
  each_api_controllers_file(codes_path) do |path|
16
- @controller_documents << FormatFile.analyze_file(path)
17
+ ctrl_doc = FormatFile.analyze_file(path)
18
+ next if ctrl_doc['About']['Desc'].nil? || ctrl_doc['About']['Desc'].length == 0
19
+ next if ctrl_doc['Actions'].length == 0
20
+ @controller_documents << ctrl_doc
17
21
  end
18
22
  end
19
23
 
@@ -45,7 +49,7 @@ module ApiDocGeneration; class Generation
45
49
  def each_api_controllers_file(codes_path, &block)
46
50
  paths = codes_path.end_with?('.rb') ? [codes_path] : Dir[codes_path + '/**/*.rb']
47
51
  paths.each do |path|
48
- next if path =~ /base_controller.*\.rb$/
52
+ next if path =~ /base_controller.*\.rb$/ && @opts[:show_base] != true
49
53
  block.call path
50
54
  end
51
55
  end
@@ -1,3 +1,3 @@
1
1
  module ApiDocGeneration
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -9,7 +9,9 @@ namespace :doc do
9
9
  title = ENV['TITLE']
10
10
 
11
11
  puts "Template: #{out_format}"
12
- generation = ApiDocGeneration::Generation.new(codes_path, title)
12
+ generation = ApiDocGeneration::Generation.new(codes_path, title, {
13
+ :show_base => ENV['SHOW_BASE'].to_s == 'true' ? true : false
14
+ })
13
15
 
14
16
  puts generation.controller_documents if ENV['SHOW_DOCS']
15
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_doc_generation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jiangzhi.xie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-23 00:00:00.000000000 Z
11
+ date: 2013-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler