rapi_doc 0.2.2 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,7 +13,7 @@ Installation
13
13
  Usage
14
14
  =====
15
15
 
16
- Run `rake rapi_doc` to generate config and layout files. (TODO: Add a separate rake task to generate config files)
16
+ Run `rake rapi_doc:setup` to generate config and layout files.
17
17
 
18
18
  Modify config file by adding your controllers, e.g.:
19
19
 
@@ -23,7 +23,7 @@ Modify config file by adding your controllers, e.g.:
23
23
 
24
24
  Then invoke the generation by calling:
25
25
 
26
- `rake rapi_doc`
26
+ `rake rapi_doc:generate`
27
27
 
28
28
  Documentation Example
29
29
  ---------------------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.3.1
data/lib/doc_parser.rb CHANGED
@@ -10,9 +10,9 @@ module RapiDoc
10
10
  @in_class = false
11
11
  end
12
12
 
13
- def start
13
+ def start(order)
14
14
  @current_scope = !in_class ? :class : :function
15
- @current_api_block = MethodDoc.new(current_scope)
15
+ @current_api_block = MethodDoc.new(current_scope, order)
16
16
  end
17
17
 
18
18
  def reset_current_scope_and_api_block
data/lib/method_doc.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  module RapiDoc
2
2
  # This class holds methods about a doc.
3
3
  class MethodDoc
4
- attr_accessor :scope, :content, :request, :response, :code, :outputs, :variables
4
+ attr_accessor :scope, :content, :request, :response, :code, :outputs, :variables, :method_order
5
5
 
6
- def initialize(type)
6
+ def initialize(type, order)
7
7
  @scope = type
8
+ @method_order = order
8
9
  @variables = []
9
10
  @outputs = []
10
11
  @content = ""
data/lib/rapi_config.rb CHANGED
@@ -18,6 +18,18 @@ module RapiDoc
18
18
  File.join(find_location(location), 'layout.html.erb')
19
19
  end
20
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
+
21
33
  def find_location(location)
22
34
  location == :target ? config_dir : template_dir
23
35
  end
data/lib/rapi_doc.rb CHANGED
@@ -34,16 +34,20 @@ module RapiDoc
34
34
  # generate the index file for the api views
35
35
  def generate_index!
36
36
  template = ""
37
- @page_type = 'index'
38
- File.open(layout_file(:target)).each { |line| template << line }
37
+ @page_type2 = 'dudul'
38
+ File.open(class_layout_file(:target)).each { |line| template << line }
39
39
  parsed = ERB.new(template).result(binding)
40
- File.open(File.join(temp_dir, "index.html"), 'w') { |file| file.write parsed }
40
+ File.open(File.join(temp_dir, "class.html"), 'w') { |file| file.write parsed }
41
41
  end
42
42
 
43
43
  def move_structure!
44
44
  target_folder = "#{::Rails.root.to_s}/public/apidoc/"
45
45
  Dir.mkdir(target_folder) if (!File.directory?(target_folder))
46
46
 
47
+ # Copy the frameset & main files
48
+ FileUtils.cp frameset_file(:target), target_folder + 'index.html'
49
+ FileUtils.cp main_file(:target), target_folder + 'main.html'
50
+
47
51
  Dir.new(temp_dir).each do |d|
48
52
  if d =~ /^[a-zA-Z]+\.(html|css)$/ # Only want to copy over the .html files, not the .erb templates
49
53
  FileUtils.cp File.join(temp_dir + d), target_folder + d
@@ -8,7 +8,7 @@ namespace :rapi_doc do
8
8
  else
9
9
  FileUtils.mkdir(config_dir)
10
10
  end
11
- %w(config_file layout_file).each do |type_file|
11
+ %w(config_file layout_file class_layout_file frameset_file main_file).each do |type_file|
12
12
  target_file = send(type_file, :target)
13
13
  template_file = send(type_file, :template)
14
14
  if File.exist? target_file
data/lib/resource_doc.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'method_doc'
2
3
  require 'doc_parser'
3
4
 
@@ -8,7 +9,7 @@ module RapiDoc
8
9
 
9
10
  attr_reader :name, :resource_location, :controller_name, :function_blocks, :class_block
10
11
 
11
- # Initializes RAPIDoc.
12
+ # Initializes ResourceDoc.
12
13
  def initialize(name, resource_location, controller_name, options = {})
13
14
  @name = name
14
15
  @standard_methods = options[:standard_methods] || [:put, :post, :get, :delete]
@@ -37,10 +38,11 @@ module RapiDoc
37
38
  line_no = 0
38
39
 
39
40
  parser = DocParser.new
41
+ order = 1
40
42
  File.open(controller_location).each do |line|
41
43
  case
42
44
  when line =~ /=begin apidoc/
43
- parser.start
45
+ parser.start(order)
44
46
  when line =~ /=end/
45
47
  if parser.current_api_block.nil?
46
48
  puts "#{controller_location}:#{line_no} - No starttag for '=end' found"
@@ -53,6 +55,7 @@ module RapiDoc
53
55
  @function_blocks << parser.current_api_block
54
56
  end
55
57
  parser.reset_current_scope_and_api_block
58
+ order += 1
56
59
  end
57
60
  when line =~ /class/
58
61
  parser.in_class = true
@@ -71,8 +74,10 @@ module RapiDoc
71
74
  def generate_view!(resources, temp_dir)
72
75
  @resources = resources
73
76
  @header_code = get_parsed_header unless @class_block.nil?
77
+ i = 1
74
78
  function_blocks.each do |mb|
75
- @method_codes << get_parsed_method(mb)
79
+ @method_codes << get_parsed_method(mb, i)
80
+ i += 1
76
81
  end
77
82
  # write it to a file
78
83
  template = ""
@@ -87,7 +92,7 @@ module RapiDoc
87
92
  ERB.new(template).result(@class_block.get_binding)
88
93
  end
89
94
 
90
- def get_parsed_method(method_block)
95
+ def get_parsed_method(method_block, method_order)
91
96
  template = ""
92
97
  File.open(File.join(File.dirname(__FILE__), '..', 'templates', '_resource_method.html.erb')).each { |line| template << line }
93
98
  return ERB.new(template).result(method_block.get_binding)
@@ -1,4 +1,4 @@
1
- <div id="method">
1
+ <div id="method_<%=@method_order%>">
2
2
 
3
3
  <%
4
4
  splitted = @method
@@ -29,13 +29,13 @@
29
29
  <% unless @outputs.empty? %>
30
30
  <ul class="tabs">
31
31
  <% @outputs.each do |output| %>
32
- <li class="<%= (output == @outputs.first)? 'active' : '' %>"><a href="#<%= output.keys.first %>"><%= output.keys.first %></a></li>
32
+ <li class="<%= (output == @outputs.first)? 'active' : '' %>"><a href='#<%= "#{output.keys.first}_#{@method_order}" %>'><%= output.keys.first %></a></li>
33
33
  <% end %>
34
34
  </ul>
35
35
  <div class="pill-content">
36
36
  <% @outputs.each do |output| %>
37
37
  <% output_format = output.keys.first %>
38
- <div class="<%= (output == @outputs.first)? 'active' : '' %>" id="<%= output_format %>">
38
+ <div class="<%= (output == @outputs.first)? 'active' : '' %>" id='<%= "#{output.keys.first}_#{@method_order}" %>'>
39
39
  <pre class="prettyprint" ><%= output[output_format] %></pre>
40
40
  </div>
41
41
  <% end %>
@@ -0,0 +1,36 @@
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>
@@ -0,0 +1,11 @@
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>
@@ -51,36 +51,19 @@
51
51
  </head>
52
52
  <body>
53
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>
54
59
 
55
- <% if @page_type == 'index' %>
56
- <div id="introduction">
57
- <!-- documentation intro -->
58
- </div>
60
+ <hr />
59
61
 
60
- <h2>Resources</h2>
61
- <div id="resources">
62
- <ul>
63
- <% @resources.each do |r| %>
64
- <li>Resource: <a href="/apidoc/<%=r.name %>.html"><%=r.resource_location %></a></li>
65
- <% end %>
66
- </ul>
67
- </div>
68
- <% else %>
69
- <div id="navigation">
70
- <ul class="main">
71
- <li><a href="/apidoc/index.html">&laquo; Back to index</a></li>
72
- </ul>
73
- </div>
62
+ <%=@header_code %>
74
63
 
75
- <hr />
76
-
77
- <%=@header_code %>
78
-
79
- <% @method_codes.each do |mc| %>
80
- <%=mc %>
81
- <% end %>
64
+ <% @method_codes.each do |mc| %>
65
+ <%=mc %>
82
66
  <% end %>
83
-
84
67
  </div>
85
68
  </body>
86
69
  </html>
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ </head>
6
+ <body>
7
+ <div class="content">
8
+ <h1>API Doc</h1>
9
+ <div>
10
+
11
+ </div>
12
+
13
+ </div>
14
+ </body>
15
+ </html>
metadata CHANGED
@@ -1,83 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rapi_doc
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
4
5
  prerelease:
