yard-markdown 0.4.2 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1c4368b70ec91bff1a8f9bf1aaefc79578a34251b879d800f59c466b611dd5a
4
- data.tar.gz: 917397c1e9df43930d699fe0258dd124260b5168222fc28c5d0a84ded9f21d1e
3
+ metadata.gz: 92bac83ffe7c1f83b26164adef991efe13678b96096ba61af2626f83e9505991
4
+ data.tar.gz: 7c871bffa551b5acc83e0b954163d933b7289db6542b1485c385ab97fb53e4eb
5
5
  SHA512:
6
- metadata.gz: 932de039cf4fbd5fadd8bf012f7663f6cda4b270100b7930a28d6e182949628b727705a47893daebb5b39cf4c630f5c3a4e2f7a8ff3e7609e2aa2a43172db00f
7
- data.tar.gz: 1d8191d7f0e0db8eea07842025a3dea14a924a67924464df8053ad00d337c9efb71ca832cafd3b83c2e6d150fa897c3ca08527744e86e043d4f3bd059db54898
6
+ metadata.gz: 7d7fb3ae97903f7c61aa0a057cdefd878a562264d15d5e7a3da17a5a2bdd5ea35c63cc47244022ab10fe20356c7adf367eee27e1de5b67281376174645c29b54
7
+ data.tar.gz: 126033d377d8e652a19b33731d57ccfad197731cf819521766dbee5b37d1ee293baf41fc58c7927073ae3cddea9c5a4227b57539023de96ff66740e3d53e88d7
data/.yardopts CHANGED
@@ -1,8 +1 @@
1
1
  --load ./lib/yard-markdown.rb
2
- --format markdown
3
- --markup markdown
4
- --output-dir example
5
- --private
6
- --protected
7
- -
8
- example.rb
data/README.md CHANGED
@@ -1,11 +1,15 @@
1
1
  # Yard::Markdown
2
2
 
3
- Yard plugin to generate markdown documentation
3
+ Yard plugin to output markdown documentation.
4
+
5
+ ## Motivation
6
+ Markdown has become the de-facto documentation standard. I heavily rely on Obsidian to render my storage of markdown notes. But markdown is used not just for scribbles, supported is far and wide. We can render markdown file on any device, probably even on thermometer with a screen. But also everyone knows enough markdown to be dangerous (or productive).
7
+ It's a pitty that rdoc and yard can't output a proper markdown file. I would like to change that.
4
8
 
5
9
  ## Goals:
6
10
  - Compatible with Github Flavored Markdown
11
+ - Produce .csv index file
7
12
  - Mimick yard html layout where it makes sense to maintain familiarity
8
- - Produce .csv index file alonside markdown documentation to act as file index
9
13
 
10
14
  ## Usage
11
15
  Yard doesn't load plugin by default, so you need to load plugin through `~/.yard/config`:
@@ -24,14 +28,49 @@ gem install yard-markdown
24
28
 
25
29
  Run `yardoc --format=markdown` to generate markdown documentation.
26
30
 
