api_doc_generation 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/api_doc_generation/version.rb +1 -1
- data/lib/api_doc_generation/view_helper.rb +27 -0
- data/lib/api_doc_generation.rb +7 -5
- data/templates/doc.html.erb +6 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71a28c541f63c63c6e7c2f272fca44b43e14273f
|
4
|
+
data.tar.gz: 020955f784ca17f2bbe71dd010e87ed8e37a1b7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f01c633f69fa3b9e097ea7f4d196602a8c85e0c92fd023984eeb4036dcac1094e38268617ab942a973873fac3bc4f151daf1950503e1cf96a0c70ba54c63c5af
|
7
|
+
data.tar.gz: 0b5b2dc9495774abd017bc494983bd451c9cde1513786d726136cd0bf6668627871452f4ee9aee3ad69281eebab1b47bc95c394307d49fd0cb5907b1823ced07
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ApiDocGeneration; class ViewHelper
|
4
|
+
def self.render(template, args = {})
|
5
|
+
template.result(self.new(args).obj_binding)
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
# {:a => 1, :b => 2}
|
10
|
+
def initialize(args)
|
11
|
+
args.each do |key, val|
|
12
|
+
self.instance_variable_set("@#{key}", val)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def obj_binding
|
18
|
+
binding
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
################## Helper #######################
|
24
|
+
def action_identifer(controller_name, action_name)
|
25
|
+
"action-#{Digest::MD5.hexdigest(controller_name)}-#{action_name}"
|
26
|
+
end
|
27
|
+
end; end
|
data/lib/api_doc_generation.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
1
3
|
require "api_doc_generation/version"
|
4
|
+
require 'api_doc_generation/view_helper'
|
5
|
+
|
2
6
|
|
3
7
|
if defined? Rake
|
4
8
|
require "rake/api_doc_generation"
|
@@ -145,12 +149,10 @@ module ApiDocGeneration; class Generation
|
|
145
149
|
template = ERB.new(
|
146
150
|
File.read(File.expand_path('../../templates/doc.html.erb', __FILE__))
|
147
151
|
)
|
148
|
-
doc_binding = Object.new.instance_eval do
|
149
|
-
@documents = controller_documents
|
150
|
-
binding
|
151
|
-
end
|
152
152
|
|
153
|
-
@result =
|
153
|
+
@result = ViewHelper.render(template, {
|
154
|
+
:documents => controller_documents
|
155
|
+
})
|
154
156
|
end
|
155
157
|
|
156
158
|
end; end
|
data/templates/doc.html.erb
CHANGED
@@ -67,7 +67,11 @@
|
|
67
67
|
|
68
68
|
<ul class='ul-controller'>
|
69
69
|
<% controller[:actions].each do |action| %>
|
70
|
-
<li
|
70
|
+
<li>
|
71
|
+
<a href='#<%= action_identifer(controller[:klass], action[:name]) %>'>
|
72
|
+
<%= action[:desc] %>
|
73
|
+
</a>
|
74
|
+
</li>
|
71
75
|
<% end %>
|
72
76
|
</ul>
|
73
77
|
|
@@ -82,7 +86,7 @@
|
|
82
86
|
|
83
87
|
<% controller[:actions].each_with_index do |action, i| %>
|
84
88
|
<div class='action action-<%= i % 2 == 0 ? 'even' : 'odd' %>'
|
85
|
-
id='
|
89
|
+
id='<%= action_identifer(controller[:klass], action[:name]) %>'>
|
86
90
|
<strong class='desc-one'><%= action[:desc] %></strong>
|
87
91
|
|
88
92
|
<% action.each do |key, val| %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_doc_generation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jiangzhi.xie
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- api_doc_generation.gemspec
|
54
54
|
- lib/api_doc_generation.rb
|
55
55
|
- lib/api_doc_generation/version.rb
|
56
|
+
- lib/api_doc_generation/view_helper.rb
|
56
57
|
- lib/rake/api_doc_generation.rb
|
57
58
|
- lib/rake/tasks/api_doc.rake
|
58
59
|
- templates/doc.html.erb
|