yard-markdown 0.7.0 → 0.7.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41e14595e84affb837da2c36afb9a40f0e7ea866472fa32e5aefabc7c32c2ec8
4
- data.tar.gz: 605f1ad9c9496ebaf48afc7245ab25db98b5e22aed88c7c718bb3968f78b3b5e
3
+ metadata.gz: 20eaf2ccb5ab45418bcb82e961f472231fb5d705090e8650dd854a8cc0e1d92f
4
+ data.tar.gz: ec1a4f6d7f3afa2f7af44c44a72af9ba6a22148ffeb643dda1ffbb747a0cf1ee
5
5
  SHA512:
6
- metadata.gz: '0887584b2fe63298271fad1483237eb303d215068a6da79aee7cb59c463a6c2838a6a72171676e7876f7a7d8c9003c0e23eb0fcb9dbfd88e329f028c5907bdef'
7
- data.tar.gz: 9d50e908447b65b564315c996af01a43e35d360f2bafd600d34197ed20fc0cf8fde1b506850eb2fd476ee65d33c44ff10de8658abcd51037011060d4e69ec59f
6
+ metadata.gz: ea0c103943a5b5361ecab753fa0d014835016a6a154bb77552e7c8d3c1f253eea2a8c62c2aafe2d7f72afd31dfe5cac763c864a7768cd0126bc229ba8f19ace4
7
+ data.tar.gz: 0f2ade24652236aef7cfb310cafe04f1f0dcc43a5bccba854ec9712d0a7edb752d91a6f85b723a8c5e19e66aff798ff2cbf669b4e5401f33f2f18c66875e8dd3
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ ignore:
2
+ - "example_*.rb"
3
+ - "test/example/example.rb"
data/AGENTS.md CHANGED
@@ -40,15 +40,15 @@ the user.
40
40
  No `expressions:` filters, no `coverage_criteria:` tweaks.
41
41
  - You may not use `send` or `__send__` to invoke private methods
42
42
  in tests just to satisfy mutant.
43
- - You may not stub or mock the system under test (`Age`).
43
+ - You may not stub or mock the system under test.
44
44
 
45
45
  ## Done
46
46
 
47
- You are done when both of these are green and don't return any offenses:
47
+ You are done when all of these commands are green and don't return any offenses:
48
48
 
49
49
  ```
50
50
  SIMPLECOV=1 bundle exec rake test
51
51
  bundle exec mutant run
52
52
  bundle exec rake markdown:validate_real_world
53
- yard-lint lib/
53
+ yard-lint
54
54
  ```
data/CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@ This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ ## 0.7.1
9
+
10
+ ### Fixed
11
+ - Preserve fenced code blocks in YARD docstrings so generated Markdown examples render correctly.
12
+
8
13
  ## 0.7.0
9
14
  ## Added
10
15
  - Adding yard-lint and all method documentation
@@ -14,4 +19,3 @@ This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
14
19
  ## Changed
15
20
  - Refactoring and simplification of teamplate, mostly driven by mutantion testing
16
21
  - Improve documentation for entire project
17
-
data/README.md CHANGED
@@ -12,15 +12,6 @@ It's a pitty that rdoc and yard can't output a proper markdown file. I would lik
12
12
  - Mimick yard html layout where it makes sense to maintain familiarity
13
13
 
14
14
  ## Usage
15
- Yard doesn't load plugin by default, so you need to load plugin through `~/.yard/config`:
16
-
17
- ```yaml
18
- !!!yaml
19
- load_plugins: true
20
- autoload_plugins:
21
- - markdown
22
- ```
23
-
24
15
  Install a plugin
