-
Couldn't load subscription status.
- Fork 20
API Improvements #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
API Improvements #256
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| /** | ||
| /** | ||
| DietDoc/DDOC support routines | ||
|
|
||
| Copyright: © 2012-2016 RejectedSoftware e.K. | ||
|
|
@@ -191,6 +191,14 @@ class DdocComment { | |
| /// The macros contained in the "Macros" section (if any) | ||
| @property const(string[string]) macros() const { return m_macros; } | ||
|
|
||
| /** All sections of the comment that contain visible text in original order | ||
|
|
||
| Note that any "Macro" section is not included, whereas the special | ||
| sections "$Short", "$Long" and "Params" are included, just as any | ||
| user defined sections. | ||
| */ | ||
| @property const(Section)[] sections() const { return m_sections; } | ||
|
|
||
| bool hasSection(string name) const { return m_sections.canFind!(s => s.name == name); } | ||
|
|
||
| void renderSectionR(R)(ref R dst, DdocContext context, string name, int hlevel = 2) | ||
|
|
@@ -224,6 +232,26 @@ class DdocComment { | |
| renderSectionsR(dst, context, display_section, hlevel); | ||
| return dst.data; | ||
| } | ||
|
|
||
| /** Renders each parameter's description in the "Params" section individually. | ||
|
|
||
| While `renderSection` and the related overloads will render the whole | ||
| parameter section as an HTML table, this method allows to customize | ||
| the structure of the section. | ||
|
|
||
| Params: | ||
| context = Context implementation used to control the render process | ||
| on_parameter = Callback that gets invoked with the name and the | ||
| rendered description for each parameter | ||
| */ | ||
| void renderParameters(DdocContext context, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused or undocumented public API Should this rather return a helper struct that you can foreach on to be more idiomatic? (e.g. opApply) |
||
| void delegate(string, string) @safe on_parameter) | ||
| { | ||
| auto idx = m_sections.countUntil!(s => s.name == "Params"); | ||
| if (idx < 0) return; | ||
|
|
||
| .renderParameters(context, m_sections[idx], on_parameter); | ||
| } | ||
| } | ||
|
|
||
| enum DdocRenderOptions { | ||
|
|
@@ -270,8 +298,14 @@ private enum { | |
| SECTION | ||
| } | ||
|
|
||
| private struct Section { | ||
|
|
||
| /// Represents a single section within a Ddoc comment | ||
| struct Section { | ||
| /// Name of the section as specified in the Ddoc comment | ||
| string name; | ||
|
|
||
| /** Raw text contents of the section. | ||
| */ | ||
| string[] lines; | ||
|
|
||
| this(string name, string[] lines...) | ||
|
|
@@ -423,6 +457,39 @@ private void parseSection(R)(ref R dst, string sect, string[] lines, DdocContext | |
| } | ||
| } | ||
|
|
||
| private void renderParameters(DdocContext context, Section parms_section, | ||
| void delegate(string, string) @safe del) | ||
| { | ||
| string paramname; | ||
| string desc; | ||
|
|
||
| foreach (string ln; parms_section.lines) { | ||
| // check if the line starts a parameter documentation | ||
| string name; | ||
| auto eidx = ln.indexOf("="); | ||
| if (eidx > 0) name = ln[0 .. eidx].strip(); | ||
| if (!isIdent(name)) name = null; | ||
|
|
||
| // if it does, start a new row | ||
| if (name.length) { | ||
| if (paramname !is null) { | ||
| auto dst = appender!string; | ||
| renderTextLine(dst, desc, context); | ||
| del(paramname, dst.data); | ||
| } | ||
|
|
||
| desc = ln[eidx+1 .. $]; | ||
| paramname = name; | ||
| } else if (paramname !is null) desc ~= "\n" ~ ln; | ||
| } | ||
|
|
||
| if (paramname !is null) { | ||
| auto dst = appender!string; | ||
| renderTextLine(dst, desc, context); | ||
| del(paramname, dst.data); | ||
| } | ||
| } | ||
|
|
||
| private string highlightAndCrossLink(string line, DdocContext context) | ||
| { | ||
| auto dst = appender!string; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.