Skip to content

Commit

Permalink
adding constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Katkov committed Nov 16, 2023
1 parent 56de789 commit a16ca3a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
5 changes: 5 additions & 0 deletions example/Bird.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# Class: Bird
The base class for all birds.

## Constant
| Name | Value | Description |
| ---- | ---- | ----------- |
|DEFAULT_DUCK_VELOCITY | 70 | Default velocity for a flying duck.
5 changes: 5 additions & 0 deletions example/Duck.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ Features:
waterfowl::

* swim

## Constant
| Name | Value | Description |
| ---- | ---- | ----------- |
|DEFAULT_DUCK_VELOCITY | 70 | Default velocity for a flying duck.
5 changes: 5 additions & 0 deletions example/Waterfowl.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# Module: Waterfowl
A mixin for waterfowl creatures.

## Constant
| Name | Value | Description |
| ---- | ---- | ----------- |
|DEFAULT_DUCK_VELOCITY | 70 | Default velocity for a flying duck.
53 changes: 51 additions & 2 deletions templates/default/fulldoc/markdown/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,57 @@ def init

def serialize(object)
template = ERB.new(%q{# <%= format_object_title object %>
<%= object.docstring %>
}.gsub(/^ /, ''))
<%= object.docstring %>
<% if constant_listing.size > 0 %>
<% groups(constant_listing, "Constant") do |list, name| %>
## <%= name %>
| Name | Value | Description |
| ---- | ---- | ----------- |
<% list.each do |cnst| %>
|<%= cnst.name %> | <%= cnst.value %> | <%= cnst.docstring %>
<% end %>
<% end %>
<% end %>
}.gsub(/^ /, ''), trim_mode: "%<>")

template.result(binding)
end

def constant_listing
return @constants if defined?(@constants) && @constants
@constants = object.constants(:included => false, :inherited => false)
@constants += object.cvars
@constants
end

def groups(list, type = "Method")
groups_data = object.groups
if groups_data
list.each {|m| groups_data |= [m.group] if m.group && owner != m.namespace }
others = list.select {|m| !m.group || !groups_data.include?(m.group) }
groups_data.each do |name|
items = list.select {|m| m.group == name }
yield(items, name) unless items.empty?
end
else
others = []
group_data = {}
list.each do |itm|
if itm.group
(group_data[itm.group] ||= []) << itm
else
others << itm
end
end
group_data.each {|group, items| yield(items, group) unless items.empty? }
end

return if others.empty?
if others.first.respond_to?(:scope)
scopes(others) {|items, scope| yield(items, "#{scope.to_s.capitalize} #{type}") }
else
yield(others, type)
end
end

0 comments on commit a16ca3a

Please sign in to comment.