Skip to content

Commit

Permalink
Better list of Constants (#21)
Browse files Browse the repository at this point in the history
Use markdown table to render list of constants (name and default value).

I, so far, didn't figure out how to add comment for constant (docstring is missing).
  • Loading branch information
skatkov authored Dec 16, 2024
1 parent b23b80a commit d2cd281
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
yard-markdown (0.4)
yard-markdown (0.4.1)
csv
yard

Expand Down
12 changes: 5 additions & 7 deletions example/Aquatic.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ A mixin for aquatic creatures.
## swim() [](#method-i-swim)
Swim in the water.

**return** [void]
**@return** [void]


# Constants
## DEFAULT_SALMON_SPEED [](#constant-DEFAULT_SALMON_SPEED)


## MAX_DEPTH [](#constant-MAX_DEPTH)


| Name | Default Value |
| --- | --- |
| [DEFAULT_SALMON_SPEED](#constant-DEFAULT_SALMON_SPEED) | 20 |
| [MAX_DEPTH](#constant-MAX_DEPTH) | 500 |
24 changes: 11 additions & 13 deletions example/Fish.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@ The base class for all fish.
## make_sound() [](#method-i-make_sound)
Make a sound.

**return** [void]
**yield** [sound] The sound produced by the fish
**yieldparam** [String] The actual sound
**@return** [void]
**@yield** [sound] The sound produced by the fish
**@yieldparam** [String] The actual sound
## swim(direction, speed) [](#method-i-swim)
Swim in a specific direction.

Swimming is the most critical feature of fish.

**param** [Symbol, String] The direction to swim
**param** [Integer] The speed at which to swim
**return** [Boolean] Whether the swim was successful
**@param** [Symbol, String] The direction to swim
**@param** [Integer] The speed at which to swim
**@return** [Boolean] Whether the swim was successful

**example**
**@example**
```ruby
swim(:north, 30)
```

# Constants
## DEFAULT_SALMON_SPEED [](#constant-DEFAULT_SALMON_SPEED)


## MAX_DEPTH [](#constant-MAX_DEPTH)


| Name | Default Value |
| --- | --- |
| [DEFAULT_SALMON_SPEED](#constant-DEFAULT_SALMON_SPEED) | 20 |
| [MAX_DEPTH](#constant-MAX_DEPTH) | 500 |
32 changes: 15 additions & 17 deletions example/Salmon.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,38 @@ A salmon is an Aquatic Fish.
## initialize(farmed, wild) [](#method-i-initialize)
Creates a new salmon.

**param** [Boolean] Whether the salmon is farmed
**param** [Boolean] Whether the salmon is wild
**return** [Salmon] a new instance of Salmon
**@param** [Boolean] Whether the salmon is farmed
**@param** [Boolean] Whether the salmon is wild
**@return** [Salmon] a new instance of Salmon
## make_sound() [](#method-i-make_sound)
Salmon overrides generic implementation.

**return** [void]
**yield** [sound] The sound produced by the salmon
**yieldparam** [String] The actual sound
**@return** [void]
**@yield** [sound] The sound produced by the salmon
**@yieldparam** [String] The actual sound
## sustainable?() [](#method-i-sustainable?)
Checks if this salmon is sustainable.

**return** [Boolean] Whether the salmon is sustainable
**@return** [Boolean] Whether the salmon is sustainable
## swim() [](#method-i-swim)
Swim in the water.

**return** [void]
**@return** [void]

# Public Class Methods
## wild_salmon() [](#method-c-wild_salmon)
**return** [Array<Salmon>] List of all wild salmon
**@return** [Array<Salmon>] List of all wild salmon

# Attributes
## farmed[RW] [](#attribute-i-farmed)

**return** [Boolean] True for farmed salmon
**@return** [Boolean] True for farmed salmon
## wild[RW] [](#attribute-i-wild)

**return** [Boolean] True for wild salmon
**@return** [Boolean] True for wild salmon

# Constants
## DEFAULT_SALMON_SPEED [](#constant-DEFAULT_SALMON_SPEED)


## MAX_DEPTH [](#constant-MAX_DEPTH)


| Name | Default Value |
| --- | --- |
| [DEFAULT_SALMON_SPEED](#constant-DEFAULT_SALMON_SPEED) | 20 |
| [MAX_DEPTH](#constant-MAX_DEPTH) | 500 |
13 changes: 2 additions & 11 deletions example_yard.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# @title YARD Markdown Example
# @description This example demonstrates various YARD features using markdown formatting.
#
# ## Links
#
# 1. [YARD Documentation](https://yardoc.org/)
# 2. [Markdown Syntax](https://daringfireball.net/projects/markdown/syntax)

# A mixin for aquatic creatures.
#
module Aquatic
# Swim in the water.
#
Expand Down Expand Up @@ -135,11 +128,9 @@ def environmentally_friendly?
end
end

# @!constant [Integer] DEFAULT_SALMON_SPEED
# Default speed for a swimming salmon
# Default speed for a swimming salmon
DEFAULT_SALMON_SPEED = 20

# @!constant [Integer] MAX_DEPTH
# Maximum depth for salmon habitat
MAX_DEPTH = 500

Expand Down
19 changes: 7 additions & 12 deletions templates/default/fulldoc/markdown/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,29 +126,24 @@ def serialize(object)
## <%= item.name(false) %>(<%= item.parameters.map {|p| p.join(" ") }.join(", ") %>) [](#<%=aref(item)%>)
<%= rdoc_to_md item.docstring %>
<%= render_tags item %>
<% end %>
<% end %>
<% end %><% end %>
<% if (attrs = attr_listing(object)).size > 0 %>
# Attributes
<% attrs.each do |item|%>
## <%= item.name %><%= item.reader? ? "[RW]" : "[R]" %> [](#<%=aref(item)%>)
<%= rdoc_to_md item.docstring %>
<%= render_tags item %>
<% end %>
<% end %>
<% end %><% end %>
<% if constant_listing.size > 0 %>
<% groups(constant_listing, "Constants") do |list, name| %>
# <%= name %>
<% if list.size > 0 %>
| Name | Default Value |
| --- | --- |
<% list.each do |cnst| %>
## <%= cnst.name %> [](#<%=aref(cnst)%>)
<%= rdoc_to_md cnst.docstring %>
<%= render_tags cnst %>
<% end %><% end %><% end %>',
| [<%= cnst.name %>](#<%=aref(cnst)%>) | <%= cnst.value %> |
<% end %><% end %><% end %><% end %>',
trim_mode: "<>",
)

Expand Down
2 changes: 1 addition & 1 deletion yard-markdown.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |spec|
spec.name = "yard-markdown"
spec.version = "0.4"
spec.version = "0.4.1"
spec.authors = ["Stanislav (Stas) Katkov"]
spec.email = ["yard-markdown@skatkov.com"]

Expand Down

0 comments on commit d2cd281

Please sign in to comment.