25
16
  ```
26
17
  gem install yard-markdown
@@ -28,20 +19,32 @@ gem install yard-markdown
28
19
 
29
20
  Run `yardoc --format=markdown` to generate markdown documentation.
30
21
 
31
- ## Note on RDoc support
22
+ ## FAQ
23
+
24
+ ### Note on RDoc support
32
25
  It seems important to note, that yard claims to have support for RDoc. That support is certainly present, but output for rdoc is dramatically different. A lot of useful information seems lost in the process.
33
26
 
34
27
  If you know how to improve that, please get in touch or submit a patch.
35
28
 
36
29
  So in meantime, there is work going on a competing gem for RDoc and it's called [rdoc-markdown gem](https://github.com/skatkov/rdoc-markdown/).
37
30
 
38
- ## Note on index.csv file
31
+ ### Note on index.csv file
39
32
  This gem emits index of all markdown files in a index.csv file.
40
33
 
41
34
  There are decent tools that offer search through structured plain-text files. But my expectation is that nobody will use CSV as an actual search index, but rather import it into something that performs this function better.
42
35
 
43
36
  In my personal use-case, I use SQLite. All other databases seem to have a good support for CSV imports.
44
37
 
38
+ ### Yard doesn't load plugin properly?
39
+ so you need to load plugin through `~/.yard/config`:
40
+
41
+ ```yaml
42
+ !!!yaml
43
+ load_plugins: true
44
+ autoload_plugins:
45
+ - markdown
46
+ ```
47
+
45
48
  ## Testing
46
49
  Unit tests verify renderer behavior, index links, and anchor consistency for both YARD-style and RDoc-style sources.
47
50
 
data/Rakefile CHANGED
@@ -64,7 +64,7 @@ def run_command_with_analysis(command, label:)
64
64
 
65
65
  details = ["#{label} failed output checks (log: #{log_path})"]
66
66
  details << "exit status: #{status.exitstatus}" unless status.success?
67
- details << "errors: #{combined_analysis[:errors].first(5).join(' | ')}" unless combined_analysis[:errors].empty?
67
+ details << "errors: #{combined_analysis[:errors].first(5).join(" | ")}" unless combined_analysis[:errors].empty?
68
68
  raise details.join("\n")
69
69
  end
70
70
 
@@ -113,7 +113,6 @@ def ensure_clean_generated_file(path)
113
113
  raise "#{path} is out of date. Run `bundle exec rake types:generate` and commit the updated file."
114
114
  end
115
115
 
116
-
117
116
  namespace :examples do
118
117
  desc "Generate basic example documentation using yard-markdown plugin"
119
118
  task :generate do
@@ -133,28 +132,28 @@ namespace :examples do
133
132
  end
134
133
 
135
134
  namespace :real_world do
136
- REPOS_DIR = "tmp/real-world/repos"
137
- RSPEC_REPO = "#{REPOS_DIR}/rspec-core"
138
- SIDEKIQ_REPO = "#{REPOS_DIR}/sidekiq"
135
+ repos_dir = "tmp/real-world/repos"
136
+ rspec_repo = "#{repos_dir}/rspec-core"
137
+ sidekiq_repo = "#{repos_dir}/sidekiq"
139
138
 
140
139
  desc "Checkout rspec-core repository"
141
140
  task :checkout_rspec do
142
- checkout_repo("https://github.com/rspec/rspec-core.git", RSPEC_REPO, ref: "v3.13.2")
141
+ checkout_repo("https://github.com/rspec/rspec-core.git", rspec_repo, ref: "v3.13.2")
143
142
  end
144
143
 
145
144
  desc "Checkout sidekiq repository"
146
145
  task :checkout_sidekiq do
147
- checkout_repo("https://github.com/sidekiq/sidekiq.git", SIDEKIQ_REPO, ref: "v7.3.10")
146
+ checkout_repo("https://github.com/sidekiq/sidekiq.git", sidekiq_repo, ref: "v7.3.10")
148
147
  end
149
148
 
150
149
  desc "Generate markdown docs for rspec-core"
151
150
  task rspec: :checkout_rspec do
152
- generate_markdown_docs("#{RSPEC_REPO}/lib", "tmp/real-world/rspec-core")
151
+ generate_markdown_docs("#{rspec_repo}/lib", "tmp/real-world/rspec-core")
153
152
  end
154
153
 
155
154
  desc "Generate markdown docs for sidekiq"
156
155
  task sidekiq: :checkout_sidekiq do
157
- generate_markdown_docs("#{SIDEKIQ_REPO}/lib", "tmp/real-world/sidekiq")
156
+ generate_markdown_docs("#{sidekiq_repo}/lib", "tmp/real-world/sidekiq")
158
157
  end
159
158
 
160
159
  desc "Generate markdown docs for rspec-core and sidekiq"
data/config/mutant.yml CHANGED
@@ -12,14 +12,4 @@ requires:
12
12
 
13
13
  matcher:
14
14
  subjects:
15
- - YARD::Markdown::AnchorComponentHelper#
16
- - YARD::Markdown::ArefHelper#
17
- - YARD::Markdown::CollectionRenderingHelper#
18
- - YARD::Markdown::DocumentationHelper#
19
- - YARD::Markdown::HeadingHelper#
20
- - YARD::Markdown::LinkNormalizationHelper#
21
- - YARD::Markdown::MethodPresentationHelper#
22
- - YARD::Markdown::ObjectListingHelper#
23
- - YARD::Markdown::RelationshipSectionHelper#
24
- - YARD::Markdown::SectionAssemblyHelper#
25
- - YARD::Markdown::TagFormattingHelper#
15
+ - YARD::Markdown*
data/example_rdoc.rb CHANGED
@@ -133,7 +133,6 @@ end
133
133
  DEFAULT_DUCK_VELOCITY = 70
134
134
  DEFAULT_SPEED = 10 # Maximum speed for a swimming duck.
135
135
 
136
-
137
136
  # Default rubber duck.
138
137
  #
139
138
  # *Note:*
data/example_yard.rb CHANGED
@@ -142,4 +142,4 @@ $default_wild_salmon = Salmon.new(false, true)
142
142
  # Farmed sustainable salmon.
143
143
  #
144
144
  # @note This is just a local variable for demonstration purposes.
145
- farmed_sustainable_salmon = Salmon.new(true, false)
145
+ Salmon.new(true, false)
@@ -12,7 +12,7 @@ module YARD
12
12
  # @return [String] Anchor-safe identifier fragment.
13
13
  def anchor_component(value)
14
14
  value.to_s.each_char.map do |char|
15
- char.match?(/[A-Za-z0-9_-]/) ? char : format('-%X', char.ord)
15
+ char.match?(/[A-Za-z0-9_-]/) ? char : format("-%X", char.ord)
16
16
  end.join
17
17
  end
18
18
  end
@@ -13,12 +13,12 @@ module YARD
13
13
  def aref(object)
14
14
  type = object.type
15
15
 
16
- return "class-#{object.path.gsub('::', '-')}" if type == :class
17
- return "module-#{object.path.gsub('::', '-')}" if type == :module
16
+ return "class-#{object.path.gsub("::", "-")}" if type == :class
17
+ return "module-#{object.path.gsub("::", "-")}" if type == :module
18
18
  return "constant-#{object.name}" if type == :constant
19
19
  return "classvariable-#{anchor_component(object.name)}" if type == :classvariable
20
20
 
21
- scope = object.scope == :class ? 'c' : 'i'
21
+ scope = (object.scope == :class) ? "c" : "i"
22
22
 
23
23
  if !object.attr_info.nil?
24
24
  "attribute-#{scope}-#{object.name}"
@@ -10,16 +10,16 @@ module YARD
10
10
  # @param group_order [Array<String>, nil] Preferred ordering for group headings.
11
11
  # @return [String] Markdown for the constants section.
12
12
  def render_constants(constants, group_order)
13
- lines = ['## Constants']
13
+ lines = ["## Constants"]
14
14
  grouped_constants = grouped_items(constants.sort_by { |item| item.name }, group_order)
15
15
  uses_groups = grouped_constants.any? { |name, _items| !name.nil? }
16
16
 
17
17
  grouped_constants.each do |group_name, items|
18
18
  if uses_groups
19
- lines << "### #{group_name || 'General'}"
20
- item_heading = '####'
19
+ lines << "### #{group_name || "General"}"
20
+ item_heading = "####"
21
21
  else
22
- item_heading = '###'
22
+ item_heading = "###"
23
23
  end
24
24
 
25
25
  lines << items.map { |item|
@@ -39,16 +39,16 @@ module YARD
39
39
  # @param group_order [Array<String>, nil] Preferred ordering for group headings.
40
40
  # @return [String] Markdown for the attributes section.
41
41
  def render_attributes(attrs, group_order)
42
- lines = ['## Attributes']
42
+ lines = ["## Attributes"]
43
43
  grouped_attrs = grouped_items(attrs, group_order)
44
44
  uses_groups = grouped_attrs.any? { |name, _items| !name.nil? }
45
45
 
46
46
  grouped_attrs.each do |group_name, items|
47
47
  if uses_groups
48
- lines << "### #{group_name || 'General'}"
49
- item_heading = '####'
48
+ lines << "### #{group_name || "General"}"
49
+ item_heading = "####"
50
50
  else
51
- item_heading = '###'
51
+ item_heading = "###"
52
52
  end
53
53
 
54
54
  lines << items.map { |item|
@@ -75,10 +75,10 @@ module YARD
75
75
 
76
76
  grouped_methods.each do |group_name, items|
77
77
  if uses_groups
78
- lines << "### #{group_name || 'General'}"
79
- item_heading = '####'
78
+ lines << "### #{group_name || "General"}"
79
+ item_heading = "####"
80
80
  else
81
- item_heading = '###'
81
+ item_heading = "###"
82
82
  end
83
83
 
84
84
  lines << items.map { |item|
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rdoc'
3
+ require "rdoc"
4
4
 
5
5
  module YARD
6
6
  module Markdown
@@ -13,9 +13,9 @@ module YARD
13
13
  def documented_text(object)
14
14
  text = rdoc_to_md(object.docstring)
15
15
  return text unless text.empty?
16
- return '' unless object.tags.empty?
16
+ return "" unless object.tags.empty?
17
17
 
18
- 'Not documented.'
18
+ "Not documented."
19
19
  end
20
20
 
21
21
  # Converts an RDoc-formatted docstring to Markdown.
@@ -23,7 +23,19 @@ module YARD
23
23
  # @param docstring [Object] Raw docstring content.
24
24
  # @return [String] Markdown-rendered docstring content.
25
25
  def rdoc_to_md(docstring)
26
- RDoc::Markup::ToMarkdown.new.convert(docstring).rstrip
26
+ fenced_code_blocks = []
27
+ placeholder = "YARD_MARKDOWN_FENCED_CODE_BLOCK_%d"
28
+ content = docstring.gsub(/^```[^\n]*\n.*?^```[ \t]*$/m) do |block|
29
+ fenced_code_blocks << block
30
+ format(placeholder, fenced_code_blocks.length - 1)
31
+ end
32
+
33
+ markdown = RDoc::Markup::ToMarkdown.new.convert(content).rstrip
34
+ fenced_code_blocks.each_with_index do |block, index|
35
+ markdown = markdown.sub(format(placeholder, index), block)
36
+ end
37
+
38
+ markdown
27
39
  end
28
40
  end
29
41
  end
@@ -37,7 +37,7 @@ module YARD
37
37
  # @param object [YARD::CodeObjects::Base] Object being rendered.
38
38
  # @return [String] Heading text with embedded anchor tags.
39
39
  def heading_with_anchors(heading, object)
40
- "#{heading} #{anchor_tags_for(object).join(' ')}"
40
+ "#{heading} #{anchor_tags_for(object).join(" ")}"
41
41
  end
42
42
 
43
43
  # Builds an HTML anchor tag for a generated id.
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pathname'
4
-
5
3
  module YARD
6
4
  module Markdown
7
5
  # Rewrites generated Markdown links so they point at Markdown output.
@@ -31,12 +29,12 @@ module YARD
31
29
  markdown.gsub(%r{\[(.+?)\]\((?!https?://|mailto:|#)([^)\n]+)\)}) do
32
30
  label = Regexp.last_match(1)
33
31
  target = Regexp.last_match(2)
34
- path = target.sub(/[?#].*\z/, '')
32
+ path = target.sub(/[?#].*\z/, "")
35
33
  suffix = target[path.length..]
36
34
  rewritten_path = resolve_local_link_target(path, current_dir)
37
35
 
38
36
  if rewritten_path.nil?
39
- "`#{label.tr('`', '')}`"
37
+ "`#{label.tr("`", "")}`"
40
38
  else
41
39
  "[#{label}](#{rewritten_path}#{suffix})"
42
40
  end
@@ -49,15 +47,15 @@ module YARD
49
47
  # @param current_dir [Pathname] Directory for the current output file.
50
48
  # @return [YARD::CodeObjects::Base, nil] Matched registry object, if any.
51
49
  def resolve_registry_object(path, current_dir)
52
- cleaned = path.sub(%r{\A(?:(?:\.\./)+|\./)}, '')
50
+ cleaned = path.sub(%r{\A(?:(?:\.\./)+|\./)}, "")
53
51
  candidates = [path]
54
52
 
55
53
  if constant_reference_path?(cleaned)
56
- current_parts = current_dir.to_s.split('/').reject { |part| part.empty? || part == '.' }
57
- target_parts = cleaned.split('/')
54
+ current_parts = current_dir.to_s.split("/").reject { |part| part.empty? || part == "." }
55
+ target_parts = cleaned.split("/")
58
56
 
59
57
  current_parts.length.downto(0) do |depth|
60
- candidates << (current_parts.first(depth) + target_parts).join('::')
58
+ candidates << (current_parts.first(depth) + target_parts).join("::")
61
59
  end
62
60
  end
63
61
 
@@ -77,7 +75,7 @@ module YARD
77
75
  # @param current_dir [Pathname] Directory for the current output file.
