yard-docco 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/README.md +84 -0
- data/Rakefile +13 -0
- data/example/annotated_source.rb +252 -0
- data/lib/yard-docco.rb +8 -0
- data/templates/default/fulldoc/html/css/docco.css +37 -0
- data/templates/default/fulldoc/html/js/docco.js +14 -0
- data/templates/default/fulldoc/html/setup.rb +7 -0
- data/templates/default/layout/html/setup.rb +17 -0
- data/templates/default/method_details/html/annotated_source.erb +21 -0
- data/templates/default/method_details/html/setup.rb +130 -0
- data/templates/default/method_details/html/source.erb +10 -0
- data/yard-docco.gemspec +62 -0
- metadata +81 -0
data/History.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
YARD-Docco: Docco style code annotation
|
2
|
+
====================================
|
3
|
+
|
4
|
+
Synopsis
|
5
|
+
--------
|
6
|
+
|
7
|
+
YARD-Docco is a YARD extension that provides an additional source view that
|
8
|
+
will show comments alongside the source code within a method. I recently spent
|
9
|
+
some time learning Backbone.js and really enjoyed the annotated source code that
|
10
|
+
was generated for a large number of the examples and thought that it would be
|
11
|
+
useful to add this view to YARD's existing source view to take advantage of comments
|
12
|
+
made within methods.
|
13
|
+
|
14
|
+
Examples
|
15
|
+
--------
|
16
|
+
|
17
|
+
I have created a trivial, example project to help provide a quick
|
18
|
+
visualization of the resulting documentation.
|
19
|
+
|
20
|
+
The implemented example has been deployed at [http://recursivegames.com/yard-docco](http://recursivegames.com/yard-docco).
|
21
|
+
|
22
|
+
**1. Comments made within methods appear alongside the code they are attempting to describe.
|
23
|
+
|
24
|
+
**2. YARD tags (e.g. @note, @todo) and links will appear as they do for methods and classes.
|
25
|
+
|
26
|
+
Installation
|
27
|
+
------------
|
28
|
+
|
29
|
+
YARD-Docco requires the following gems installed:
|
30
|
+
|
31
|
+
YARD 0.7.0 - http://yardoc.org
|
32
|
+
|
33
|
+
To install `yard-docco` use the following command:
|
34
|
+
|
35
|
+
$ gem install yard-docco
|
36
|
+
|
37
|
+
(Add `sudo` if you're installing under a POSIX system as root)
|
38
|
+
|
39
|
+
Usage
|
40
|
+
-----
|
41
|
+
|
42
|
+
YARD supports for automatically including gems with the prefix `yard-`
|
43
|
+
as a plugin. To enable automatic loading yard-docco.
|
44
|
+
|
45
|
+
$ yard config load_plugins true
|
46
|
+
$ yardoc 'example/**/*.rb'
|
47
|
+
|
48
|
+
Now you can run YARD as you [normally](https://github.com/lsegal/yard) would and
|
49
|
+
have your features, step definitions and transforms captured.
|
50
|
+
|
51
|
+
An example with the rake task:
|
52
|
+
|
53
|
+
require 'yard'
|
54
|
+
|
55
|
+
YARD::Rake::YardocTask.new do |t|
|
56
|
+
t.files = ['lib/**/*.rb', 'app/**/*.rb']
|
57
|
+
t.options = ['--any', '--extra', '--opts'] # optional
|
58
|
+
end
|
59
|
+
|
60
|
+
LICENSE
|
61
|
+
-------
|
62
|
+
|
63
|
+
(The MIT License)
|
64
|
+
|
65
|
+
Copyright (c) 2011 Franklin Webber
|
66
|
+
|
67
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
68
|
+
a copy of this software and associated documentation files (the
|
69
|
+
'Software'), to deal in the Software without restriction, including
|
70
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
71
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
72
|
+
permit persons to whom the Software is furnished to do so, subject to
|
73
|
+
the following conditions:
|
74
|
+
|
75
|
+
The above copyright notice and this permission notice shall be
|
76
|
+
included in all copies or substantial portions of the Software.
|
77
|
+
|
78
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
79
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
80
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
81
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
82
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
83
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
84
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,252 @@
|
|
1
|
+
class Example
|
2
|
+
|
3
|
+
def to_s
|
4
|
+
|
5
|
+
# Comments at the start of will be collected with the comments below and
|
6
|
+
# all notes and todos will be above even this.
|
7
|
+
# @note that I want to tell you something
|
8
|
+
# @todo this is a todo
|
9
|
+
# This sentence was below the @note and the @todo but will appear with the
|
10
|
+
# other sentences below them.
|
11
|
+
self.to_s.capitalize
|
12
|
+
|
13
|
+
# Some comments at the end that should get included as well
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# Create an xml representation of the specified class based on defined
|
19
|
+
# HappyMapper elements and attributes. The method is defined in a way
|
20
|
+
# that it can be called recursively by classes that are also HappyMapper
|
21
|
+
# classes, allowg for the composition of classes.
|
22
|
+
#
|
23
|
+
# @param [Nokogiri::XML::Builder] builder an instance of the XML builder which
|
24
|
+
# is being used when called recursively.
|
25
|
+
# @param [String] default_namespace the name of the namespace which is the
|
26
|
+
# default for the xml being produced; this is specified by the element
|
27
|
+
# declaration when calling #to_xml recursively.
|
28
|
+
#
|
29
|
+
# @return [String,Nokogiri::XML::Builder] return XML representation of the
|
30
|
+
# HappyMapper object; when called recursively this is going to return
|
31
|
+
# and Nokogiri::XML::Builder object.
|
32
|
+
#
|
33
|
+
def to_xml(builder = nil,default_namespace = nil)
|
34
|
+
|
35
|
+
#
|
36
|
+
# If {#to_xml} has been called without a passed in builder instance that
|
37
|
+
# means we are going to return xml output. When it has been called with
|
38
|
+
# a builder instance that means we most likely being called recursively
|
39
|
+
# and will return the end product as a builder instance.
|
40
|
+
#
|
41
|
+
unless builder
|
42
|
+
write_out_to_xml = true
|
43
|
+
builder = Nokogiri::XML::Builder.new
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Find the attributes for the class and collect them into an array
|
48
|
+
# that will be placed into a Hash structure
|
49
|
+
#
|
50
|
+
attributes = self.class.attributes.collect do |attribute|
|
51
|
+
|
52
|
+
#
|
53
|
+
# If an attribute is marked as read_only then we want to ignore the attribute
|
54
|
+
# when it comes to saving the xml document; so we wiill not go into any of
|
55
|
+
# the below process
|
56
|
+
#
|
57
|
+
unless attribute.options[:read_only]
|
58
|
+
|
59
|
+
value = send(attribute.method_name)
|
60
|
+
|
61
|
+
#
|
62
|
+
# If the attribute defines an on_save lambda/proc or value that maps to
|
63
|
+
# a method that the class has defined, then call it with the value as a
|
64
|
+
# parameter.
|
65
|
+
#
|
66
|
+
if on_save_action = attribute.options[:on_save]
|
67
|
+
if on_save_action.is_a?(Proc)
|
68
|
+
value = on_save_action.call(value)
|
69
|
+
elsif respond_to?(on_save_action)
|
70
|
+
value = send(on_save_action,value)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Attributes that have a nil value should be ignored unless they explicitly
|
76
|
+
# state that they should be expressed in the output.
|
77
|
+
#
|
78
|
+
if value || attribute.options[:state_when_nil]
|
79
|
+
attribute_namespace = attribute.options[:namespace] || default_namespace
|
80
|
+
[ "#{attribute_namespace ? "#{attribute_namespace}:" : ""}#{attribute.tag}", value ]
|
81
|
+
else
|
82
|
+
[]
|
83
|
+
end
|
84
|
+
|
85
|
+
else
|
86
|
+
[]
|
87
|
+
end
|
88
|
+
|
89
|
+
end.flatten
|
90
|
+
|
91
|
+
attributes = Hash[ *attributes ]
|
92
|
+
|
93
|
+
#
|
94
|
+
# Create a tag in the builder that matches the class's tag name and append
|
95
|
+
# any attributes to the element that were defined above.
|
96
|
+
#
|
97
|
+
builder.send(self.class.tag_name,attributes) do |xml|
|
98
|
+
|
99
|
+
#
|
100
|
+
# Add all the registered namespaces to the root element.
|
101
|
+
# When this is called recurisvely by composed classes the namespaces
|
102
|
+
# are still added to the root element
|
103
|
+
#
|
104
|
+
# However, we do not want to add the namespace if the namespace is 'xmlns'
|
105
|
+
# which means that it is the default namesapce of the code.
|
106
|
+
#
|
107
|
+
if self.class.instance_variable_get('@registered_namespaces') && builder.doc.root
|
108
|
+
self.class.instance_variable_get('@registered_namespaces').each_pair do |name,href|
|
109
|
+
name = nil if name == "xmlns"
|
110
|
+
builder.doc.root.add_namespace(name,href)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
#
|
115
|
+
# If the object we are persisting has a namespace declaration we will want
|
116
|
+
# to use that namespace or we will use the default namespace.
|
117
|
+
# When neither are specifed we are simply using whatever is default to the
|
118
|
+
# builder
|
119
|
+
#
|
120
|
+
if self.class.respond_to?(:namespace) && self.class.namespace
|
121
|
+
xml.parent.namespace = builder.doc.root.namespace_definitions.find do |x|
|
122
|
+
x.prefix == self.class.namespace
|
123
|
+
end
|
124
|
+
elsif default_namespace
|
125
|
+
xml.parent.namespace = builder.doc.root.namespace_definitions.find do |x|
|
126
|
+
x.prefix == default_namespace
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
#
|
132
|
+
# When a text_node has been defined we add the resulting value
|
133
|
+
# the output xml
|
134
|
+
#
|
135
|
+
if text_node = self.class.instance_variable_get('@text_node')
|
136
|
+
|
137
|
+
unless text_node.options[:read_only]
|
138
|
+
text_accessor = text_node.tag || text_node.name
|
139
|
+
value = send(text_accessor)
|
140
|
+
|
141
|
+
if on_save_action = text_node.options[:on_save]
|
142
|
+
if on_save_action.is_a?(Proc)
|
143
|
+
value = on_save_action.call(value)
|
144
|
+
elsif respond_to?(on_save_action)
|
145
|
+
value = send(on_save_action,value)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
builder.text(value)
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
#
|
155
|
+
# for every define element (i.e. has_one, has_many, element) we are
|
156
|
+
# going to persist each one
|
157
|
+
#
|
158
|
+
self.class.elements.each do |element|
|
159
|
+
|
160
|
+
#
|
161
|
+
# If an element is marked as read only do not consider at all when
|
162
|
+
# saving to XML.
|
163
|
+
#
|
164
|
+
unless element.options[:read_only]
|
165
|
+
|
166
|
+
tag = element.tag || element.name
|
167
|
+
|
168
|
+
#
|
169
|
+
# The value to store is the result of the method call to the element,
|
170
|
+
# by default this is simply utilizing the attr_accessor defined. However,
|
171
|
+
# this allows for this method to be overridden
|
172
|
+
#
|
173
|
+
value = send(element.name)
|
174
|
+
|
175
|
+
#
|
176
|
+
# If the element defines an on_save lambda/proc then we will call that
|
177
|
+
# operation on the specified value. This allows for operations to be
|
178
|
+
# performed to convert the value to a specific value to be saved to the xml.
|
179
|
+
#
|
180
|
+
if on_save_action = element.options[:on_save]
|
181
|
+
if on_save_action.is_a?(Proc)
|
182
|
+
value = on_save_action.call(value)
|
183
|
+
elsif respond_to?(on_save_action)
|
184
|
+
value = send(on_save_action,value)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
# Normally a nil value would be ignored, however if specified then
|
189
|
+
# an empty element will be written to the xml
|
190
|
+
#
|
191
|
+
if value.nil? && element.options[:single] && element.options[:state_when_nil]
|
192
|
+
xml.send(tag,"")
|
193
|
+
end
|
194
|
+
|
195
|
+
#
|
196
|
+
# To allow for us to treat both groups of items and singular items
|
197
|
+
# equally we wrap the value and treat it as an array.
|
198
|
+
#
|
199
|
+
if value.nil?
|
200
|
+
values = []
|
201
|
+
elsif value.respond_to?(:to_ary) && !element.options[:single]
|
202
|
+
values = value.to_ary
|
203
|
+
else
|
204
|
+
values = [value]
|
205
|
+
end
|
206
|
+
|
207
|
+
values.each do |item|
|
208
|
+
|
209
|
+
if item.is_a?(HappyMapper)
|
210
|
+
|
211
|
+
#
|
212
|
+
# Other items are convertable to xml through the xml builder
|
213
|
+
# process should have their contents retrieved and attached
|
214
|
+
# to the builder structure
|
215
|
+
#
|
216
|
+
item.to_xml(xml,element.options[:namespace])
|
217
|
+
|
218
|
+
elsif item
|
219
|
+
|
220
|
+
item_namespace = element.options[:namespace] || default_namespace
|
221
|
+
|
222
|
+
#
|
223
|
+
# When a value exists we should append the value for the tag
|
224
|
+
#
|
225
|
+
if item_namespace
|
226
|
+
xml[item_namespace].send(tag,item.to_s)
|
227
|
+
else
|
228
|
+
xml.send(tag,item.to_s)
|
229
|
+
end
|
230
|
+
|
231
|
+
else
|
232
|
+
|
233
|
+
#
|
234
|
+
# Normally a nil value would be ignored, however if specified then
|
235
|
+
# an empty element will be written to the xml
|
236
|
+
#
|
237
|
+
xml.send(tag,"") if element.options[:state_when_nil]
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|
247
|
+
|
248
|
+
write_out_to_xml ? builder.to_xml : builder
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
data/lib/yard-docco.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
module DoccoInTheYARD
|
2
|
+
VERSION = '1.0.0'
|
3
|
+
end
|
4
|
+
|
5
|
+
YARD::Templates::Engine.register_template_path File.dirname(__FILE__) + '/../templates'
|
6
|
+
|
7
|
+
# The following static paths and templates are for yard server
|
8
|
+
YARD::Server.register_static_path File.dirname(__FILE__) + "/../templates/default/fulldoc/html"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
.annotated_source_code {
|
3
|
+
display: none;
|
4
|
+
border-collapse:collapse;
|
5
|
+
}
|
6
|
+
|
7
|
+
/* Within the annotated source section the docstring should have a much smaller
|
8
|
+
right margin so that the description text will be closer to the center line */
|
9
|
+
.annotated_source_code * div.docstring { margin-right: 20px; }
|
10
|
+
|
11
|
+
/* For the comment column set a minimum/max width and change the fonts to look
|
12
|
+
like the nice font and size used by docco comments. Docco examples I have
|
13
|
+
seen use 450px, I'm going a little smaller here to allow more to appear on
|
14
|
+
screen. */
|
15
|
+
.annotated_source_code * td.comment {
|
16
|
+
width: 400px; min-width: 400px;
|
17
|
+
padding: 10px 0px 0px 10px;
|
18
|
+
vertical-align: text-top;
|
19
|
+
font-family: Palatino Linotype; font-size: 15px;
|
20
|
+
}
|
21
|
+
|
22
|
+
/* Give the line numbers a nice gutter that will site between the comments and
|
23
|
+
the code. */
|
24
|
+
.annotated_source_code * td.line-numbers {
|
25
|
+
background-color: #DDD;
|
26
|
+
vertical-align: text-top;
|
27
|
+
padding-left: 8px;
|
28
|
+
padding-right: 8px;
|
29
|
+
}
|
30
|
+
|
31
|
+
.annotated_source_code * td.code {
|
32
|
+
background-color: #F5F5FF;
|
33
|
+
padding-left: 10px;
|
34
|
+
padding-right: 10px;
|
35
|
+
width: 100%;
|
36
|
+
vertical-align: text-top;
|
37
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
function createAnnotatedSourceLinks() {
|
2
|
+
$('.method_details_list .annotated_source_code').
|
3
|
+
before("<span class='showSource'>[<a href='#' class='annotatedToggleSource'>View annotated source</a>]</span>");
|
4
|
+
$('.annotatedToggleSource').toggle(function() {
|
5
|
+
$(this).parent().next().slideDown(100);
|
6
|
+
$(this).text("Hide annotated source");
|
7
|
+
},
|
8
|
+
function() {
|
9
|
+
$(this).parent().next().slideUp(100);
|
10
|
+
$(this).text("View annotated source");
|
11
|
+
});
|
12
|
+
}
|
13
|
+
|
14
|
+
$(createAnnotatedSourceLinks);
|
@@ -0,0 +1,17 @@
|
|
1
|
+
def init
|
2
|
+
super
|
3
|
+
end
|
4
|
+
|
5
|
+
#
|
6
|
+
# Append yard-docco stylesheet to yard core stylesheets
|
7
|
+
#
|
8
|
+
def stylesheets
|
9
|
+
super + %w(css/docco.css)
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# Append yard-docco javascript to yard core javascripts
|
14
|
+
#
|
15
|
+
def javascripts
|
16
|
+
super + %w(js/docco.js)
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<table class="annotated_source_code">
|
2
|
+
<tr>
|
3
|
+
<td colspan="3" style="padding-left: 10px;">
|
4
|
+
<pre class="code"><span class="info file"># File '<%= h object.file %>'<% if object.line %>, line <%= object.line %><% end %></span></pre>
|
5
|
+
</td>
|
6
|
+
</tr>
|
7
|
+
<% object.annotated_source.each do |source| %>
|
8
|
+
<tr>
|
9
|
+
<td class="comment">
|
10
|
+
<span><%= docstring_comment Array(source.first).join("\n") %>
|
11
|
+
</td>
|
12
|
+
<td class="line-numbers">
|
13
|
+
<pre class="lines" style="padding-right: 0px;"><%= h show_annotated_lines(source) %></pre>
|
14
|
+
</td>
|
15
|
+
<td class="code">
|
16
|
+
<pre class="code"><span class="info file"><%= html_syntax_highlight Array(source.last).join("\n") %></pre>
|
17
|
+
</td>
|
18
|
+
</tr>
|
19
|
+
<% end %>
|
20
|
+
|
21
|
+
</table>
|
@@ -0,0 +1,130 @@
|
|
1
|
+
def init
|
2
|
+
super
|
3
|
+
|
4
|
+
# Added the annotated source template to the end of the sections to be rendered.
|
5
|
+
sections.push(:annotated_source)
|
6
|
+
|
7
|
+
# object contains the method details that are about to be processed.
|
8
|
+
#
|
9
|
+
# object.source contains all the source within the method that we can use
|
10
|
+
# to generate the inline documentation. We should allow for the normal sour
|
11
|
+
#
|
12
|
+
# Source with annotations would simply look at the source and each line with
|
13
|
+
# a comment would be lumped together with comments.
|
14
|
+
object.annotated_source = annotate_source(object.source)
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# The comments within a method are just strings and have not been converted into
|
20
|
+
# Docstrings. Here we hijack the method object and send it to the docstring
|
21
|
+
# template to be rendered with the new docstring.
|
22
|
+
#
|
23
|
+
# @param [String] comments that should be converted into a docstring and then
|
24
|
+
# rendered with the docstring template.
|
25
|
+
# @return [String] the rendered results of the docstring
|
26
|
+
def docstring_comment(comments)
|
27
|
+
method_object = object.dup
|
28
|
+
object.docstring = Docstring.new(comments,object)
|
29
|
+
|
30
|
+
result = T('docstring').run(options)
|
31
|
+
object = method_object
|
32
|
+
result
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# This method will find the comments and then the source code (non-comments) and
|
37
|
+
# generate an array of comment-code pairs which should be displayed next to each
|
38
|
+
# other.
|
39
|
+
#
|
40
|
+
# @param [String] source that will be scanned and annotated
|
41
|
+
#
|
42
|
+
# @return [Array<Array<String,String>>] an array of arrays. Each element contains
|
43
|
+
# in the first element the comments, the second contains the source code.
|
44
|
+
def annotate_source(source)
|
45
|
+
|
46
|
+
annotated = []
|
47
|
+
current_comment = nil
|
48
|
+
current_code = nil
|
49
|
+
finished_comment = nil
|
50
|
+
|
51
|
+
# Move through the source code line by line.
|
52
|
+
# When we come to a comment line (starts with #) then we add a source
|
53
|
+
# When we come to a non-comment line we are done builing that comment
|
54
|
+
# we would then start to build the source up line by line
|
55
|
+
source.split("\n").each do |line|
|
56
|
+
|
57
|
+
if line =~ /^\s*#.*$/
|
58
|
+
|
59
|
+
# When parsing a comment
|
60
|
+
#
|
61
|
+
# If we are parsing the first comment then we need to look to see if there
|
62
|
+
# was some code that we were parsing and finish that code. Then we need to
|
63
|
+
# add the comment to a new array of comments
|
64
|
+
#
|
65
|
+
# If this is another comment, after the first one then we need to add it
|
66
|
+
# to the list of comments.
|
67
|
+
if current_comment
|
68
|
+
current_comment << line[/^\s*#\s?(.+)/,1].to_s
|
69
|
+
else
|
70
|
+
|
71
|
+
if current_code
|
72
|
+
annotated << [ finished_comment, current_code ]
|
73
|
+
finished_comment = current_code = nil
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
(current_comment ||=[]) << line[/^\s*#\s?(.+)/,1].to_s
|
78
|
+
end
|
79
|
+
|
80
|
+
else
|
81
|
+
|
82
|
+
# When parsing a line of code
|
83
|
+
#
|
84
|
+
# If we are parsing the first line of code then if there are any comments
|
85
|
+
# then we are done with the comments that are associated with this line of
|
86
|
+
# code (and any lines that follow). We want to save the finished block of
|
87
|
+
# comments so that we can put it together with the code when we are finished
|
88
|
+
# with it.
|
89
|
+
#
|
90
|
+
if current_comment
|
91
|
+
finished_comment = current_comment
|
92
|
+
current_comment = nil
|
93
|
+
else
|
94
|
+
# We were not working on a comment
|
95
|
+
end
|
96
|
+
|
97
|
+
# Add the current code line to the current_code if one exists (create one if it does not exist)
|
98
|
+
(current_code ||= []) << line.to_s
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
# If we have finished parsing lines and we still have code within a home, which
|
105
|
+
# is likely if the the source code ends with an end. We want to create a new pair
|
106
|
+
if current_code
|
107
|
+
annotated << [ finished_comment.to_s, current_code ]
|
108
|
+
current_code = nil
|
109
|
+
end
|
110
|
+
|
111
|
+
# If we have a comment that still remains, then the comment exists without
|
112
|
+
# source and we should add it the pairs.
|
113
|
+
if current_comment
|
114
|
+
annotated << [ current_comment, "" ]
|
115
|
+
current_comment = nil
|
116
|
+
end
|
117
|
+
|
118
|
+
return annotated
|
119
|
+
end
|
120
|
+
|
121
|
+
def show_annotated_lines(section)
|
122
|
+
@current_count ||= object.line
|
123
|
+
|
124
|
+
# Add the comment line length to the line number
|
125
|
+
@current_count += Array(section.first).length
|
126
|
+
|
127
|
+
lines = (@current_count..(@current_count+Array(section.last).length)).to_a.join("\n")
|
128
|
+
@current_count += Array(section.last).length
|
129
|
+
lines
|
130
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<table class="source_code">
|
2
|
+
<tr>
|
3
|
+
<td>
|
4
|
+
<pre class="lines"><%= "\n\n\n" %><%= h format_lines(object) %></pre>
|
5
|
+
</td>
|
6
|
+
<td>
|
7
|
+
<pre class="code"><span class="info file"># File '<%= h object.file %>'<% if object.line %>, line <%= object.line %><% end %></span><%= "\n\n" %><%= html_syntax_highlight object.source %></pre>
|
8
|
+
</td>
|
9
|
+
</tr>
|
10
|
+
</table>
|
data/yard-docco.gemspec
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'YARD'
|
2
|
+
require File.dirname(__FILE__) + "/lib/yard-docco"
|
3
|
+
|
4
|
+
module DoccoInTheYARD
|
5
|
+
def self.show_version_changes(version)
|
6
|
+
date = ""
|
7
|
+
changes = []
|
8
|
+
grab_changes = false
|
9
|
+
|
10
|
+
File.open("#{File.dirname(__FILE__)}/History.txt",'r') do |file|
|
11
|
+
while (line = file.gets) do
|
12
|
+
|
13
|
+
if line =~ /^===\s*#{version.gsub('.','\.')}\s*\/\s*(.+)\s*$/
|
14
|
+
grab_changes = true
|
15
|
+
date = $1.strip
|
16
|
+
elsif line =~ /^===\s*.+$/
|
17
|
+
grab_changes = false
|
18
|
+
elsif grab_changes
|
19
|
+
changes = changes << line
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
{ :date => date, :changes => changes }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Gem::Specification.new do |s|
|
30
|
+
s.name = 'yard-docco'
|
31
|
+
s.version = ::DoccoInTheYARD::VERSION
|
32
|
+
s.authors = ["Franklin Webber"]
|
33
|
+
s.description = %{
|
34
|
+
YARD-Docco is a YARD extension that provides an additional source view that
|
35
|
+
will show comments alongside the source code within a method. }
|
36
|
+
s.summary = "Docco style documentation within methods"
|
37
|
+
s.email = 'franklin.webber@gmail.com'
|
38
|
+
s.homepage = "http://github.com/burtlo/yard-docco"
|
39
|
+
|
40
|
+
s.platform = Gem::Platform::RUBY
|
41
|
+
|
42
|
+
changes = DoccoInTheYARD.show_version_changes(::DoccoInTheYARD::VERSION)
|
43
|
+
|
44
|
+
s.post_install_message = %{
|
45
|
+
(==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==)
|
46
|
+
|
47
|
+
Thank you for installing yard-docco #{::DoccoInTheYARD::VERSION} / #{changes[:date]}.
|
48
|
+
|
49
|
+
Changes:
|
50
|
+
#{changes[:changes].collect{|change| " #{change}"}.join("")}
|
51
|
+
(==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==)
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
s.add_dependency 'yard', '>= 0.7.0'
|
56
|
+
|
57
|
+
s.rubygems_version = "1.3.7"
|
58
|
+
s.files = `git ls-files`.split("\n")
|
59
|
+
s.extra_rdoc_files = ["README.md", "History.txt"]
|
60
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
61
|
+
s.require_path = "lib"
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yard-docco
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Franklin Webber
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-31 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: yard
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.7.0
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
description: " \n YARD-Docco is a YARD extension that provides an additional source view that\n will show comments alongside the source code within a method. "
|
28
|
+
email: franklin.webber@gmail.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files:
|
34
|
+
- README.md
|
35
|
+
- History.txt
|
36
|
+
files:
|
37
|
+
- History.txt
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- example/annotated_source.rb
|
41
|
+
- lib/yard-docco.rb
|
42
|
+
- templates/default/fulldoc/html/css/docco.css
|
43
|
+
- templates/default/fulldoc/html/js/docco.js
|
44
|
+
- templates/default/fulldoc/html/setup.rb
|
45
|
+
- templates/default/layout/html/setup.rb
|
46
|
+
- templates/default/method_details/html/annotated_source.erb
|
47
|
+
- templates/default/method_details/html/setup.rb
|
48
|
+
- templates/default/method_details/html/source.erb
|
49
|
+
- yard-docco.gemspec
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/burtlo/yard-docco
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message: "\n\
|
55
|
+
(==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==)\n\n Thank you for installing yard-docco 1.0.0 / 2011-07-31.\n \n Changes:\n \n * Initial Release\n\
|
56
|
+
(==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==) (==)\n\n"
|
57
|
+
rdoc_options:
|
58
|
+
- --charset=UTF-8
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.6.2
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Docco style documentation within methods
|
80
|
+
test_files: []
|
81
|
+
|