5
- version: 0.2.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Husein Choroomi
9
9
  - Adinda Praditya
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-12-09 00:00:00 Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
13
+ date: 2012-02-17 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: activesupport
18
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &70302725893440 !ruby/object:Gem::Requirement
19
18
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "2.1"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '2.1'
24
23
  type: :runtime
25
24
  prerelease: false
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
25
+ version_requirements: *70302725893440
26
+ - !ruby/object:Gem::Dependency
28
27
  name: rspec
29
- requirement: &id002 !ruby/object:Gem::Requirement
28
+ requirement: &70302725892500 !ruby/object:Gem::Requirement
30
29
  none: false
31
- requirements:
30
+ requirements:
32
31
  - - ~>
33
- - !ruby/object:Gem::Version
32
+ - !ruby/object:Gem::Version
34
33
  version: 2.7.0
35
34
  type: :development
36
35
  prerelease: false
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
36
+ version_requirements: *70302725892500
37
+ - !ruby/object:Gem::Dependency
39
38
  name: bundler
40
- requirement: &id003 !ruby/object:Gem::Requirement
39
+ requirement: &70302725891540 !ruby/object:Gem::Requirement
41
40
  none: false
42
- requirements:
41
+ requirements:
43
42
  - - ~>
44
- - !ruby/object:Gem::Version
43
+ - !ruby/object:Gem::Version
45
44
  version: 1.0.0
46
45
  type: :development
47
46
  prerelease: false
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
47
+ version_requirements: *70302725891540
48
+ - !ruby/object:Gem::Dependency
50
49
  name: jeweler
51
- requirement: &id004 !ruby/object:Gem::Requirement
50
+ requirement: &70302725890700 !ruby/object:Gem::Requirement
52
51
  none: false
53
- requirements:
52
+ requirements:
54
53
  - - ~>
55
- - !ruby/object:Gem::Version
54
+ - !ruby/object:Gem::Version
56
55
  version: 1.6.4
57
56
  type: :development
58
57
  prerelease: false
59
- version_requirements: *id004
60
- - !ruby/object:Gem::Dependency
58
+ version_requirements: *70302725890700
59
+ - !ruby/object:Gem::Dependency
61
60
  name: rcov
62
- requirement: &id005 !ruby/object:Gem::Requirement
61
+ requirement: &70302725889940 !ruby/object:Gem::Requirement
63
62
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: "0"
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
68
67
  type: :development
69
68
  prerelease: false
70
- version_requirements: *id005
69
+ version_requirements: *70302725889940
71
70
  description: Rails API Doc Generator
72
71
  email: hchoroomi@gmail.com
73
72
  executables: []
74
-
75
73
  extensions: []
76
-
77
- extra_rdoc_files:
74
+ extra_rdoc_files:
78
75
  - LICENSE.txt
79
76
  - README.md
80
- files:
77
+ files:
81
78
  - .rvmrc
82
79
  - Gemfile
83
80
  - Gemfile.lock
@@ -100,38 +97,38 @@ files:
100
97
  - spec/spec_helper.rb
101
98
  - templates/_resource_header.html.erb
102
99
  - templates/_resource_method.html.erb
100
+ - templates/class_layout.html.erb
103
101
  - templates/config.yml
102
+ - templates/frameset.html.erb
104
103
  - templates/layout.html.erb
104
+ - templates/main.html.erb
105
105
  - uninstall.rb
106
106
  homepage: http://github.com/elc/rapi_doc
107
- licenses:
107
+ licenses:
108
108
  - MIT
109
109
  post_install_message:
110
110
  rdoc_options: []
111
-
112
- require_paths:
111
+ require_paths:
113
112
  - lib
114
- required_ruby_version: !ruby/object:Gem::Requirement
113
+ required_ruby_version: !ruby/object:Gem::Requirement
115
114
  none: false
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- hash: -1093643544274794326
120
- segments:
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ segments:
121
120
  - 0
122
- version: "0"
123
- required_rubygems_version: !ruby/object:Gem::Requirement
121
+ hash: -4532277263417640116
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
123
  none: false
125
- requirements:
126
- - - ">="
127
- - !ruby/object:Gem::Version
128
- version: "0"
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
129
128
  requirements: []
130
-
131
129
  rubyforge_project:
132
- rubygems_version: 1.8.6
130
+ rubygems_version: 1.8.10
133
131
  signing_key:
134
132
  specification_version: 3
135
133
  summary: Rails API Doc Generator
136
134
  test_files: []
137
-