78
76
  # @return [String, nil] Relative Markdown path, or nil when unresolved.
79
77
  def resolve_local_link_target(path, current_dir)
80
- normalized = path.sub(%r{\A/+}, '')
78
+ normalized = path.sub(%r{\A/+}, "")
81
79
 
82
80
  obj = resolve_registry_object(normalized, current_dir)
83
81
  if obj
@@ -86,11 +84,11 @@ module YARD
86
84
  end
87
85
 
88
86
  if normalized.match?(/\.html\z/i)
89
- normalized = normalized.sub(/\.html\z/i, '.md')
87
+ normalized = normalized.sub(/\.html\z/i, ".md")
90
88
  elsif File.extname(normalized).empty?
91
89
  return nil if unresolved_identifier_target?(normalized)
92
90
 
93
- normalized = "#{normalized}.md" if normalized.include?('/')
91
+ normalized = "#{normalized}.md" if normalized.include?("/")
94
92
  end
95
93
 
96
94
  relative_output_path(current_dir, normalized)
@@ -112,8 +110,8 @@ module YARD
112
110
  # @param path [String] Link target to inspect.
113
111
  # @return [Boolean] True when the target should be treated as unresolved.
114
112
  def unresolved_identifier_target?(path)
115
- cleaned = path.sub(%r{\A(?:(?:\.\./)+|\./)}, '')
116
- return true if cleaned.start_with?(':') || cleaned.match?(/\A\d/)
113
+ cleaned = path.sub(%r{\A(?:(?:\.\./)+|\./)}, "")
114
+ return true if cleaned.start_with?(":") || cleaned.match?(/\A\d/)
117
115
 
118
116
  cleaned.match?(/\A[a-z_]\w*\z/)
119
117
  end
@@ -125,10 +123,10 @@ module YARD
125
123
  # @return [String] Relative path suitable for a Markdown link.
126
124
  def relative_output_path(current_dir, target_path)
127
125
  target = target_path.to_s
128
- return target if target.start_with?('../')
126
+ return target if target.start_with?("../")
129
127
 
130
128
  Pathname.new(target).relative_path_from(current_dir).to_s
131
- rescue StandardError
129
+ rescue
132
130
  target
133
131
  end
134
132
 
@@ -11,7 +11,7 @@ module YARD
11
11
  def formatted_method_heading(method_object)
12
12
  name = method_object.name
13
13
  signature = method_signature(method_object)
14
- signature = " #{signature}" if name.end_with?(']')
14
+ signature = " #{signature}" if name.end_with?("]")
15
15
  "#{name}#{signature}"
16
16
  end
17
17
 
@@ -20,13 +20,13 @@ module YARD
20
20
  # @param method_object [YARD::CodeObjects::MethodObject] Method being rendered.
21
21
  # @return [String] Parenthesized method signature.
22
22
  def method_signature(method_object)
23
- return '()' if method_object.parameters.nil?
23
+ return "()" if method_object.parameters.nil?
24
24
 
25
25
  rendered = method_object.parameters.map do |name, default|
26
- default.nil? || default.empty? ? name : "#{name} = #{default}"
26
+ (default.nil? || default.empty?) ? name : "#{name} = #{default}"
27
27
  end
28
28
 
29
- "(#{rendered.join(', ')})"
29
+ "(#{rendered.join(", ")})"
30
30
  end
31
31
 
32
32
  # Returns the access marker for an attribute.
@@ -35,14 +35,14 @@ module YARD
35
35
  # @return [String] Access mode marker such as `R`, `W`, or `RW`.
36
36
  def attribute_access(attribute)
37
37
  info = attribute.attr_info || {}
38
- return 'RW' if info[:read] && info[:write]
39
- return 'R' if info[:read]
40
- return 'W' if info[:write]
38
+ return "RW" if info[:read] && info[:write]
39
+ return "R" if info[:read]
40
+ return "W" if info[:write]
41
41
 
42
- return 'RW' if attribute.reader? && attribute.writer?
43
- return 'R' if attribute.reader?
42
+ return "RW" if attribute.reader? && attribute.writer?
43
+ return "R" if attribute.reader?
44
44
 
45
- 'W'
45
+ "W"
46
46
  end
47
47
  end
48
48
  end
@@ -80,7 +80,7 @@ module YARD
80
80
  # @param object [YARD::CodeObjects::Base] Listed object whose docstring may start with `:nodoc:`.
81
81
  # @return [Boolean] True when the object should be hidden.
82
82
  def hidden_object?(object)
83
- object.docstring.lstrip.start_with?(':nodoc:')
83
+ object.docstring.start_with?(":nodoc:")
84
84
  end
85
85
  end
86
86
  end
@@ -10,7 +10,7 @@ module YARD
10
10
  # @return [String] Section content followed by blank-line spacing.
11
11
  def render_section_content(content)
12
12
  text = content.to_s.strip
13
- return '' if text.empty?
13
+ return "" if text.empty?
14
14
 
15
15
  "#{text}\n\n"
16
16
  end
@@ -24,11 +24,11 @@ module YARD
24
24
 
25
25
  lines << "**Inherits:** `#{object.superclass}`" if object.instance_of?(CodeObjects::ClassObject)
26
26
 
27
- [[:class, 'Extended by'], [:instance, 'Includes']].each do |scope, label|
27
+ [[:class, "Extended by"], [:instance, "Includes"]].each do |scope, label|
28
28
  mixins = run_verifier(object.mixins(scope)).sort_by { |item| item.path }
29
29
  next if mixins.empty?
30
30
 
