readme_yard 0.1.2 → 0.3.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.yardopts +1 -0
- data/CHANGELOG.md +16 -1
- data/Gemfile +3 -0
- data/Gemfile.lock +65 -15
- data/README.md +235 -47
- data/README_YARD.md +141 -34
- data/bin/readme +2 -2
- data/lib/readme_yard/code_tag.rb +28 -0
- data/lib/readme_yard/comment_tag.rb +50 -0
- data/lib/readme_yard/error.rb +19 -0
- data/lib/readme_yard/example_tag.rb +36 -0
- data/lib/readme_yard/logger.rb +16 -0
- data/lib/readme_yard/readme_tag.rb +45 -0
- data/lib/readme_yard/source_tag.rb +30 -0
- data/lib/readme_yard/string_tag.rb +86 -0
- data/lib/readme_yard/tag_registry.rb +21 -0
- data/lib/readme_yard/value_tag.rb +31 -0
- data/lib/readme_yard/version.rb +1 -1
- data/lib/readme_yard/yard_opts_manager.rb +49 -0
- data/lib/readme_yard.rb +61 -80
- data/readme_yard.gemspec +7 -3
- metadata +45 -11
data/lib/readme_yard.rb
CHANGED
@@ -1,50 +1,44 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "yard"
|
3
4
|
require "yard-readme"
|
5
|
+
require "tty-markdown"
|
4
6
|
require_relative "readme_yard/version"
|
7
|
+
require_relative "readme_yard/error"
|
8
|
+
require_relative "readme_yard/logger"
|
9
|
+
require_relative "readme_yard/readme_tag"
|
10
|
+
require_relative "readme_yard/example_tag"
|
11
|
+
require_relative "readme_yard/comment_tag"
|
12
|
+
require_relative "readme_yard/code_tag"
|
13
|
+
require_relative "readme_yard/source_tag"
|
14
|
+
require_relative "readme_yard/value_tag"
|
15
|
+
require_relative "readme_yard/string_tag"
|
16
|
+
require_relative "readme_yard/tag_registry"
|
17
|
+
require_relative "readme_yard/yard_opts_manager"
|
18
|
+
|
19
|
+
YARD::Readme::DocstringParser.readme_tag_names = ReadmeYard::TagRegistry.tag_names
|
5
20
|
|
6
21
|
#
|
7
22
|
# @readme
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# Take a look at [README_YARD.md](https://github.com/mattruzicka/readme_yard/blob/main/README_YARD.md)
|
11
|
-
# to see the template from which the README for this project was generated.
|
23
|
+
# Build a better README with [YARD](https://yardoc.org)
|
24
|
+
# by generating it straight from the source.
|
12
25
|
#
|
26
|
+
# This gem aims to minimize the effort needed to keep your
|
27
|
+
# README, documentation, and source code synced, useful,
|
28
|
+
# and correct. Among its features, it introduces the @readme tag
|
29
|
+
# that enables you to embed code comments directly into README sections,
|
30
|
+
# eliminating redundancy and keeping documentation consistent
|
31
|
+
# across your codebase and project README.
|
32
|
+
#
|
33
|
+
# Look at the [README_YARD.md](https://github.com/mattruzicka/readme_yard/blob/main/README_YARD.md)
|
34
|
+
# template for this project to see how it works.
|
13
35
|
# If you're reading the README, that means this text is here
|
14
|
-
# because `{@readme ReadmeYard}` is in
|
15
|
-
#
|
16
|
-
# and someone ran `readme build` at the command line.
|
36
|
+
# because the custom `{@readme ReadmeYard}` markdown tag is in
|
37
|
+
# README_YARD.md and `readme build` was run at the command line.
|
17
38
|
#
|
18
|
-
#
|
19
|
-
# [documentation](https://rubydoc.info/github/mattruzicka/readme_yard),
|
20
|
-
# _welcome_ to readme yard!
|
39
|
+
# Here's the [full documentation](https://rubydoc.info/github/mattruzicka/readme_yard).
|
21
40
|
#
|
22
41
|
class ReadmeYard
|
23
|
-
class Error < StandardError
|
24
|
-
class << self
|
25
|
-
# TODO: Look for instance method with same name if
|
26
|
-
# class method and vise versa to give a more helpful error.
|
27
|
-
# Also, look for the object path in other scopes.
|
28
|
-
def object_not_found(tag_name, object_path)
|
29
|
-
new("`#{object_path}` could not be found. Perhaps" \
|
30
|
-
" the `@#{tag_name}` tag was moved, mispelled," \
|
31
|
-
" or the `.yardopts` YARD file is missing the file path.")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
#
|
37
|
-
# @readme
|
38
|
-
# This object only exists so that you can read this in the README. `ReadmeYard.hello_world` references
|
39
|
-
# the class method located in [lib/readme_yard.rb](https://github.com/mattruzicka/readme_yard/blob/main/lib/readme_yard.rb).
|
40
|
-
#
|
41
|
-
# @example
|
42
|
-
# ReadmeYard.hello_world => "Hello 🌎 🌍 🌏"
|
43
|
-
#
|
44
|
-
def self.hello_world
|
45
|
-
"Hello 🌎 🌍 🌏"
|
46
|
-
end
|
47
|
-
|
48
42
|
#
|
49
43
|
# @see #command_line_usage
|
50
44
|
#
|
@@ -54,13 +48,13 @@ class ReadmeYard
|
|
54
48
|
case arg
|
55
49
|
when "build"
|
56
50
|
readme_yard.build(options: options)
|
57
|
-
when "
|
58
|
-
readme_yard.
|
51
|
+
when "yard"
|
52
|
+
readme_yard.yard(options: options)
|
59
53
|
else
|
60
|
-
|
54
|
+
Logger.puts_md(readme_yard.command_line_usage)
|
61
55
|
end
|
62
56
|
rescue Error => e
|
63
|
-
|
57
|
+
Logger.puts_md(e.message)
|
64
58
|
end
|
65
59
|
|
66
60
|
def initialize
|
@@ -80,13 +74,13 @@ class ReadmeYard
|
|
80
74
|
#
|
81
75
|
# `readme build` - Reads from README_YARD.md and writes to README.md.
|
82
76
|
#
|
83
|
-
# `readme
|
77
|
+
# `readme yard` - Same as `readme build` + generates yard docs.
|
84
78
|
#
|
85
79
|
def command_line_usage
|
86
80
|
yard_parse_this_file
|
87
81
|
yard_object = YARD::Registry.at("#{self.class.name}##{__method__}")
|
88
|
-
|
89
|
-
"\n#{
|
82
|
+
yard_tags = yard_object.tags(:readme)
|
83
|
+
"\n#{ReadmeTag.format_tags(yard_object, yard_tags)}\n\n"
|
90
84
|
end
|
91
85
|
|
92
86
|
#
|
@@ -100,19 +94,16 @@ class ReadmeYard
|
|
100
94
|
# `-q` silence yardoc output statements
|
101
95
|
#
|
102
96
|
def build(options: "-nq")
|
103
|
-
|
97
|
+
YARD::CLI::Yardoc.run(options || "-nq")
|
104
98
|
File.write(readme_path, gsub_tags!(readme_yard_md))
|
105
99
|
end
|
106
100
|
|
107
101
|
#
|
108
102
|
# @readme Same as "build" + generates yard docs.
|
109
103
|
#
|
110
|
-
def
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
def run_yardoc(options: "-nq")
|
115
|
-
YARD::CLI::Yardoc.run("#{options || "-nq"} --plugin readme")
|
104
|
+
def yard(options: "-q")
|
105
|
+
YardOptsManager.upsert_yardopts
|
106
|
+
build(options: options || "-q")
|
116
107
|
end
|
117
108
|
|
118
109
|
private
|
@@ -130,22 +121,6 @@ class ReadmeYard
|
|
130
121
|
new_readme_yard_md
|
131
122
|
end
|
132
123
|
|
133
|
-
#
|
134
|
-
# This method adds the below paragraph to a project's
|
135
|
-
# README file, if it doesn't already have one when running
|
136
|
-
# `readme build` for the first time.
|
137
|
-
#
|
138
|
-
# @readme
|
139
|
-
# This is a quick example of using a readme tag in README_YARD.md
|
140
|
-
#
|
141
|
-
# > {@readme ReadmeYard#default_readme_yard_md}
|
142
|
-
#
|
143
|
-
# to copy a `@readme` comment from
|
144
|
-
# [source code](https://github.com/mattruzicka/readme_yard/blob/main/lib/readme_yard.rb)
|
145
|
-
# and paste it into the README file.
|
146
|
-
#
|
147
|
-
# 🌱 ⚽
|
148
|
-
#
|
149
124
|
def default_readme_yard_md
|
150
125
|
yard_parse_this_file
|
151
126
|
+"Welcome to the README_YARD 🌿 🥏\n\n" \
|
@@ -155,23 +130,37 @@ class ReadmeYard
|
|
155
130
|
end
|
156
131
|
|
157
132
|
def gsub_tags!(markdown)
|
158
|
-
markdown.gsub!(/([^`]|^)(\{@\w+\s.+\})/) { |string|
|
133
|
+
markdown.gsub!(/([^`]|^)(\{@\w+\s.+\})/) { |string| format_tag_markdown(string) }
|
159
134
|
markdown
|
160
135
|
end
|
161
136
|
|
162
|
-
def
|
137
|
+
def format_tag_markdown(string)
|
163
138
|
first_char = string[0]
|
164
139
|
return string if first_char == "`"
|
165
140
|
|
166
141
|
tag_name = extract_tag_name(string)
|
167
142
|
object_path = extract_object_path(string)
|
168
|
-
|
169
|
-
raise Error.
|
143
|
+
yard_object = YARD::Registry.at(object_path)
|
144
|
+
raise Error.object_not_found(object_path, tag_name) unless yard_object
|
145
|
+
|
146
|
+
yard_tags_markdown = format_yard_tags_markdown(yard_object, tag_name, string)
|
147
|
+
"#{first_char if first_char != "{"}#{yard_tags_markdown}"
|
148
|
+
end
|
170
149
|
|
171
|
-
|
172
|
-
|
150
|
+
def format_yard_tags_markdown(yard_object, tag_name, string)
|
151
|
+
yard_tags = yard_object.tags(tag_name)
|
152
|
+
tag_class = TagRegistry.find_class(tag_name)
|
173
153
|
|
174
|
-
|
154
|
+
if yard_tags.empty?
|
155
|
+
if tag_class.respond_to?(:format_yard_object)
|
156
|
+
tag_class.format_yard_object(yard_object) || string
|
157
|
+
else
|
158
|
+
Logger.warn("The `@#{tag_name}` tag is missing from `#{yard_object}`.")
|
159
|
+
string
|
160
|
+
end
|
161
|
+
else
|
162
|
+
tag_class.format_tags(yard_object, yard_tags)
|
163
|
+
end
|
175
164
|
end
|
176
165
|
|
177
166
|
def extract_tag_name(tag_string)
|
@@ -182,14 +171,6 @@ class ReadmeYard
|
|
182
171
|
tag_string.match(/\s(\b.+)}/).captures.first
|
183
172
|
end
|
184
173
|
|
185
|
-
def format_readme_tags(tags)
|
186
|
-
tags.map(&:text).join
|
187
|
-
end
|
188
|
-
|
189
|
-
def format_example_tags(tags)
|
190
|
-
tags.map { |tag| "```ruby\n#{tag.text}\n```" }.join("\n")
|
191
|
-
end
|
192
|
-
|
193
174
|
def yard_parse_this_file
|
194
175
|
gem_spec = Gem::Specification.find_by_name("readme_yard")
|
195
176
|
current_file_path = File.join(gem_spec.full_gem_path, "lib", "readme_yard.rb")
|
data/readme_yard.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
spec.summary = "Build a better README with YARD."
|
12
12
|
spec.homepage = "https://github.com/mattruzicka/readme_yard"
|
13
|
-
spec.required_ruby_version = ">=
|
13
|
+
spec.required_ruby_version = ">= 3.0"
|
14
14
|
|
15
15
|
spec.metadata["homepage_uri"] = spec.homepage
|
16
16
|
spec.metadata["source_code_uri"] = spec.homepage
|
@@ -22,12 +22,16 @@ Gem::Specification.new do |spec|
|
|
22
22
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
23
23
|
end
|
24
24
|
|
25
|
-
spec.
|
25
|
+
spec.bindir = "bin"
|
26
|
+
spec.executables = ["readme"]
|
26
27
|
spec.require_paths = ["lib"]
|
27
28
|
|
28
29
|
# Uncomment to register a new dependency of your gem
|
29
30
|
spec.add_dependency "tty-markdown", "~> 0.7"
|
30
|
-
spec.add_dependency "yard
|
31
|
+
spec.add_dependency "yard", "~> 0.9"
|
32
|
+
spec.add_dependency "yard-readme", "~> 0.5"
|
33
|
+
|
34
|
+
spec.add_development_dependency "irb"
|
31
35
|
|
32
36
|
# For more information and examples about making a new gem, checkout our
|
33
37
|
# guide at: https://bundler.io/guides/creating_gem.html
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: readme_yard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Ruzicka
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: tty-markdown
|
@@ -24,22 +23,48 @@ dependencies:
|
|
24
23
|
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: '0.7'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: yard
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.9'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.9'
|
27
40
|
- !ruby/object:Gem::Dependency
|
28
41
|
name: yard-readme
|
29
42
|
requirement: !ruby/object:Gem::Requirement
|
30
43
|
requirements:
|
31
44
|
- - "~>"
|
32
45
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
46
|
+
version: '0.5'
|
34
47
|
type: :runtime
|
35
48
|
prerelease: false
|
36
49
|
version_requirements: !ruby/object:Gem::Requirement
|
37
50
|
requirements:
|
38
51
|
- - "~>"
|
39
52
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
41
|
-
|
42
|
-
|
53
|
+
version: '0.5'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: irb
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
43
68
|
executables:
|
44
69
|
- readme
|
45
70
|
extensions: []
|
@@ -59,7 +84,18 @@ files:
|
|
59
84
|
- bin/readme
|
60
85
|
- bin/setup
|
61
86
|
- lib/readme_yard.rb
|
87
|
+
- lib/readme_yard/code_tag.rb
|
88
|
+
- lib/readme_yard/comment_tag.rb
|
89
|
+
- lib/readme_yard/error.rb
|
90
|
+
- lib/readme_yard/example_tag.rb
|
91
|
+
- lib/readme_yard/logger.rb
|
92
|
+
- lib/readme_yard/readme_tag.rb
|
93
|
+
- lib/readme_yard/source_tag.rb
|
94
|
+
- lib/readme_yard/string_tag.rb
|
95
|
+
- lib/readme_yard/tag_registry.rb
|
96
|
+
- lib/readme_yard/value_tag.rb
|
62
97
|
- lib/readme_yard/version.rb
|
98
|
+
- lib/readme_yard/yard_opts_manager.rb
|
63
99
|
- readme_yard.gemspec
|
64
100
|
homepage: https://github.com/mattruzicka/readme_yard
|
65
101
|
licenses:
|
@@ -68,7 +104,6 @@ metadata:
|
|
68
104
|
homepage_uri: https://github.com/mattruzicka/readme_yard
|
69
105
|
source_code_uri: https://github.com/mattruzicka/readme_yard
|
70
106
|
changelog_uri: https://github.com/mattruzicka/readme_yard/blob/master/CHANGELOG.md
|
71
|
-
post_install_message:
|
72
107
|
rdoc_options: []
|
73
108
|
require_paths:
|
74
109
|
- lib
|
@@ -76,15 +111,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
111
|
requirements:
|
77
112
|
- - ">="
|
78
113
|
- !ruby/object:Gem::Version
|
79
|
-
version: '
|
114
|
+
version: '3.0'
|
80
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
116
|
requirements:
|
82
117
|
- - ">="
|
83
118
|
- !ruby/object:Gem::Version
|
84
119
|
version: '0'
|
85
120
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
87
|
-
signing_key:
|
121
|
+
rubygems_version: 3.6.8
|
88
122
|
specification_version: 4
|
89
123
|
summary: Build a better README with YARD.
|
90
124
|
test_files: []
|