api_doc_generation 0.2.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3c631601be29797aa6e14707a92b515fa6b68be
4
- data.tar.gz: 942cee388e1db6bfd6cd96672e2e7c51a5b9db2c
3
+ metadata.gz: 81d519ebc01140cc7b74d66069a3b6eb3f8a07c7
4
+ data.tar.gz: 47b6f328b09fc166044e4236ee927890d8527691
5
5
  SHA512:
6
- metadata.gz: c12bf362dc163eb5f8c3befc5dca58a17494ae0ff5928520f23698d07feec8f759fb6ee4124aa406c24e729009bb6ef3ba7a3f6713131d05206de5b922f944f8
7
- data.tar.gz: 83f02c76a07a1f33291cdfd9e4d391d36c9d2b60b8a2f1053de8f71c769dc3b05deb2cf8c7c542a55eea62d220a8b81793c45fdd1244b441260482a73a148384
6
+ metadata.gz: 06f370284d952468cf80dd44eeb0854264310913aacc96a7a9b80dd7d3dd755331252fe83906968320ce34662743a38b669704064fa9f5ce9f0dcfbbc0d6f800
7
+ data.tar.gz: ea5d24152928832e48c56e6406cb89b70928b30e94247afe10c5a2c4cac9a005b1271d8878953b99b951b606adf065c812c2525c92eecc2c933aef7d28341a20
data/README.md CHANGED
@@ -72,6 +72,31 @@ __代码注释格式:__
72
72
 
73
73
  上面已经给出了api说明,参数,返回,错误信息,而api地址和请求方法将会自动从Rails中查找出来
74
74
 
75
+ __总的来说,注释格式有三种__
76
+
77
+ 1.
78
+ ```
79
+ # 层级1: 说明
80
+ ```
81
+
82
+ 2.
83
+ ```
84
+ # 层级1:
85
+ # 层级2: 说明
86
+ # 层级2: 说明
87
+ ```
88
+
89
+ 3.
90
+ ```
91
+ # 层级1:
92
+ # 层级2: 说明
93
+ # 层级3
94
+ # 更多的层级,这些层级只会显示在层级2中,等于就是层级2的说明
95
+ # 字段2: 说明
96
+ ```
97
+
98
+
99
+ 上面的格式可以任意组合,要注意的是,解析时层级是按 (空格 / 2)来计算的
75
100
 
76
101
  ## Level
77
102
  * 默认level显示所有
@@ -12,13 +12,20 @@ module ApiDocGeneration; module FormatFile; class << self
12
12
  actions = actions.map do |action|
13
13
  method = klass.instance_method action
14
14
  filepath, line = method.source_location
15
+
15
16
  note = FormatNote.analyze(filelines, line - 2)
16
17
  note["Level"] ||= ''
17
18
  note['Name'] = action.to_s
18
19
  note = get_routes(klass, action).merge(note) unless note['Path']
20
+
19
21
  note
20
22
  end
21
23
 