31
- lines << "**#{label}:** #{mixins.map { |mixin| "`#{mixin.path}`" }.join(', ')}"
31
+ lines << "**#{label}:** #{mixins.map { |mixin| "`#{mixin.path}`" }.join(", ")}"
32
32
  end
33
33
 
34
34
  lines.join("\n")
@@ -38,7 +38,7 @@ module YARD
38
38
  def append_lines(lines, content, separated: true)
39
39
  return if content.lstrip.empty?
40
40
 
41
- lines << '' if separated && !lines.empty? && !lines.last.empty?
41
+ lines << "" if separated && !lines.empty? && !lines.last.empty?
42
42
  lines.concat(content.split("\n"))
43
43
  end
44
44
  end
@@ -10,8 +10,8 @@ module YARD
10
10
  # @return [String] Markdown representation of the object's tags.
11
11
  def render_tags(object)
12
12
  lines = []
13
- regular_tags = object.tags.reject { |tag| tag.tag_name == 'example' }
14
- example_tags = object.tags.select { |tag| tag.tag_name == 'example' }
13
+ regular_tags = object.tags.reject { |tag| tag.tag_name == "example" }
14
+ example_tags = object.tags.select { |tag| tag.tag_name == "example" }
15
15
 
16
16
  regular_tags.each do |tag|
17
17
  lines << "- #{format_tag(tag)}"
@@ -19,11 +19,11 @@ module YARD
19
19
 
20
20
  example_tags.each do |tag|
21
21
  lines << nil unless lines.empty?
22
- title = tag.name.to_s.rstrip.empty? ? '**@example**' : "**@example #{tag.name}**"
22
+ title = tag.name.to_s.rstrip.empty? ? "**@example**" : "**@example #{tag.name}**"
23
23
  lines << title
24
- lines << '```ruby'
24
+ lines << "```ruby"
25
25
  lines << tag.text.to_s.rstrip
26
- lines << '```'
26
+ lines << "```"
27
27
  end
28
28
 
29
29
  lines.join("\n")
@@ -38,10 +38,10 @@ module YARD
38
38
  parts << "`#{tag.name}`" unless tag.name.to_s.lstrip.empty?
39
39
 
40
40
  cleaned_types = normalized_tag_types(tag.types)
41
- parts << "[#{cleaned_types.join(', ')}]" unless cleaned_types.empty?
41
+ parts << "[#{cleaned_types.join(", ")}]" unless cleaned_types.empty?
42
42
  parts << tag.text.strip unless tag.text.to_s.lstrip.empty?
43
43
 
44
- parts.join(' ')
44
+ parts.join(" ")
45
45
  end
46
46
 
47
47
  # Normalizes tag type declarations into printable strings.
@@ -50,10 +50,10 @@ module YARD
50
50
  # @return [Array<String>] Cleaned type strings.
51
51
  def normalized_tag_types(types)
52
52
  values = if types.instance_of?(Hash)
53
- types.map { |name, value| format_hash_tag_type(name, value) }
54
- else
55
- Array(types)
56
- end
53
+ types.map { |name, value| format_hash_tag_type(name, value) }
54
+ else
55
+ Array(types)
56
+ end
57
57
 
58
58
  values.map(&:to_s).map(&:strip).reject(&:empty?)
59
59
  end
@@ -11,14 +11,14 @@ module YARD
11
11
  # _@param_ `object` — Object being rendered.
12
12
  #
13
13
  # _@return_ — Anchor id for the object's heading.
14
- def aref: (untyped object) -> String
14
+ def aref: (Object object) -> String
15
15
 
16
16
  # Encodes a value so it can be embedded safely in an HTML anchor id.
17
17
  #
18
18
  # _@param_ `value` — Raw anchor fragment to encode.
19
19
  #
20
20
  # _@return_ — Anchor-safe identifier fragment.
21
- def anchor_component: (Object value) -> String
21
+ def anchor_component: () -> String
22
22
  end
23
23
 
24
24
  # Builds headings and legacy anchors for rendered object sections.
@@ -30,14 +30,14 @@ module YARD
30
30
  # _@param_ `object` — Object being rendered.
31
31
  #
32
32
  # _@return_ — Legacy anchor id, if supported.
33
- def legacy_aref: (untyped object) -> String?
33
+ def legacy_aref: (Object object) -> String?
34
34
 
35
35
  # Returns all anchor tags that should be attached to a heading.
36
36
  #
37
37
  # _@param_ `object` — Object being rendered.
38
38
  #
39
39
  # _@return_ — HTML anchor tags for the object.
40
- def anchor_tags_for: (untyped object) -> ::Array[String]
40
+ def anchor_tags_for: (Object object) -> Symbol
41
41
 
42
42
  # Appends the generated anchor tags to a Markdown heading.
43
43
  #
@@ -46,7 +46,7 @@ module YARD
46
46
  # _@param_ `object` — Object being rendered.
47
47
  #
48
48
  # _@return_ — Heading text with embedded anchor tags.
49
- def heading_with_anchors: (String heading, untyped object) -> String
49
+ def heading_with_anchors: (String heading, Object object) -> String
50
50
 
51
51
  # Builds an HTML anchor tag for a generated id.
52
52
  #
@@ -60,14 +60,14 @@ module YARD
60
60
  # _@param_ `object` — Object being rendered.
61
61
  #
62
62
  # _@return_ — Anchor id for the object's heading.
63
- def aref: (untyped object) -> String
63
+ def aref: () -> String
64
64
 
65
65
  # Encodes a value so it can be embedded safely in an HTML anchor id.
66
66
  #
67
67
  # _@param_ `value` — Raw anchor fragment to encode.
68
68
  #
69
69
  # _@return_ — Anchor-safe identifier fragment.
70
- def anchor_component: (Object value) -> String
70
+ def anchor_component: () -> String
71
71
  end
72
72
 
73
73
  # Converts YARD docstrings into Markdown-friendly text.
