readme_yard 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/docs/index.html ADDED
@@ -0,0 +1,405 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ File: README
8
+
9
+ &mdash; Documentation by YARD 0.9.37
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
18
+ pathId = "README";
19
+ relpath = '';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="_index.html">Index</a> &raquo;
40
+ <span class="title">File: README</span>
41
+
42
+ </div>
43
+
44
+ <div id="search">
45
+
46
+ <a class="full_list_link" id="class_list_link"
47
+ href="class_list.html">
48
+
49
+ <svg width="24" height="24">
50
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
51
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
52
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
53
+ </svg>
54
+ </a>
55
+
56
+ </div>
57
+ <div class="clear"></div>
58
+ </div>
59
+
60
+ <div id="content"><div id='filecontents'><h1 id="readme-yard-">Readme Yard 🌿</h1>
61
+ <p><a href="https://badge.fury.io/rb/readme_yard"><img src="https://badge.fury.io/rb/readme_yard.svg" alt="Gem Version" /></a></p>
62
+
63
+ <p><strong>Code Version: 0.4.0</strong></p>
64
+
65
+ <p>Build a better README with <a href="https://yardoc.org">YARD</a>
66
+ by generating it straight from the source.</p>
67
+
68
+ <p>This gem aims to minimize the effort needed to keep your
69
+ README, documentation, and source code synced, useful,
70
+ and correct. Among its features, it introduces the @readme tag
71
+ that enables you to embed code comments directly into README sections,
72
+ eliminating redundancy and keeping documentation consistent
73
+ across your codebase and project README.</p>
74
+
75
+ <p>Look at the <a href="https://github.com/mattruzicka/readme_yard/blob/main/README_YARD.md">README_YARD.md</a>
76
+ template for this project to see how it works.
77
+ If you’re reading the README, that means this text is here
78
+ because the custom <code>{@readme ReadmeYard}</code> markdown tag is in
79
+ README_YARD.md and <code>readme build</code> was run at the command line.</p>
80
+
81
+ <hr />
82
+
83
+ <p>⚠️ <strong>Generated file warning</strong> – Edit README_YARD.md, not README.md. Changes to README.md will be lost when running <code>readme build</code>.</p>
84
+
85
+ <p><strong>Future Work</strong>
86
+ - Implement safeguards to prevent accidental edits to README.md
87
+ - Support bidirectional editing through git integration</p>
88
+
89
+ <p><a href="#contributing">PRs are welcome</a> for these improvements.</p>
90
+
91
+ <hr />
92
+
93
+ <h2 id="table-of-contents">Table of Contents</h2>
94
+ <ul>
95
+ <li><a href="#installation">Installation</a></li>
96
+ <li><a href="#getting-started">Getting Started</a></li>
97
+ <li><a href="#command-line-usage">Command Line Usage</a></li>
98
+ <li><a href="#tag-usage">Tag Usage</a></li>
99
+ <li><a href="#readme-tag">Readme Tag</a></li>
100
+ <li><a href="#standalone-tag-usage">Standalone Tag Usage</a></li>
101
+ <li><a href="#example-tag">Example Tag</a></li>
102
+ <li><a href="#contributing">Contributing</a></li>
103
+ <li><a href="https://mattruzicka.github.io/readme_yard/">Documentation</a></li>
104
+ </ul>
105
+
106
+ <hr />
107
+
108
+ <h2 id="installation">Installation</h2>
109
+
110
+ <p>Add <a href="https://rubygems.org/gems/readme_yard">gem “readme_yard”</a> to your Gemfile and run <code>bundle install</code> or install it yourself with: <code>gem install readme_yard</code></p>
111
+
112
+ <p><strong>Note:</strong> As of version 0.3.0, Readme Yard requires Ruby 3.0 or higher.</p>
113
+
114
+ <h2 id="getting-started">Getting Started</h2>
115
+
116
+ <p>Run <code>readme build</code> at the command line. This creates a README_YARD.md file if there isn’t one by copying your existing README.md file.</p>
117
+
118
+ <p>README_YARD.md is the template from which <code>readme build</code> generates the README. Readme Yard adds the ability to embed and reference your source code in your README via README_YARD.md.</p>
119
+
120
+ <p>See <a href="#tag-usage">Tag Usage</a>.</p>
121
+
122
+ <hr />
123
+
124
+ <h2 id="command-line-usage">Command Line Usage</h2>
125
+
126
+ <p><code>readme</code> - Prints command line usage.</p>
127
+
128
+ <p><code>readme build</code> - Reads from README_YARD.md and writes to README.md.</p>
129
+
130
+ <p><code>readme yard</code> - Same as <code>readme build</code> + generates yard docs.</p>
131
+
132
+ <p><code>readme version</code> - Prints the current version of ReadmeYard.</p>
133
+
134
+ <hr />
135
+
136
+ <h2 id="tag-usage">Tag Usage</h2>
137
+
138
+ <p>Readme Yard uses YARD tags and custom markdown tags. YARD tags live inside Ruby source code. The markdown tags live inside README_YARD.md.</p>
139
+
140
+ <p>When the Readme Yard build process encounters a tag in README_YARD.md, it searches the Ruby source code for its YARD tag counterpart, formats the output, and embeds it in the README file.</p>
141
+
142
+ <h3 id="tag-reference-table">Tag Reference Table</h3>
143
+
144
+ <table>
145
+ <thead>
146
+ <tr>
147
+ <th>Tag Type</th>
148
+ <th>YARD Syntax (in source code)</th>
149
+ <th>Markdown Syntax (in README_YARD.md)</th>
150
+ <th>Standalone Tag*</th>
151
+ <th>Purpose</th>
152
+ </tr>
153
+ </thead>
154
+ <tbody>
155
+ <tr>
156
+ <td>Readme</td>
157
+ <td><code>@readme</code></td>
158
+ <td><code>{@readme ObjectPath}</code></td>
159
+ <td>N/A</td>
160
+ <td>General purpose tag to embed content from source code</td>
161
+ </tr>
162
+ <tr>
163
+ <td>Readme (comment)</td>
164
+ <td><code>@readme comment</code></td>
165
+ <td><code>{@readme ObjectPath}</code></td>
166
+ <td><code>{@comment ObjectPath}</code></td>
167
+ <td>Embeds only the comment from source code</td>
168
+ </tr>
169
+ <tr>
170
+ <td>Readme (code)</td>
171
+ <td><code>@readme code</code></td>
172
+ <td><code>{@readme ObjectPath}</code></td>
173
+ <td><code>{@code ObjectPath}</code></td>
174
+ <td>Embeds only code implementation</td>
175
+ </tr>
176
+ <tr>
177
+ <td>Readme (source)</td>
178
+ <td><code>@readme source</code></td>
179
+ <td><code>{@readme ObjectPath}</code></td>
180
+ <td><code>{@source ObjectPath}</code></td>
181
+ <td>Embeds both comments and code</td>
182
+ </tr>
183
+ <tr>
184
+ <td>Readme (value)</td>
185
+ <td><code>@readme value</code></td>
186
+ <td><code>{@readme ObjectPath}</code></td>
187
+ <td><code>{@value ObjectPath}</code></td>
188
+ <td>Embeds a Ruby value as a Ruby code block</td>
189
+ </tr>
190
+ <tr>
191
+ <td>Readme (string)</td>
192
+ <td><code>@readme string</code></td>
193
+ <td><code>{@readme ObjectPath}</code></td>
194
+ <td><code>{@string ObjectPath}</code></td>
195
+ <td>Embeds a Ruby string as normal text</td>
196
+ </tr>
197
+ <tr>
198
+ <td>Example</td>
199
+ <td><code>@example</code></td>
200
+ <td><code>{@example ObjectPath}</code></td>
201
+ <td>N/A</td>
202
+ <td>Embeds example code from YARD @example tags</td>
203
+ </tr>
204
+ </tbody>
205
+ </table>
206
+
207
+ <blockquote>
208
+ <p>*Standalone tags allow embedding content without requiring corresponding YARD tags in source code. See <a href="#standalone-tag-usage">Standalone Tag Usage</a> for details.</p>
209
+ </blockquote>
210
+
211
+ <h3 id="examples">Examples</h3>
212
+
213
+ <p>The next line is a code snippet if you’re looking at the <a href="https://github.com/mattruzicka/readme_yard/blob/main/README.md">README</a> and <code>{@readme ReadmeYard::ExampleTag.hello_world}</code> if you’re looking at <a href="https://github.com/mattruzicka/readme_yard/blob/main/README_YARD.md">README_YARD.md</a>.</p>
214
+
215
+ <p><code>ruby
216
+ #
217
+ # @example
218
+ # ReadmeYard::ExampleTag.hello_world #=&gt; "Hello 🌎 🌍 🌏"
219
+ #
220
+ def hello_world
221
+ "Hello 🌎 🌍 🌏"
222
+ end
223
+ </code></p>
224
+
225
+ <p>The markdown tag tells Readme Yard to parse the <code>@readme</code> tag located above the <code>hello_world</code> class method located in <a href="https://github.com/mattruzicka/readme_yard/blob/main/lib/readme_yard/example_tag.rb">lib/readme_yard/example_tag.rb</a>.</p>
226
+
227
+ <p>To use another “meta” example, <code>{@readme ReadmeYard}</code> is used at the top of this project’s README_YARD.md file to generate the first few sentences of this README. <code>ReadmeYard</code> references the class located in <a href="https://github.com/mattruzicka/readme_yard/blob/main/lib/readme_yard.rb">lib/readme_yard.rb</a>.</p>
228
+
229
+ <p>Last one, <code>{@readme ReadmeYard#command_line_usage}</code> is used to generate the “Command Line Usage” section above from the comments of the <code>command_line_usage</code> instance method located in <a href="https://github.com/mattruzicka/readme_yard/blob/main/lib/readme_yard.rb">lib/readme_yard.rb</a>. This method is extra meta: it returns the result of formatting its own comments as markdown. In this way, the usage instructions in the comments, the README, and as printed at the command line will always be in sync.</p>
230
+
231
+ <hr />
232
+
233
+ <h2 id="readme-tag">Readme Tag</h2>
234
+
235
+ <p><strong>Markdown</strong> syntax: <code>{@readme ObjectPath}</code></p>
236
+
237
+ <p><strong>YARD</strong> syntax: <code>@example &lt;name&gt;</code></p>
238
+
239
+ <p>By default, only the text nested under a @readme tag
240
+ will be embedded in the final output. The default
241
+ embed behavior can be changed through the use of tag names.</p>
242
+
243
+ <h3 id="embed-comments">Embed comments</h3>
244
+
245
+ <p><strong>Usage:</strong></p>
246
+
247
+ <p><code>ruby
248
+ # @readme comment
249
+ </code></p>
250
+
251
+ <p>This example <a href="https://github.com/mattruzicka/readme_yard/blob/main/lib/readme_yard/comment_tag.rb">@readme comment</a> tag embeds the below code snippet via the <code>{@readme ReadmeYard::CommentTag.format_tag}</code> markdown tag.</p>
252
+
253
+ <p><code>ruby
254
+ #
255
+ # This comment is in the README because `@readme comment`
256
+ # is below (in the source code).
257
+ #
258
+ </code></p>
259
+
260
+ <h3 id="embed-ruby-code">Embed Ruby code</h3>
261
+
262
+ <p><strong>Usage:</strong></p>
263
+
264
+ <p><code>ruby
265
+ # @readme code
266
+ </code></p>
267
+
268
+ <p>This example <a href="https://github.com/mattruzicka/readme_yard/blob/main/lib/readme_yard/code_tag.rb">@readme code</a> tag embeds the below code snippet via the <code>{@readme ReadmeYard::CodeTag.format_tag}</code> markdown tag.</p>
269
+
270
+ <p><code>ruby
271
+ def format_tag(yard_object, _tag)
272
+ ExampleTag.format_ruby(yard_object.source)
273
+ end
274
+ </code></p>
275
+
276
+ <h3 id="embed-ruby-comments-and-code">Embed Ruby comments and code</h3>
277
+
278
+ <p><strong>Usage:</strong></p>
279
+
280
+ <p><code>ruby
281
+ # @readme source
282
+ </code></p>
283
+
284
+ <p>This example <a href="https://github.com/mattruzicka/readme_yard/blob/main/lib/readme_yard/source_tag.rb">@readme source</a> tag embeds the below code snippet via the <code>{@readme ReadmeYard::SourceTag.format_tag}</code> markdown tag.</p>
285
+
286
+ <p><code>ruby
287
+ #
288
+ # The comment and code for ReadmeYard::SourceTag#format_tag
289
+ # is in the README because `@readme source` is below (in the source code).
290
+ #
291
+ def format_tag(yard_object, _tag)
292
+ text = CommentTag.format_docstring_as_comment(yard_object)
293
+ text &lt;&lt; "\n#{yard_object.source}"
294
+ ExampleTag.format_ruby(text)
295
+ end
296
+ </code></p>
297
+
298
+ <h3 id="embed-a-ruby-value-as-a-ruby-code-block">Embed a Ruby value as a Ruby code block</h3>
299
+
300
+ <p><strong>Usage:</strong></p>
301
+
302
+ <p><code>ruby
303
+ # @readme value
304
+ </code></p>
305
+
306
+ <p>This example <a href="https://github.com/mattruzicka/readme_yard/blob/main/lib/readme_yard/value_tag.rb">@readme value</a> tag embeds the below code snippet via the <code>{@value ReadmeYard::ValueTag::EXAMPLE}</code> markdown tag.</p>
307
+
308
+ <p><code>ruby
309
+ { key: "value" }.freeze
310
+ </code></p>
311
+
312
+ <h3 id="embed-a-ruby-string-as-normal-text">Embed a Ruby string as normal text</h3>
313
+
314
+ <p><strong>Usage:</strong></p>
315
+
316
+ <p>Because a <a href="https://github.com/mattruzicka/readme_yard/blob/main/lib/readme_yard/string_tag.rb">@readme string</a> tag:</p>
317
+
318
+ <p><code>ruby
319
+ # @readme string
320
+ </code></p>
321
+
322
+ <p>Is located above this constant:</p>
323
+
324
+ <p><code>ruby
325
+ XZAMPLE = &lt;&lt;~STRING
326
+ I heard you like self-documenting Ruby, so I wrote
327
+ self-documenting Ruby for your self-documenting Ruby.
328
+ STRING
329
+ </code></p>
330
+
331
+ <p>We see can see its string value as simple text below:</p>
332
+
333
+ <p>I heard you like self-documenting Ruby, so I wrote
334
+ self-documenting Ruby for your self-documenting Ruby.</p>
335
+
336
+ <hr />
337
+
338
+ <h2 id="standalone-tag-usage">Standalone Tag Usage</h2>
339
+
340
+ <p>While using the <code>@readme</code> tag in your source code is recommended because it makes the README’s dependency on source code explicit, sometimes it’s useful to embed source code snippets directly without it. This is especially valuable when a source object can only contain one <code>@readme</code> tag, but you want to highlight multiple aspects of the object.</p>
341
+
342
+ <p>You can use any of these tags directly in README_YARD.md without requiring a corresponding <code>@readme</code> tag in the source code:</p>
343
+
344
+ <ul>
345
+ <li><code>{@comment ObjectPath}</code> - Embeds comments only</li>
346
+ <li><code>{@code ObjectPath}</code> - Embeds code only</li>
347
+ <li><code>{@source ObjectPath}</code> - Embeds both comments and code</li>
348
+ <li><code>{@value ObjectPath}</code> - Embeds a Ruby value as a Ruby code block</li>
349
+ <li><code>{@string ObjectPath}</code> - Embeds a Ruby string as plain text</li>
350
+ </ul>
351
+
352
+ <p>For example, in the StringTag section above, we used both:
353
+ - <code>{@code ReadmeYard::StringTag::XZAMPLE}</code> to show the constant definition
354
+ - <code>{@string ReadmeYard::StringTag::XZAMPLE}</code> to display the string value as text</p>
355
+
356
+ <p>The standalone tag usage provides more flexibility when documenting your code and doesn’t require modifications to the source files.</p>
357
+
358
+ <hr />
359
+
360
+ <h2 id="example-tag">Example Tag</h2>
361
+
362
+ <p><strong>Markdown</strong> syntax: <code>{@example ObjectPath}</code></p>
363
+
364
+ <p><strong>YARD</strong> syntax: <code>@example</code></p>
365
+
366
+ <p>The Example Tag leverages YARD’s standard <code>@example</code> tag syntax, allowing you to
367
+ include example code in your README directly from source files. This saves time and
368
+ ensures your README stays in sync with your YARD documentation</p>
369
+
370
+ <p><strong>Usage:</strong></p>
371
+
372
+ <p><code>ruby
373
+ #
374
+ # @example
375
+ # ReadmeYard::ExampleTag.hello_world #=&gt; "Hello 🌎 🌍 🌏"
376
+ #
377
+ def hello_world
378
+ "Hello 🌎 🌍 🌏"
379
+ end
380
+ </code></p>
381
+
382
+ <p>The below example code is generated from <code>{@example ReadmeYard::ExampleTag.hello_world}</code> because, as you can see above, the “hello_world” class method has an <code>@example</code> tag.</p>
383
+
384
+ <p><code>ruby
385
+ ReadmeYard::ExampleTag.hello_world #=&gt; "Hello 🌎 🌍 🌏"
386
+ </code></p>
387
+
388
+ <hr />
389
+
390
+ <h2 id="contributing">Contributing</h2>
391
+
392
+ <p>Bug reports and pull requests are welcome on GitHub at https://github.com/mattruzicka/readme_yard.</p>
393
+
394
+ <p>Thanks for reading me, the README that documents how to document the README with code that documents itself 🤯</p>
395
+ </div></div>
396
+
397
+ <div id="footer">
398
+ Generated on Mon May 5 09:48:52 2025 by
399
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
400
+ 0.9.37 (ruby-3.4.2).
401
+ </div>
402
+
403
+ </div>
404
+ </body>
405
+ </html>