rapi_doc 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/doc_parser.rb DELETED
@@ -1,53 +0,0 @@
1
- module RapiDoc
2
- # This class holds the methods that parse the doc
3
- class DocParser
4
- attr_accessor :current_api_block, :current_scope, :line_no, :in_class
5
-
6
- def initialize
7
- @current_api_block = nil
8
- @current_scope = :none
9
- @line_no = 0
10
- @in_class = false
11
- end
12
-
13
- def start(order)
14
- @current_scope = !in_class ? :class : :function
15
- @current_api_block = MethodDoc.new(current_scope, order)
16
- end
17
-
18
- def reset_current_scope_and_api_block
19
- @current_api_block = nil
20
- @current_scope = :none
21
- end
22
-
23
- def parse(line)
24
- case current_scope
25
- when :response
26
- @current_api_block.response += strip_line(line)
27
- when :request
28
- @current_api_block.request += strip_line(line)
29
- when :output
30
- @current_api_block.append_output strip_line(line)
31
- when :class, :function
32
- if result = /(\w+)\:\:\s*(.+)/.match(line)
33
- if result[1] == "response" || result[1] == "request"
34
- @current_scope = result[1].to_sym
35
- elsif result[1] == "output"
36
- @current_scope = result[1].to_sym
37
- @current_api_block.add_output(result[1], result[2])
38
- else
39
- @current_api_block.add_variable(result[1], result[2])
40
- end
41
- else
42
- # add line to block
43
- @current_api_block.content << strip_line(line)
44
- end
45
- end
46
- end
47
-
48
- # strip the '#' on the line
49
- def strip_line(line)
50
- line[1..line.length]
51
- end
52
- end
53
- end
data/lib/doc_util.rb DELETED
@@ -1,8 +0,0 @@
1
- module RapiDoc
2
- class DocUtil
3
- # print some erb code to a template
4
- def self.print_erb(str, show=false)
5
- (show ? "<%= " : "<% ") + str + " %>"
6
- end
7
- end
8
- end
data/lib/method_doc.rb DELETED
@@ -1,44 +0,0 @@
1
- module RapiDoc
2
- # This class holds methods about a doc.
3
- class MethodDoc
4
- attr_accessor :scope, :content, :request, :response, :code, :outputs, :variables, :method_order
5
-
6
- def initialize(type, order)
7
- @scope = type
8
- @method_order = order
9
- @variables = []
10
- @outputs = []
11
- @content = ""
12
- @code = ""
13
- @request = ""
14
- @response = ""
15
- end
16
-
17
-
18
- def add_variable(name, value)
19
- if name == "param"
20
- @variables << value
21
- return
22
- end
23
-
24
- eval("@#{name}= \"#{value}\"")
25
- self.class.class_eval { attr_accessor name.to_sym }
26
- end
27
-
28
- def add_output(name, value)
29
- if name == 'output'
30
- @outputs << eval("{#{value}: ''}")
31
- return
32
- end
33
- end
34
-
35
- def append_output(value)
36
- last_output_key = @outputs.last.keys[0]
37
- @outputs.last[last_output_key] += ERB::Util.html_escape(value)
38
- end
39
-
40
- def get_binding
41
- binding
42
- end
43
- end
44
- end
data/lib/rapi_config.rb DELETED
@@ -1,37 +0,0 @@
1
- module RapiDoc
2
- module RapiConfig
3
- BASE_DIR = 'config/rapi_doc'
4
-
5
- def config_dir
6
- File.join(::Rails.root.to_s, BASE_DIR)
7
- end
8
-
9
- def template_dir
10
- File.join(File.dirname(__FILE__), '/../templates')
11
- end
12
-
13
- def config_file(location)
14
- File.join(find_location(location), 'config.yml')
15
- end
16
-
17
- def layout_file(location)
18
- File.join(find_location(location), 'layout.html.erb')
19
- end
20
-
21
- def class_layout_file(location)
22
- File.join(find_location(location), 'class_layout.html.erb')
23
- end
24
-
25
- def frameset_file(location)
26
- File.join(find_location(location), 'frameset.html.erb')
27
- end
28
-
29
- def main_file(location)
30
- File.join(find_location(location), 'main.html.erb')
31
- end
32
-
33
- def find_location(location)
34
- location == :target ? config_dir : template_dir
35
- end
36
- end
37
- end
data/lib/resource_doc.rb DELETED
@@ -1,102 +0,0 @@
1
- # encoding: utf-8
2
- require 'method_doc'
3
- require 'doc_parser'
4
-
5
- module RapiDoc
6
- # ResourceDoc holds the information a resource contains. It parses the class header and also the
7
- # method documentation, which will be contained in MethodDoc.
8
- class ResourceDoc
9
-
10
- attr_reader :name, :resource_location, :controller_name, :function_blocks, :class_block
11
-
12
- # Initializes ResourceDoc.
13
- def initialize(name, resource_location, controller_name, options = {})
14
- @name = name
15
- @standard_methods = options[:standard_methods] || [:put, :post, :get, :delete]
16
- @resource_location, @controller_name = resource_location, controller_name
17
- @function_blocks = []
18
- @method_codes = []
19
- @header_code = ""
20
-
21
- unless File.exist?(controller_location)
22
- raise "Unable to find or open controller. Make sure it's set properly in config/rapidoc/config.yml File: #{controller_location}"
23
- end
24
- end
25
-
26
- # returns the location of the controller that is to be parsed
27
- def controller_location
28
- # @resource_location
29
- "#{::Rails.root.to_s}/app/controllers/#{controller_name}"
30
- end
31
-
32
- def get_binding
33
- binding
34
- end
35
-
36
- # parse the controller
37
- def parse_apidoc!
38
- line_no = 0
39
-
40
- parser = DocParser.new
41
- order = 1
42
- File.open(controller_location).each do |line|
43
- case
44
- when line =~ /=begin apidoc/
45
- parser.start(order)
46
- when line =~ /=end/
47
- if parser.current_api_block.nil?
48
- puts "#{controller_location}:#{line_no} - No starttag for '=end' found"
49
- exit
50
- else
51
- case parser.current_scope
52
- when :class
53
- @class_block = parser.current_api_block
54
- when :function
55
- @function_blocks << parser.current_api_block
56
- end
57
- parser.reset_current_scope_and_api_block
58
- order += 1
59
- end
60
- when line =~ /class/
61
- parser.in_class = true
62
- when line =~ /::response-end::/, line =~ /::request-end::/, line =~ /::output-end::/
63
- parser.current_scope = :function
64
- else
65
- parser.parse(line)
66
- end
67
-
68
- line_no += 1
69
- end
70
-
71
- puts "Generated #{name}.html"
72
- end
73
-
74
- def generate_view!(resources, temp_dir)
75
- @resources = resources
76
- @header_code = get_parsed_header unless @class_block.nil?
77
- i = 1
78
- function_blocks.each do |mb|
79
- @method_codes << get_parsed_method(mb, i)
80
- i += 1
81
- end
82
- # write it to a file
83
- template = ""
84
- File.open(layout_file(:target)).each { |line| template << line }
85
- parsed = ERB.new(template).result(binding)
86
- File.open(File.join(temp_dir, name + ".html"), 'w') { |file| file.write parsed }
87
- end
88
-
89
- def get_parsed_header
90
- template = ""
91
- File.open(File.join(File.dirname(__FILE__), '..', 'templates', '_resource_header.html.erb')).each { |line| template << line }
92
- ERB.new(template).result(@class_block.get_binding)
93
- end
94
-
95
- def get_parsed_method(method_block, method_order)
96
- template = ""
97
- File.open(File.join(File.dirname(__FILE__), '..', 'templates', '_resource_method.html.erb')).each { |line| template << line }
98
- return ERB.new(template).result(method_block.get_binding)
99
- end
100
-
101
- end
102
- end
@@ -1,18 +0,0 @@
1
- <h1><%=@name %></h1>
2
- <p class="summary"><%=@content %></p>
3
-
4
- <% if @xml || @json %>
5
- <h2>Representations</h2>
6
-
7
- <% if @json %>
8
- <a name="json"></a>
9
- <strong>JSON representation:</strong> <br /><a href="javascript:$('#jsonrep').toggle()">(toggle code)</a><br />
10
- <textarea style="width:100%;height:200px;display:none;" id="jsonrep"><%=@json %></textarea><br />
11
- <% end %>
12
-
13
- <% if @xml %>
14
- <a name="xml"></a>
15
- <strong>XML representation:</strong> <br /><a href="javascript:$('#xmlrep').toggle()">(toggle code)</a><br/>
16
- <textarea style="width:100%;height:200px;display:none;" id="xmlrep"><%=@xml %></textarea>
17
- <% end %>
18
- <% end %>
@@ -1,56 +0,0 @@
1
- <div id="method_<%=@method_order%>">
2
-
3
- <%
4
- splitted = @method
5
- str = @method
6
- str = "<span id='http_verb'>#{str}</span>"
7
- %>
8
- <p class='description'><strong>Description:</strong> <%=@content %></p>
9
-
10
- <h2><%=str %><%=@url %></h2>
11
-
12
- <% if @access %>
13
- <strong>Access:</strong> <%=@access %><br />
14
- <% end %>
15
-
16
- <% if @return %>
17
- <strong>Return:</strong>
18
- <%=@return %>
19
- <br />
20
- <% end %>
21
-
22
- <% if @variables %>
23
- <strong>Parameters:</strong>
24
- <ul>
25
- <% @variables.each do |v| %><li><%=v %></li><% end %>
26
- </ul>
27
- <% end %>
28
-
29
- <% unless @outputs.empty? %>
30
- <ul class="tabs">
31
- <% @outputs.each do |output| %>
32
- <li class="<%= (output == @outputs.first)? 'active' : '' %>"><a href='#<%= "#{output.keys.first}_#{@method_order}" %>'><%= output.keys.first %></a></li>
33
- <% end %>
34
- </ul>
35
- <div class="pill-content">
36
- <% @outputs.each do |output| %>
37
- <% output_format = output.keys.first %>
38
- <div class="<%= (output == @outputs.first)? 'active' : '' %>" id='<%= "#{output.keys.first}_#{@method_order}" %>'>
39
- <pre class="prettyprint" ><%= output[output_format] %></pre>
40
- </div>
41
- <% end %>
42
- </div>
43
- <br />
44
- <% end %>
45
-
46
- <% unless @request.blank? %>
47
- <strong>Request:</strong>
48
- <pre class="code"><code><%= @request %></code></pre>
49
- <% end %>
50
-
51
- <% unless @response.blank? %>
52
- <strong>Response:</strong>
53
- <pre class="code"><code><%= @response %></code></pre>
54
- <% end %>
55
-
56
- </div>
@@ -1,36 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
- <title><%= @name || 'Home' %></title>
6
- <base id="base_target"></base>
7
- </head>
8
- <body>
9
- <script type="text/javascript" charset="utf-8">
10
- if (window.top.frames.main) {
11
- document.getElementById('base_target').target = 'main';
12
- document.body.className = 'frames'
13
- }
14
- </script>
15
- <div class="content">
16
- <h2>Resources</h2>
17
- <div id="resources_<%=@page_type2%>">
18
- <ul>
19
- <% @resources.each do |r| %>
20
- <li>
21
- Resource: <a href="/apidoc/<%=r.name %>.html"><%=r.resource_location %></a>
22
- <% if r.function_blocks.any? %>
23
- <ul>
24
- <% r.function_blocks.each do |method_block| %>
25
- <li><a href="/apidoc/<%=r.name %>.html#method_<%=method_block.method_order%>"><%= method_block.url %></a></li>
26
- <% end %>
27
- </ul>
28
- <% end %>
29
- </li>
30
- <% end %>
31
- </ul>
32
- </div>
33
-
34
- </div>
35
- </body>
36
- </html>
data/templates/config.yml DELETED
@@ -1,3 +0,0 @@
1
- #users:
2
- # location: "/users"
3
- # controller_name: "users_controller.rb"
@@ -1,11 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
- <title>Home</title>
6
- </head>
7
- <frameset cols="20%,*">
8
- <frame name="list" src="/apidoc/class.html"></frame>
9
- <frame name="main" src="/apidoc/main.html"></frame>
10
- </frameset>
11
- </html>
@@ -1,69 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
- <title><%= @name || 'Home' %></title>
6
-
7
- <style>
8
- body {
9
- line-height: 1.5em;
10
- color:#484848;
11
- }
12
-
13
- ul, ol {
14
- margin-bottom: 0.8em;
15
- }
16
-
17
- li {
18
- padding-left: 10px;
19
- margin-right: 10px;
20
- }
21
-
22
- #resources {
23
-
24
- }
25
-
26
- h1, h2, h3 {
27
- padding-top: 8px;
28
- padding-bottom: 2px;
29
- }
30
-
31
- #method {
32
- padding: 15px 30px;
33
- border-top:1px solid #ddd;
34
- }
35
-
36
- #http_verb {
37
- color:#ff6600;
38
- width:200px;
39
- margin-right:20px;'
40
- }
41
-
42
- .description{
43
- font-size: 1.4em;
44
- color:#262626;
45
- }
46
- .code {
47
- font-family: monospace;
48
- }
49
- </style>
50
-
51
- </head>
52
- <body>
53
- <div class="content">
54
- <div id="navigation">
55
- <ul class="main">
56
- <li><a href="/apidoc/main.html">&laquo; Back to index</a></li>
57
- </ul>
58
- </div>
59
-
60
- <hr />
61
-
62
- <%=@header_code %>
63
-
64
- <% @method_codes.each do |mc| %>
65
- <%=mc %>
66
- <% end %>
67
- </div>
68
- </body>
69
- </html>