@@ -77,7 +77,7 @@ module YARD
77
77
  # _@param_ `object` — Object whose docstring is being rendered.
78
78
  #
79
79
  # _@return_ — Converted documentation text or a fallback message.
80
- def documented_text: (untyped object) -> String
80
+ def documented_text: (Object object) -> String
81
81
 
82
82
  # Converts an RDoc-formatted docstring to Markdown.
83
83
  #
@@ -94,49 +94,49 @@ module YARD
94
94
  # _@param_ `object` — Object being rendered.
95
95
  #
96
96
  # _@return_ — Constants and class variables.
97
- def constant_listing: (untyped object) -> ::Array[untyped]
97
+ def constant_listing: (Object object) -> Symbol
98
98
 
99
99
  # Returns the visible public methods defined directly on an object.
100
100
  #
101
101
  # _@param_ `object` — Object being rendered.
102
102
  #
103
103
  # _@return_ — Sorted public methods.
104
- def public_method_list: (untyped object) -> ::Array[untyped]
104
+ def public_method_list: (Object object) -> Symbol
105
105
 
106
106
  # Returns the public class methods defined directly on an object.
107
107
  #
108
108
  # _@param_ `object` — Object being rendered.
109
109
  #
110
110
  # _@return_ — Sorted public class methods.
111
- def public_class_methods: (untyped object) -> ::Array[untyped]
111
+ def public_class_methods: (Object object) -> Symbol
112
112
 
113
113
  # Returns the public instance methods defined directly on an object.
114
114
  #
115
115
  # _@param_ `object` — Object being rendered.
116
116
  #
117
117
  # _@return_ — Sorted public instance methods.
118
- def public_instance_methods: (untyped object) -> ::Array[untyped]
118
+ def public_instance_methods: (Object object) -> Symbol
119
119
 
120
120
  # Returns the visible attribute methods for an object.
121
121
  #
122
122
  # _@param_ `object` — Object being rendered.
123
123
  #
124
124
  # _@return_ — Sorted attribute methods.
125
- def attr_listing: (untyped object) -> ::Array[untyped]
125
+ def attr_listing: (Object object) -> Symbol
126
126
 
127
127
  # Sorts a listing by scope and case-insensitive name.
128
128
  #
129
129
  # _@param_ `list` — Objects to sort.
130
130
  #
131
131
  # _@return_ — Sorted objects.
132
- def sort_listing: (::Array[untyped] list) -> ::Array[untyped]
132
+ def sort_listing: (Symbol list) -> Symbol
133
133
 
134
134
  # Returns whether an object is explicitly hidden with `:nodoc:`.
135
135
  #
136
136
  # _@param_ `object` — Listed object whose docstring may start with `:nodoc:`.
137
137
  #
138
138
  # _@return_ — True when the object should be hidden.
139
- def hidden_object?: (untyped object) -> bool
139
+ def hidden_object?: (Object object) -> bool
140
140
  end
141
141
 
142
142
  # Formats YARD tags into Markdown list items and fenced examples.
@@ -146,21 +146,21 @@ module YARD
146
146
  # _@param_ `object` — Object whose tags are being rendered.
147
147
  #
148
148
  # _@return_ — Markdown representation of the object's tags.
149
- def render_tags: (untyped object) -> String
149
+ def render_tags: (Object object) -> String
150
150
 
151
151
  # Formats a non-example YARD tag as a Markdown list item body.
152
152
  #
153
153
  # _@param_ `tag` — Non-example tag being converted into list item text.
154
154
  #
155
155
  # _@return_ — Markdown representation of the tag.
156
- def format_tag: (untyped tag) -> String
156
+ def format_tag: (Object tag) -> String
157
157
 
158
158
  # Normalizes tag type declarations into printable strings.
159
159
  #
160
160
  # _@param_ `types` — Raw tag types from YARD.
161
161
  #
162
162
  # _@return_ — Cleaned type strings.
163
- def normalized_tag_types: ((::Array[Object] | ::Hash[untyped, untyped])? types) -> ::Array[String]
163
+ def normalized_tag_types: (Symbol? types) -> Symbol
164
164
 
165
165
  # Formats a hash-style tag type entry.
166
166
  #
@@ -191,7 +191,7 @@ module YARD
191
191
  # _@param_ `group_order` — Preferred ordering for named groups.
192
192
  #
193
193
  # _@return_ — Ordered pairs of group names and grouped items.
194
- def grouped_items: (::Array[untyped] items, ::Array[String]? group_order) -> ::Array[::Array[untyped]]
194
+ def grouped_items: (Symbol items, Symbol? group_order) -> Symbol
195
195
 
196
196
  # Appends non-empty content to a mutable list of lines.
197
197
  #
@@ -200,7 +200,7 @@ module YARD
200
200
  # _@param_ `content` — Rendered Markdown block to split into lines.
201
201
  #
202
202
  # _@param_ `separated` — Whether to insert a blank separator line first.
203
- def append_lines: (::Array[String] lines, String content, ?separated: bool) -> void
203
+ def append_lines: (Symbol lines, String content, ?separated: bool) -> void
204
204
  end
205
205
 
206
206
  # Rewrites generated Markdown links so they point at Markdown output.
@@ -212,7 +212,7 @@ module YARD
212
212
  # _@param_ `current_path` — Output path for the current document.
213
213
  #
214
214
  # _@return_ — Normalized Markdown content with a trailing newline.
215
- def finalize_markdown: ((String | ::Array[String]) content, String current_path) -> String
215
+ def finalize_markdown: ((String | Symbol) content, String current_path) -> String
216
216
 
217
217
  # Rewrites local Markdown links relative to the current output path.
218
218
  #
@@ -230,7 +230,7 @@ module YARD
230
230
  # _@param_ `current_dir` — Directory for the current output file.
231
231
  #
232
232
  # _@return_ — Matched registry object, if any.
