rain-doc 0.0.4 → 0.0.5

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: 2ac2daf49d1502a2f8042be98b8bcf2f0a8c285f
4
- data.tar.gz: 55fa316386cf105a6c5fe59b0deac896e0e27156
3
+ metadata.gz: 760f009f7d9d3a776da4498ff735ac00c1f806d1
4
+ data.tar.gz: 8a4b8da84914e4ac4be50a986a05fb77112beae0
5
5
  SHA512:
6
- metadata.gz: 45a73cb660db67b8a21a012dbf1c05e32d70d853ddbdf4ec805e9c4600e0ccce561e309605c9cbabb55b74f37e86e19bdf81b5dd97a44258c5f789d75de72994
7
- data.tar.gz: 90634848c3256aa1261a72e234f7df6216d0c4bafa9a77b8618b04be8f2bcc9104d9e20f8f8c2f3e0ca6d09c5b82c9ad8ea37e33347e081b0e48803699b093df
6
+ metadata.gz: 0b42e4e5eb24008efe96f6953decd4d6aed4930a5c590f966c265676ab09005ead820eaada555d3df4a830431e59e28cb5faf52867c211e349a2689251c875d3
7
+ data.tar.gz: f22e1e5e95284334181893eaed71dc1eae88413a27db44af9523e4ce623664541437bfee7103f8072e36699c2d6d62606c9db15494efd6efaa560b17d32e601b
data/lib/doc.rb CHANGED
@@ -12,6 +12,7 @@ module Rain
12
12
  attr_accessor :parser, :type, :parts, :current_part, :lines, :title,
13
13
  :file_name, :file_contents, :file_ext
14
14
 
15
+ @@open_header = nil
15
16
  @@open_response = nil
16
17
  @@open_response_id = nil
17
18
  @@open_param = nil
@@ -108,6 +109,14 @@ module Rain
108
109
  else
109
110
  @@open_response = nil
110
111
  end
112
+ when :header
113
+
114
+ # open the current header tag using the code as a key
115
+ if result[:open]
116
+ @@open_header = result[:name]
117
+ else
118
+ @@open_header = nil
119
+ end
111
120
  when :param
112
121
 
113
122
  # open the current param tag using the name as the key
@@ -126,6 +135,8 @@ module Rain
126
135
  self.current_part.append_response(@@open_response.to_i, @@open_response_id, result[:text])
127
136
  elsif !@@open_param.nil?
128
137
  self.current_part.append_param(@@open_param, result[:text], @@open_param_type, @@open_param_default)
138
+ elsif !@@open_header.nil?
139
+ self.current_part.append_header(@@open_header, result[:text])
129
140
  else
130
141
  self.current_part.append_doc(result[:text])
131
142
  end
@@ -139,7 +150,7 @@ module Rain
139
150
 
140
151
  # remove any empty parts or parts without method signatures (for ruby docs)
141
152
  if self.type == :RUBY
142
- self.parts = self.parts.select{ |part| part.route != "//" || !part.signature.nil? }
153
+ self.parts = self.parts.select{ |part| !part.route.nil? || !part.signature.nil? }
143
154
  end
144
155
  end
145
156
 
@@ -8,7 +8,7 @@ module Rain
8
8
  def initialize
9
9
  self.responses = []
10
10
  self.doc = []
11
- self.route = '//'
11
+ self.route = nil
12
12
  self.params = []
13
13
  self.headers = []
14
14
  end
@@ -95,12 +95,26 @@ module Rain
95
95
  # adds a parameter with the specified type. also sets a
96
96
  # default value if specified
97
97
  def append_param(name, description, type, default = nil)
98
- self.params << {
99
- name: name,
100
- text: description,
101
- type: type,
102
- default: default
103
- }
98
+
99
+ # try and find the current param by name
100
+ current_param = self.params.select { |param| param[:name] == name }.first
101
+
102
+ # add new param if one doesn't exist
103
+ if current_param.nil?
104
+ self.params << {
105
+ name: name,
106
+ text: description,
107
+ type: type,
108
+ default: default
109
+ }
110
+ else
111
+ # otherwise append to the current param
112
+ self.params.each do |param|
113
+ if param[:name] == name
114
+ param[:text] << description
115
+ end
116
+ end
117
+ end
104
118
  end
105
119
 
106
120
  # gets a parameter by name. will return nil if
@@ -112,10 +126,23 @@ module Rain
112
126
  # adds a http header with name and
113
127
  # description of the header
114
128
  def append_header(name, description)
115
- self.headers << {
116
- name: name,
117
- text: description
118
- }
129
+
130
+ # try and find the current header by name
131
+ current_header = self.headers.select { |header| header[:name] == name }.first
132
+
133
+ if current_header.nil?
134
+ self.headers << {
135
+ name: name,
136
+ text: description
137
+ }
138
+ else
139
+ # otherwise append to the current header
140
+ self.headers.each do |header|
141
+ if header[:name] == name
142
+ header[:text] << description
143
+ end
144
+ end
145
+ end
119
146
  end
120
147
 
121
148
  # gets a header's description from the store
@@ -4,6 +4,7 @@ module Rain
4
4
 
5
5
  @@title_regex = /{title (.*?)}/m
6
6
  @@route_regex = /{route (.*?)}/m
7
+ @@header_regex = /{header (.*?)}/m
7
8
  @@response_regex = /{response (.*?) (.*?)}/m
8
9
  @@param_regex = /{param (.*?) (.*?)}/m
9
10
  @@param_regex_default = /{param (.*?) (.*?) (.*?)}/m
@@ -86,6 +87,17 @@ module Rain
86
87
  }
87
88
  end
88
89
 
90
+ # param tag. must determine whether to open the tag
91
+ # for extra docs or close it
92
+ if is_header?(line)
93
+ open = line.start_with?('{/header') ? false : true
94
+ return {
95
+ tag: :header,
96
+ name: extract_header_name(line),
97
+ open: open
98
+ }
99
+ end
100
+
89
101
  # return method signature if found
90
102
  if parse_signatures
91
103
  if line.start_with?('def ', 'class ', 'get "', "get '", 'put "', "put '", 'post "', "post '", 'delete "', "delete '")
@@ -173,5 +185,13 @@ module Rain
173
185
  def extract_param_default(line)
174
186
  line[@@param_regex_default, 3]
175
187
  end
188
+
189
+ def is_header?(line)
190
+ line.start_with?('{header') || line.start_with?('{/header')
191
+ end
192
+
193
+ def extract_header_name(line)
194
+ line[@@header_regex, 1]
195
+ end
176
196
  end
177
197
  end
@@ -36,6 +36,25 @@
36
36
  </table>
37
37
  <% end %>
38
38
 
39
+ <!-- show all of the headers in a table -->
40
+ <% if part[:headers].length > 0 %>
41
+ <h4>Headers</h4>
42
+ <table class="u-full-width">
43
+ <thead>
44
+ <tr>
45
+ <th>Name</th>
46
+ <th>Description</th>
47
+ </tr>
48
+ </thead>
49
+ <% part[:headers].each do |param| %>
50
+ <tr>
51
+ <td><%= param[:name] %></td>
52
+ <td><%= param[:text] %></td>
53
+ </tr>
54
+ <% end %>
55
+ </table>
56
+ <% end %>
57
+
39
58
  <!-- show all of the responses with examples -->
40
59
  <% if part[:responses].length > 0 %>
41
60
  <h4>Response Examples</h4>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rain-doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Brennan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-18 00:00:00.000000000 Z
11
+ date: 2014-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec