From a16ca3a2d4e9d9218ed4d80aa7577050862eed23 Mon Sep 17 00:00:00 2001 From: Stanislav Katkov Date: Thu, 16 Nov 2023 01:41:44 +0100 Subject: [PATCH] adding constants --- example/Bird.md | 5 ++ example/Duck.md | 5 ++ example/Waterfowl.md | 5 ++ templates/default/fulldoc/markdown/setup.rb | 53 ++++++++++++++++++++- 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/example/Bird.md b/example/Bird.md index 4433291..7bcf13d 100644 --- a/example/Bird.md +++ b/example/Bird.md @@ -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. diff --git a/example/Duck.md b/example/Duck.md index ad9fef2..b6a0c36 100644 --- a/example/Duck.md +++ b/example/Duck.md @@ -11,3 +11,8 @@ Features: waterfowl:: * swim + +## Constant +| Name | Value | Description | +| ---- | ---- | ----------- | +|DEFAULT_DUCK_VELOCITY | 70 | Default velocity for a flying duck. diff --git a/example/Waterfowl.md b/example/Waterfowl.md index 8461fb2..5b51841 100644 --- a/example/Waterfowl.md +++ b/example/Waterfowl.md @@ -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. diff --git a/templates/default/fulldoc/markdown/setup.rb b/templates/default/fulldoc/markdown/setup.rb index 00ae34a..67a67ea 100644 --- a/templates/default/fulldoc/markdown/setup.rb +++ b/templates/default/fulldoc/markdown/setup.rb @@ -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