233
- def resolve_registry_object: (String path, Pathname current_dir) -> untyped?
233
+ def resolve_registry_object: (String path, Pathname current_dir) -> Object?
234
234
 
235
235
  # Resolves a local link target to the final relative Markdown path.
236
236
  #
@@ -279,21 +279,21 @@ module YARD
279
279
  # _@param_ `method_object` — Method being rendered.
280
280
  #
281
281
  # _@return_ — Method heading text.
282
- def formatted_method_heading: (untyped method_object) -> String
282
+ def formatted_method_heading: (Object method_object) -> String
283
283
 
284
284
  # Returns the rendered parameter list for a method.
285
285
  #
286
286
  # _@param_ `method_object` — Method being rendered.
287
287
  #
288
288
  # _@return_ — Parenthesized method signature.
289
- def method_signature: (untyped method_object) -> String
289
+ def method_signature: (Object method_object) -> String
290
290
 
291
291
  # Returns the access marker for an attribute.
292
292
  #
293
293
  # _@param_ `attribute` — Attribute reader or writer.
294
294
  #
295
295
  # _@return_ — Access mode marker such as `R`, `W`, or `RW`.
296
- def attribute_access: (untyped attribute) -> String
296
+ def attribute_access: (Object attribute) -> String
297
297
  end
298
298
 
299
299
  # Renders grouped Markdown sections for constants, attributes, and methods.
@@ -305,7 +305,7 @@ module YARD
305
305
  # _@param_ `group_order` — Preferred ordering for group headings.
306
306
  #
307
307
  # _@return_ — Markdown for the constants section.
308
- def render_constants: (::Array[untyped] constants, ::Array[String]? group_order) -> String
308
+ def render_constants: (Symbol constants, Symbol? group_order) -> String
309
309
 
310
310
  # Renders the attributes section for an object page.
311
311
  #
@@ -314,7 +314,7 @@ module YARD
314
314
  # _@param_ `group_order` — Preferred ordering for group headings.
315
315
  #
316
316
  # _@return_ — Markdown for the attributes section.
317
- def render_attributes: (::Array[untyped] attrs, ::Array[String]? group_order) -> String
317
+ def render_attributes: (Symbol attrs, Symbol? group_order) -> String
318
318
 
319
319
  # Renders a method section for an object page.
320
320
  #
@@ -325,7 +325,7 @@ module YARD
325
325
  # _@param_ `group_order` — Preferred ordering for group headings.
326
326
  #
327
327
  # _@return_ — Markdown for the method section.
328
- def render_methods: (String section_title, ::Array[untyped] methods, ::Array[String]? group_order) -> String
328
+ def render_methods: (String section_title, Symbol methods, Symbol? group_order) -> String
329
329
  end
330
330
 
331
331
  # Renders inheritance and mixin relationship summaries.
@@ -342,7 +342,7 @@ module YARD
342
342
  # _@param_ `object` — Object being rendered.
343
343
  #
344
344
  # _@return_ — Markdown summary of the object's relationships.
345
- def object_relationships: (untyped object) -> String
345
+ def object_relationships: (Object object) -> String
346
346
  end
347
347
  end
348
348
  end
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'csv'
3
+ require "csv"
4
4
 
5
- include Helpers::ModuleHelper
6
-
7
- include YARD::Markdown::ArefHelper
8
- include YARD::Markdown::ObjectListingHelper
5
+ class_eval do
6
+ include YARD::Templates::Helpers::ModuleHelper
7
+ include YARD::Markdown::ArefHelper
8
+ include YARD::Markdown::ObjectListingHelper
9
+ end
9
10
 
10
11
  # Prepares the markdown serializer and renders each object page.
11
12
  #
@@ -16,11 +17,11 @@ def init
16
17
  options.delete(:objects)
17
18
  options.delete(:files)
18
19
 
19
- options.serializer.extension = 'md'
20
+ options.serializer.extension = "md"
20
21
 
21
22
  objects.each do |object|
22
23
  Templates::Engine.with_serializer(object, options.serializer) { serialize(object) }
23
- rescue StandardError => e
24
+ rescue => e
24
25
  path = options.serializer.serialized_path(object)
25
26
  log.error "Exception occurred while generating '#{path}'"
26
27
  log.backtrace(e)
@@ -34,7 +35,7 @@ end
34
35
  # @param object [YARD::CodeObjects::NamespaceObject] Object whose page will be serialized.
35
36
  # @return [String] Rendered markdown for the object.
36
37
  def serialize(object)
37
- T('module').run(options.merge(object: object))
38
+ T("module").run(options.merge(object: object))
38
39
  end
39
40
 
40
41
  # Writes the CSV search index for all rendered objects.
@@ -44,16 +45,16 @@ end
44
45
  def serialize_index(objects)
45
46
  filepath = "#{options.serializer.basepath}/index.csv"
46
47
 
47
- CSV.open(filepath, 'wb') do |csv|
48
+ CSV.open(filepath, "wb") do |csv|
48
49
  csv << %w[name type path]
49
50
 
50
51
  objects.each do |object|
51
52
  next if object.name == :root
52
53
 
53
54
  if object.type == :class
54
- csv << [object.path, 'Class', options.serializer.serialized_path(object)]
55
+ csv << [object.path, "Class", options.serializer.serialized_path(object)]
55
56
  elsif object.type == :module
56
- csv << [object.path, 'Module', options.serializer.serialized_path(object)]
57
+ csv << [object.path, "Module", options.serializer.serialized_path(object)]
57
58
  end
58
59
 
59
60
  constants = constant_listing(object)
@@ -61,8 +62,8 @@ def serialize_index(objects)
61
62
  constants.each do |cnst|
62
63
  csv << [
63
64
  "#{object.path}.#{cnst.name(false)}",
64
- 'Constant',
65
- (options.serializer.serialized_path(object) + '#' + aref(cnst))
65
+ "Constant",
66
+ (options.serializer.serialized_path(object) + "#" + aref(cnst))
66
67
  ]