24
+ actions.delete_if do |val|
25
+ val['Return'].nil?
26
+ end
27
+
28
+
22
29
  {
23
30
  'Path' => path,
24
31
  'Klass' => klass.to_s,
@@ -33,7 +40,7 @@ module ApiDocGeneration; module FormatFile; class << self
33
40
  def get_controller_about(filelines, class_name)
34
41
  filelines.each_with_index do |line, line_number|
35
42
  next if line =~ /^\s*(\#.*)?$/
36
-
43
+
37
44
  doc = FormatNote.analyze(filelines, line_number -1)
38
45
 
39
46
  doc.delete_if {|key, v| key =~ /encoding/ }
@@ -71,7 +78,7 @@ module ApiDocGeneration; module FormatFile; class << self
71
78
  require 'rails/application/route_inspector'
72
79
  inspector = Rails::Application::RouteInspector.new
73
80
 
74
- inspector.collect_routes(all_routes) +
75
- inspector.instance_variable_get(:@engines).flatten
81
+ inspector.collect_routes(all_routes) +
82
+ inspector.instance_variable_get(:@engines).values.flatten
76
83
  end
77
84
  end; end; end
@@ -43,8 +43,8 @@ module ApiDocGeneration; class Generation
43
43
 
44
44
  # API_CONTROLLERS_DIR = File.expand_path('app/controllers/api/**/*.rb', Rails.root)
45
45
  def each_api_controllers_file(codes_path, &block)
46
-
47
- Dir[codes_path + '/**/*.rb'].each do |path|
46
+ paths = codes_path.end_with?('.rb') ? [codes_path] : Dir[codes_path + '/**/*.rb']
47
+ paths.each do |path|
48
48
  next if path =~ /base_controller.*\.rb$/
49
49
  block.call path
50
50
  end
@@ -1,3 +1,3 @@
1
1
  module ApiDocGeneration
2
- VERSION = "0.2.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -31,7 +31,9 @@ module ApiDocGeneration; class ViewHelper
31
31
  ################## View Helper ###################
32
32
 
33
33
  def render(path, opts = {})
34
- file_path = File.expand_path("templates/_#{path}.html.erb", ROOT_PATH)
34
+ path = "templates/_#{path}.*.erb"
35
+ file_path = Dir[File.expand_path(path, ROOT_PATH)].first
36
+ raise "no found file '#{path}'" unless file_path
35
37
 
36
38
  template = ERB.new(File.read(file_path))
37
39
 
@@ -0,0 +1,58 @@
1
+ $(function(){
2
+ var no_print_class = 'no_print';
3
+ var iframe = $('.helper_iframe')[0];
4
+ var idoc = iframe.contentDocument;
5
+
6
+
7
+ // 设置勾选内容的打印及显示
8
+ // 添加或移除no_print类
9
+ $('.print_selector').change(function(event){
10
+ var $this = $(this);
11
+ var $a = $this.next();
12
+ var $top = $a.parent();
13
+ var $target_el = $($a.attr('href'));
14
+
15
+ if ($this.is(":checked")) {
16
+ $top.removeClass(no_print_class)
17
+ $target_el.removeClass(no_print_class);
18
+ } else {
19
+ $top.addClass(no_print_class)
20
+ $target_el.addClass(no_print_class);
21
+ }
22
+ });
23
+
24
+
25
+ // 下载保存勾选的内容
26
+ $("a.save_to_file").click(function(event){
27
+ var head = document.head.innerHTML;
28
+ idoc.body.innerHTML = document.body.innerHTML;
29
+
30
+ $(idoc.body).find("." + no_print_class).remove();
31
+
32
+ var html = '<html><head>';
33
+ html += head + '</head><body>';
34
+ html += idoc.body.innerHTML + '</body></html>';
35
+
36
+ window.open('data:application/octet-stream;charset=utf-8,' + encodeURIComponent(html));
37
+ return false;
38
+ });
39
+
40
+
41
+ // 合并文档
42
+ $("#merge_doc").change(function(event){
43
+ var fr = new FileReader();
44
+
45
+ fr.onloadend = function(e){
46
+ var $body = $(document.body);
47
+ idoc.write(this.result);
48
+
49
+ var menus = $(idoc.body).find(".list>ul>li");
50
+ var controllers = $(idoc.body).find(".controller");
51
+
52
+ $body.find(".list>ul").append(menus);
53
+ $body.append(controllers);
54
+ }
55
+
56
+ fr.readAsText(this.files[0]);
57
+ });
58
+ });
@@ -1,5 +1,14 @@
1
1
  <div class='list'>
2
- <strong class='no_print no_opacity about'>* 被勾选的内容将被打印</strong>
2
+ <strong class='no_print no_opacity about'>* 被勾选的内容才会被打印、保存</strong>
3
+
4
+ <div class='helpers'>
5
+ <label for='merge_doc' class='btn no_print no_opacity'>合并文档...</label>
6
+ <input type='file' id='merge_doc' style='display:none'/>
7
+
8
+ <a href='#' class='no_print no_opacity btn save_to_file'>保存到新文件</a>
9
+
10
+ <iframe class='helper_iframe' style='display:none'></iframe>
11
+ </div>
3
12
 
4
13
  <ul>
5
14
  <% @documents.each do |controller| %>
@@ -0,0 +1,45 @@
1
+ .title {
2
+ text-align: center;
3
+ color: blank;
4
+ }
5
+
6
+ .controller, .list {
7
+ width: 900px;
8
+ border: 1px solid;
9
+ margin: 20px auto 40 auto;
10
+ }
11
+
12
+ .list {
13
+ padding-top: 20px;
14
+ }
15
+
16
+ .list .helpers {
17
+ padding: 20px;
18
+ }
19
+
20
+ .controller-title {
21
+ text-align: center;
22
+ }
23
+
24
+ .action {
25
+ margin-top: 40px;
26
+ padding: 20px 40px 20px 20px;
27
+ }
28
+
29
+ .about {
30
+ padding-left: 20px;
31
+ }
32
+
33
+ .no_print {
34
+ opacity: 0.4;
35
+ }
36
+
37
+ .no_opacity {
38
+ opacity: 1;
39
+ }
40
+
41
+ @media print {
42
+ .no_print {
43
+ display: none;
44
+ }
45
+ }
@@ -5,71 +5,10 @@
5
5
  <title><%= @title %></title>
6
6
 
7
7
  <link href='http://libs.baidu.com/bootstrap/2.3.2/css/bootstrap.css' rel='stylesheet'>
8
- <style type='text/css'>
9
- .title {
10
- text-align: center;
11
- color: blank;
12
- }
13
-
14
- .controller, .list {
15
- width: 900px;
16
- border: 1px solid;
17
- margin: 20px auto 40 auto;
18
- }
19
-
20
- .list {
21
- padding-top: 20px;
22
- }
23
-
24
- .controller-title {
25
- text-align: center;
26
- }
27
-
28
- .action {
29
- margin-top: 40px;
30
- padding: 20px 40px 20px 20px;
31
- }
32
-
33
- .about {
34
- padding-left: 20px;
35
- }
36
-
37
- .no_print {
38
- opacity: 0.4;
39
- }
40
-
41
- .no_opacity {
42
- opacity: 1;
43
- }
44
-
45
- @media print {
46
- .no_print {
47
- display: none;
48
- }
49
- }
50
- </style>
8
+ <style type='text/css'><%= render 'style' %></style>
51
9
 
52
10
  <script type='text/javascript' src='http://code.jquery.com/jquery-2.0.3.min.js'></script>
53
- <script type='text/javascript'>
54
- $(function(){
55
- var no_print_class = 'no_print';
56
-
57
- $('.print_selector').change(function(event){
58
- var $this = $(this);
59
- var $a = $this.next();
60
- var $top = $a.parent();
61
- var $target_el = $($a.attr('href'));
62
-
63
- if ($this.is(":checked")) {
64
- $top.removeClass(no_print_class)
65
- $target_el.removeClass(no_print_class);
66
- } else {
67
- $top.addClass(no_print_class)
68
- $target_el.addClass(no_print_class);
69
- }
70
- });
71
- });
72
- </script>
11
+ <script type='text/javascript'><%= render 'javascript' %></script>
73
12
  </head>
74
13
 
75
14
  <body>
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.2.1
4
+ version: 0.4.0
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-03 00:00:00.000000000 Z
11
+ date: 2013-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,8 +60,10 @@ files:
60
60
  - lib/rake/api_doc_generation.rb
61
61
  - lib/rake/tasks/api_doc.rake
62
62
  - templates/_controller.html.erb
63
+ - templates/_javascript.js.erb
63
64
  - templates/_menu.html.erb
64
65
  - templates/_params_table.html.erb
66
+ - templates/_style.css.erb
65
67
  - templates/doc.html.erb
66
68
  - templates/doc_detailed.html.erb
67
69
  homepage: ''