27
- ## Backstory
28
- This is a successor to [rdoc-mardown gem](https://github.com/skatkov/rdoc-markdown/tree/main/example). These docsets are used in [POSH TUI](https://poshtui.com).
31
+ ## Note on RDoc support
32
+ 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
+
34
+ If you know how to improve that, please get in touch or submit a patch.
35
+
36
+ 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
+
38
+ ## Note on index.csv file
39
+ This gem emits index of all markdown files in a index.csv file.
40
+
41
+ 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
+
43
+ In my personal use-case, I use SQLite. All other databases seem to have a good support for CSV imports.
29
44
 
30
45
  ## Testing
31
- Unit tests can't really test this gem properly. So it's semi-manual process of making changes and reviewing output.
46
+ Unit tests verify renderer behavior, index links, and anchor consistency for both YARD-style and RDoc-style sources.
47
+
48
+ Run:
49
+
50
+ ```bash
51
+ bundle exec rake test
52
+ ```
53
+
54
+ Regenerate local sample docs:
55
+
56
+ ```bash
57
+ bundle exec rake examples:generate
58
+ ```
59
+
60
+ Validate generated markdown in sample docs:
61
+
62
+ ```bash
63
+ bundle exec rake markdown:validate_examples
64
+ ```
65
+
66
+ There is also a real-world validation harness for repositories with substantial YARD documentation (`rspec-core`, `sidekiq`):
67
+
68
+ ```bash
69
+ bundle exec rake markdown:validate_real_world
70
+ ```
71
+
72
+ This task validates generated markdown against CommonMark + GFM rendering, and reports unresolved local links found in upstream source comments while still validating local anchor/link structure.
32
73
 
33
- ### Testing Rdoc conversion to markdown:
34
- `yardoc example_rdoc.rb` -> outputs everything into example/ folder.
74
+ GitHub Actions CI now runs this task on every push/PR, so `sidekiq` and other real-world fixture gems are verified continuously.
35
75
 
36
- ### Testing Yard conversion to markdown:
37
- `yardoc example_yard.rb` -> outputs everything into example/ folder.
76
+ For reproducible checks, the task clones pinned tags (`rspec-core` `v3.13.2`, `sidekiq` `v7.3.10`) into `tmp/real-world/repos` before generating output.
data/Rakefile CHANGED
@@ -1,8 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "fileutils"
4
+ require "open3"
5
+ require "shellwords"
6
+
3
7
  require "bundler/gem_tasks"
4
8
  require "rake/testtask"
5
9
 
10
+ require_relative "test/support/markdown_validator"
11
+
6
12
  Rake::TestTask.new(:test) do |t|
7
13
  t.libs << "test"
8
14
  t.libs << "lib"
@@ -10,3 +16,140 @@ Rake::TestTask.new(:test) do |t|
10
16
  end
11
17
 
12
18
  task default: %i[test stree:write]
19
+
20
+ def shell_escape(path)
21
+ Shellwords.escape(path)
22
+ end
23
+
24
+ COMMAND_WARNING_REGEX = /\bwarning:/i
25
+ COMMAND_ERROR_REGEX = /\b(?:error|exception|fatal|loaderror)\b/i
26
+
27
+ def analyze_command_output(text)
28
+ lines = text.each_line.map(&:strip).reject(&:empty?)
29
+ {
30
+ warnings: lines.grep(COMMAND_WARNING_REGEX),
31
+ errors: lines.grep(COMMAND_ERROR_REGEX)
32
+ }
33
+ end
34
+
35
+ def command_log_path(label)
36
+ safe_label = label.gsub(%r{[^a-zA-Z0-9_-]+}, "_")
37
+ File.join("tmp", "command-logs", "#{safe_label}.log")
38
+ end
39
+
40
+ def run_command_with_analysis(command, label:)
41
+ puts command
42
+
43
+ stdout, stderr, status = Open3.capture3(command)
44
+ combined_output = [stdout, stderr].reject(&:empty?).join("\n")
45
+ log_path = command_log_path(label)
46
+
47
+ FileUtils.mkdir_p(File.dirname(log_path))
48
+ File.write(log_path, combined_output)
49
+
50
+ puts combined_output unless combined_output.empty?
51
+
52
+ stdout_analysis = analyze_command_output(stdout)
53
+ stderr_analysis = analyze_command_output(stderr)
54
+ combined_analysis = {
55
+ warnings: stdout_analysis[:warnings] + stderr_analysis[:warnings],
56
+ errors: stdout_analysis[:errors] + stderr_analysis[:errors]
57
+ }
58
+
59
+ puts "Output analysis for #{label}: warnings=#{combined_analysis[:warnings].size}, errors=#{combined_analysis[:errors].size}"
60
+
61
+ return if status.success? && combined_analysis[:errors].empty?
62
+
63
+ details = ["#{label} failed output checks (log: #{log_path})"]
64
+ details << "exit status: #{status.exitstatus}" unless status.success?
65
+ details << "errors: #{combined_analysis[:errors].first(5).join(' | ')}" unless combined_analysis[:errors].empty?
66
+ raise details.join("\n")
67
+ end
68
+
69
+ def generate_markdown_docs(source, output_dir)
70
+ FileUtils.rm_rf(output_dir)
71
+ FileUtils.mkdir_p(output_dir)
72
+
73
+ command = "yardoc --no-stats --quiet --format markdown --load ./lib/yard-markdown.rb --output-dir #{shell_escape(output_dir)} #{shell_escape(source)}"
74
+ run_command_with_analysis(command, label: "yardoc_#{output_dir}")
75
+ end
76
+
77
+ def checkout_repo(url, destination, ref: nil)
78
+ FileUtils.rm_rf(destination)
79
+ FileUtils.mkdir_p(File.dirname(destination))
80
+
81
+ command = "git clone --depth 1"
82
+ command += " --branch #{shell_escape(ref)}" if ref
83
+ command += " #{shell_escape(url)} #{shell_escape(destination)}"
84
+ run_command_with_analysis(command, label: "git_clone_#{destination}")
85
+ end
86
+
87
+
88
+ namespace :examples do
89
+ desc "Generate basic example documentation using yard-markdown plugin"
90
+ task :generate do
91
+ Rake::Task["examples:yard"].invoke
92
+ Rake::Task["examples:rdoc"].invoke
93
+ end
94
+
95
+ desc "Generate example documentation for code annotated with yard"
96
+ task :yard do
97
+ generate_markdown_docs("example_yard.rb", "example/yard")
98
+ end
99
+
100
+ desc "Generate example documentation for code annotated with rdoc"
101
+ task :rdoc do
102
+ generate_markdown_docs("example_rdoc.rb", "example/rdoc")
103
+ end
104
+ end
105
+
106
+ namespace :real_world do
107
+ REPOS_DIR = "tmp/real-world/repos"
108
+ RSPEC_REPO = "#{REPOS_DIR}/rspec-core"
109
+ SIDEKIQ_REPO = "#{REPOS_DIR}/sidekiq"
110
+
111
+ desc "Checkout rspec-core repository"
112
+ task :checkout_rspec do
113
+ checkout_repo("https://github.com/rspec/rspec-core.git", RSPEC_REPO, ref: "v3.13.2")
114
+ end
115
+
116
+ desc "Checkout sidekiq repository"
117
+ task :checkout_sidekiq do
118
+ checkout_repo("https://github.com/sidekiq/sidekiq.git", SIDEKIQ_REPO, ref: "v7.3.10")
119
+ end
120
+
121
+ desc "Generate markdown docs for rspec-core"
122
+ task rspec: :checkout_rspec do
123
+ generate_markdown_docs("#{RSPEC_REPO}/lib", "tmp/real-world/rspec-core")
124
+ end
125
+
126
+ desc "Generate markdown docs for sidekiq"
127
+ task sidekiq: :checkout_sidekiq do
128
+ generate_markdown_docs("#{SIDEKIQ_REPO}/lib", "tmp/real-world/sidekiq")
129
+ end
130
+
131
+ desc "Generate markdown docs for rspec-core and sidekiq"
132
+ task :generate do
133
+ Rake::Task["real_world:rspec"].invoke
134
+ Rake::Task["real_world:sidekiq"].invoke
135
+ end
136
+ end
137
+
138
+ namespace :markdown do
139
+ desc "Validate checked-in example markdown output"
140
+ task validate_examples: "examples:generate" do
141
+ ["example/yard", "example/rdoc"].each do |dir|
142
+ file_count = MarkdownValidator.new(dir).validate!
143
+ puts "Validated #{file_count} markdown files in #{dir}"
144
+ end
145
+ end
146
+
147
+ desc "Generate and validate markdown output for rspec-core and sidekiq"
148
+ task validate_real_world: "real_world:generate" do
149
+ ["tmp/real-world/rspec-core", "tmp/real-world/sidekiq"].each do |dir|
150
+ validator = MarkdownValidator.new(dir, strict_links: false)
151
+ file_count = validator.validate!
152
+ puts "Validated #{file_count} markdown files in #{dir} (unresolved local links: #{validator.unresolved_links})"
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,25 @@
1
+ # Class Bird <a id="class-Bird"></a>
2
+
3
+ **Inherits:** `Object`
4
+
5
+ The base class for all birds.
6
+
7
+ ## Public Instance Methods
8
+ ### `fly(direction, velocity)` <a id="method-i-fly"></a> <a id="fly-instance_method"></a>
9
+ Fly somewhere.
10
+
11
+ Flying is the most critical feature of birds.
12
+
13
+ :args: direction, velocity
14
+
15
+ :call-seq:
16
+ Bird.fly(symbol, number) -> bool
17
+ Bird.fly(string, number) -> bool
18
+
19
+ # Example
20
+
21
+ fly(:south, 70)
22
+
23
+ ### `speak()` <a id="method-i-speak"></a> <a id="speak-instance_method"></a>
24
+ Produce some noise. -- FIXME: maybe extract this to a base class `Animal`? ++
25
+ - **@yield** ["tweet"]
@@ -0,0 +1,59 @@
1
+ # Class Duck <a id="class-Duck"></a>
2
+
3
+ **Inherits:** `Object`
4
+ **Extended by:** `Animal`
5
+ **Includes:** `Waterfowl`
6
+
7
+ A duck is a Waterfowl Bird.
8
+
9
+ Features:
10
+
11
+ bird::
12
+
13
+ * speak
14
+ * fly
15
+
16
+ waterfowl::
17
+
18
+ * swim
19
+
20
+ ## Constants
21
+ ### `@@rubber_ducks` <a id="classvariable--40-40rubber_ducks"></a> <a id="@@rubber_ducks-classvariable"></a>
22
+ Global list of all rubber ducks.
23
+
24
+ Use when in trouble.
25
+
26
+ ### `MAX_VELOCITY` <a id="constant-MAX_VELOCITY"></a> <a id="MAX_VELOCITY-constant"></a>
27
+ Maximum velocity for a flying duck.
28
+
29
+ ## Attributes
30
+ ### `domestic` [RW] <a id="attribute-i-domestic"></a> <a id="domestic-instance_method"></a>
31
+ True for domestic ducks.
32
+
33
+ ### `rubber` [R] <a id="attribute-i-rubber"></a> <a id="rubber-instance_method"></a>
34
+ True for rubber ducks.
35
+
36
+ ## Public Class Methods
37
+ ### `rubber_ducks()` <a id="method-c-rubber_ducks"></a> <a id="rubber_ducks-class_method"></a>
38
+ - **@return** [Array<Duck>] list of all rubber ducks
39
+
40
+ ## Public Instance Methods
41
+ ### `initialize(domestic, rubber)` <a id="method-i-initialize"></a> <a id="initialize-instance_method"></a>
42
+ Creates a new duck.
43
+ - **@param** `domestic` [Boolean]
44
+ - **@param** `rubber` [Boolean]
45
+ - **@return** [Duck] a new instance of Duck
46
+
47
+ ### `speak()` <a id="method-i-speak"></a> <a id="speak-instance_method"></a>
48
+ Duck overrides generic implementation.
49
+ - **@yield** [speech]
50
+
51
+ ### `swim()` <a id="method-i-swim"></a> <a id="swim-instance_method"></a>
52
+ Swimming helper.
53
+
54
+ ### `useful?()` <a id="method-i-useful-3F"></a> <a id="useful?-instance_method"></a>
55
+ Checks if this duck is a useful one.
56
+
57
+ :call-seq:
58
+ Bird.useful? -> bool
59
+ - **@return** [Boolean]
@@ -0,0 +1,7 @@
1
+ # Module Waterfowl <a id="module-Waterfowl"></a>
2
+
3
+ A mixin for waterfowl creatures.
4
+
5
+ ## Public Instance Methods
6
+ ### `swim()` <a id="method-i-swim"></a> <a id="swim-instance_method"></a>
7
+ Swimming helper.
@@ -0,0 +1,16 @@
1
+ name,type,path
2
+ Waterfowl,Module,Waterfowl.md
3
+ Waterfowl.swim,Method,Waterfowl.md#method-i-swim
4
+ Bird,Class,Bird.md
5
+ Bird.fly,Method,Bird.md#method-i-fly
6
+ Bird.speak,Method,Bird.md#method-i-speak
7
+ Duck,Class,Duck.md
8
+ Duck.MAX_VELOCITY,Constant,Duck.md#constant-MAX_VELOCITY
9
+ Duck.@@rubber_ducks,Constant,Duck.md#classvariable--40-40rubber_ducks
10
+ Duck.initialize,Method,Duck.md#method-i-initialize
11
+ Duck.speak,Method,Duck.md#method-i-speak
12
+ Duck.swim,Method,Duck.md#method-i-swim
13
+ Duck.useful?,Method,Duck.md#method-i-useful-3F
14
+ Duck.rubber_ducks,Method,Duck.md#method-c-rubber_ducks
15
+ Duck.domestic,Attribute,Duck.md#attribute-i-domestic
16
+ Duck.rubber,Attribute,Duck.md#attribute-i-rubber
@@ -0,0 +1,8 @@
1
+ # Module Aquatic <a id="module-Aquatic"></a>
2
+
3
+ A mixin for aquatic creatures.
4
+
5
+ ## Public Instance Methods
6
+ ### `swim()` <a id="method-i-swim"></a> <a id="swim-instance_method"></a>
7
+ Swim in the water.
8
+ - **@return** [void]
@@ -0,0 +1,25 @@
1
+ # Class Fish <a id="class-Fish"></a>
2
+
3
+ **Inherits:** `Object`
4
+
5
+ The base class for all fish.
6
+
7
+ ## Public Instance Methods
8
+ ### `make_sound()` <a id="method-i-make_sound"></a> <a id="make_sound-instance_method"></a>
9
+ Make a sound.
10
+ - **@return** [void]
11
+ - **@yield** [sound] The sound produced by the fish
12
+ - **@yieldparam** `sound` [String] The actual sound
13
+
14
+ ### `swim(direction, speed)` <a id="method-i-swim"></a> <a id="swim-instance_method"></a>
15
+ Swim in a specific direction.
16
+
17
+ Swimming is the most critical feature of fish.
18
+ - **@param** `direction` [Symbol, String] The direction to swim
19
+ - **@param** `speed` [Integer] The speed at which to swim
20
+ - **@return** [Boolean] Whether the swim was successful
21
+
22
+ **@example**
23
+ ```ruby
24
+ swim(:north, 30)
25
+ ```
@@ -0,0 +1,58 @@
1
+ # Class Salmon <a id="class-Salmon"></a>
2
+
3
+ **Inherits:** `Fish`
4
+ **Includes:** `Aquatic`
5
+
6
+ A salmon is an Aquatic Fish.
7
+
8
+ ## Features
9
+
10
+ * **Fish**
11
+ * make_sound
12
+ * swim
13
+ * **Aquatic**
14
+ * swim (overridden)
15
+
16
+ ## Constants
17
+ ### Salmon specific attributes
18
+ #### `MAX_SPEED` <a id="constant-MAX_SPEED"></a> <a id="MAX_SPEED-constant"></a>
19
+ - **@return** [Integer] Maximum speed for a swimming salmon
20
+ ### General
21
+ #### `@@wild_salmon` <a id="classvariable--40-40wild_salmon"></a> <a id="@@wild_salmon-classvariable"></a>
22
+ Global list of all wild salmon.
23
+
24
+ Use for conservation efforts.
25
+
26
+ ## Attributes
27
+ ### Salmon specific attributes
28
+ #### `farmed` [RW] <a id="attribute-i-farmed"></a> <a id="farmed-instance_method"></a>
29
+ - **@return** [Boolean] True for farmed salmon
30
+
31
+ #### `wild` [R] <a id="attribute-i-wild"></a> <a id="wild-instance_method"></a>
32
+ - **@return** [Boolean] True for wild salmon
33
+
34
+ ## Public Class Methods
35
+ ### `wild_salmon()` <a id="method-c-wild_salmon"></a> <a id="wild_salmon-class_method"></a>
36
+ - **@return** [Array<Salmon>] List of all wild salmon
37
+
38
+ ## Public Instance Methods
39
+ ### Fish overrides
40
+ #### `make_sound()` <a id="method-i-make_sound"></a> <a id="make_sound-instance_method"></a>
41
+ Salmon overrides generic implementation.
42
+ - **@return** [void]
43
+ - **@yield** [sound] The sound produced by the salmon
44
+ - **@yieldparam** `sound` [String] The actual sound
45
+ ### General
46
+ #### `initialize(farmed, wild)` <a id="method-i-initialize"></a> <a id="initialize-instance_method"></a>
47
+ Creates a new salmon.
48
+ - **@param** `farmed` [Boolean] Whether the salmon is farmed
49
+ - **@param** `wild` [Boolean] Whether the salmon is wild
50
+ - **@return** [Salmon] a new instance of Salmon
51
+
52
+ #### `sustainable?()` <a id="method-i-sustainable-3F"></a> <a id="sustainable?-instance_method"></a>
53
+ Checks if this salmon is sustainable.
54
+ - **@return** [Boolean] Whether the salmon is sustainable
55
+
56
+ #### `swim()` <a id="method-i-swim"></a> <a id="swim-instance_method"></a>
57
+ Swim in the water.
58
+ - **@return** [void]
@@ -0,0 +1,16 @@
1
+ name,type,path
2
+ Aquatic,Module,Aquatic.md
3
+ Aquatic.swim,Method,Aquatic.md#method-i-swim
4
+ Fish,Class,Fish.md
5
+ Fish.make_sound,Method,Fish.md#method-i-make_sound
6
+ Fish.swim,Method,Fish.md#method-i-swim
7
+ Salmon,Class,Salmon.md
8
+ Salmon.MAX_SPEED,Constant,Salmon.md#constant-MAX_SPEED
9
+ Salmon.@@wild_salmon,Constant,Salmon.md#classvariable--40-40wild_salmon
10
+ Salmon.initialize,Method,Salmon.md#method-i-initialize
11
+ Salmon.make_sound,Method,Salmon.md#method-i-make_sound
12
+ Salmon.sustainable?,Method,Salmon.md#method-i-sustainable-3F
13
+ Salmon.swim,Method,Salmon.md#method-i-swim
14
+ Salmon.wild_salmon,Method,Salmon.md#method-c-wild_salmon
15
+ Salmon.farmed,Attribute,Salmon.md#attribute-i-farmed
16
+ Salmon.wild,Attribute,Salmon.md#attribute-i-wild