67
68
  end
68
69
  end
@@ -71,8 +72,8 @@ def serialize_index(objects)
71
72
  insmeths.each do |item|
72
73
  csv << [
73
74
  "#{object.path}.#{item.name(false)}",
74
- 'Method',
75
- options.serializer.serialized_path(object) + '#' + aref(item)
75
+ "Method",
76
+ options.serializer.serialized_path(object) + "#" + aref(item)
76
77
  ]
77
78
  end
78
79
  end
@@ -81,8 +82,8 @@ def serialize_index(objects)
81
82
  pubmeths.each do |item|
82
83
  csv << [
83
84
  "#{object.path}.#{item.name(false)}",
84
- 'Method',
85
- options.serializer.serialized_path(object) + '#' + aref(item)
85
+ "Method",
86
+ options.serializer.serialized_path(object) + "#" + aref(item)
86
87
  ]
87
88
  end
88
89
  end
@@ -92,8 +93,8 @@ def serialize_index(objects)
92
93
  attrs.each do |item|
93
94
  csv << [
94
95
  "#{object.path}.#{item.name(false)}",
95
- 'Attribute',
96
- options.serializer.serialized_path(object) + '#' + aref(item)
96
+ "Attribute",
97
+ options.serializer.serialized_path(object) + "#" + aref(item)
97
98
  ]
98
99
  end
99
100
  end
@@ -1,33 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pathname'
4
- require 'rdoc'
5
-
6
- include Helpers::ModuleHelper
7
- include YARD::Markdown::AnchorComponentHelper
8
- include YARD::Markdown::ArefHelper
9
- include YARD::Markdown::CollectionRenderingHelper
10
- include YARD::Markdown::DocumentationHelper
11
- include YARD::Markdown::HeadingHelper
12
- include YARD::Markdown::LinkNormalizationHelper
13
- include YARD::Markdown::MethodPresentationHelper
14
- include YARD::Markdown::ObjectListingHelper
15
- include YARD::Markdown::RelationshipSectionHelper
16
- include YARD::Markdown::SectionAssemblyHelper
17
- include YARD::Markdown::TagFormattingHelper
3
+ require "rdoc"
4
+
5
+ class_eval do
6
+ include YARD::Templates::Helpers::ModuleHelper
7
+ include YARD::Markdown::AnchorComponentHelper
8
+ include YARD::Markdown::ArefHelper
9
+ include YARD::Markdown::CollectionRenderingHelper
10
+ include YARD::Markdown::DocumentationHelper
11
+ include YARD::Markdown::HeadingHelper
12
+ include YARD::Markdown::LinkNormalizationHelper
13
+ include YARD::Markdown::MethodPresentationHelper
14
+ include YARD::Markdown::ObjectListingHelper
15
+ include YARD::Markdown::RelationshipSectionHelper
16
+ include YARD::Markdown::SectionAssemblyHelper
17
+ include YARD::Markdown::TagFormattingHelper
18
+ end
18
19
 
19
20
  # Registers the sections rendered for a namespace markdown page.
20
21
  #
21
22
  # @return [void]
22
23
  def init
23
24
  sections :header,
24
- :relationships,
25
- :docstring_section,
26
- :tags_section,
27
- :constants_section,
28
- :attributes_section,
29
- :public_class_methods_section,
30
- :public_instance_methods_section
25
+ :relationships,
26
+ :docstring_section,
27
+ :tags_section,
28
+ :constants_section,
29
+ :attributes_section,
30
+ :public_class_methods_section,
31
+ :public_instance_methods_section
31
32
  end
32
33
 
33
34
  # Renders the template and normalizes markdown for top-level page output.
@@ -89,7 +90,7 @@ end
89
90
  # @return [String] Markdown constants section, or an empty string.
90
91
  def constants_section
91
92
  constants = constant_listing(object).reject { |item| hidden_object?(item) }
92
- return '' unless constants.any?
93
+ return "" unless constants.any?
93
94
 
94
95
  render_section_content(render_constants(constants, Array(object.groups)))
95
96
  end
@@ -99,7 +100,7 @@ end
99
100
  # @return [String] Markdown attributes section, or an empty string.
100
101
  def attributes_section
101
102
  attrs = attr_listing(object).reject { |item| hidden_object?(item) }
102
- return '' unless attrs.any?
103
+ return "" unless attrs.any?
103
104
 
104
105
  render_section_content(render_attributes(attrs, Array(object.groups)))
105
106
  end
@@ -109,9 +110,9 @@ end
109
110
  # @return [String] Markdown public class methods section, or an empty string.
110
111
  def public_class_methods_section
111
112
  methods = public_class_methods(object)
112
- return '' unless methods.any?
113
+ return "" unless methods.any?
113
114
 
114
- render_section_content(render_methods('Public Class Methods', methods, Array(object.groups)))
115
+ render_section_content(render_methods("Public Class Methods", methods, Array(object.groups)))
115
116
  end
116
117
 
117
118
  # Renders the public instance methods section when methods are present.
@@ -119,7 +120,7 @@ end
119
120
  # @return [String] Markdown public instance methods section, or an empty string.
120
121
  def public_instance_methods_section
121
122
  methods = public_instance_methods(object)
122
- return '' unless methods.any?
123
+ return "" unless methods.any?
123
124
 
124
- render_section_content(render_methods('Public Instance Methods', methods, Array(object.groups)))
125
+ render_section_content(render_methods("Public Instance Methods", methods, Array(object.groups)))
125
126
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislav (Stas) Katkov
@@ -59,6 +59,7 @@ extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
61
  - ".editorconfig"
62
+ - ".standard.yml"
62
63
  - ".streerc"
63
64
  - ".yard-lint.yml"
64
65
  - ".yardopts"