Skip to content

Commit

Permalink
📝 🐛 Fix generated doc references
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Dec 27, 2023
1 parent 2046e37 commit 870ac79
Show file tree
Hide file tree
Showing 22 changed files with 68 additions and 43 deletions.
4 changes: 2 additions & 2 deletions docs/templates/dnd5e/QuteMonster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ See [ImmuneResist#resist](../ImmuneResist.md#resist)

### savesSkills

Creature saving throws and skill modifiers as [SavesAndSkills](../SavesAndSkills.md)
Creature saving throws and skill modifiers as [SavesAndSkills](SavesAndSkills.md)

### savingThrows

Expand Down Expand Up @@ -175,7 +175,7 @@ Creature speed as a comma-separated list

### spellcasting

Creature abilities as a list of [Spellcasting](../Spellcasting.md) attributes
Creature abilities as a list of [Spellcasting](Spellcasting.md) attributes

### subtype

Expand Down
2 changes: 1 addition & 1 deletion docs/templates/dnd5e/QuteMonster/Spellcasting.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Name: "Spellcasting" or "Innate Spellcasting"

### spells

Map: key = spell level, value: spell level information as [Spells](../QuteSpell/Spells.md)
Map: key = spell level, value: spell level information as [Spells](Spells.md)

### will

Expand Down
8 changes: 4 additions & 4 deletions docs/templates/dnd5e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
- [ImmuneResist](ImmuneResist.md): 5eTools vulnerabilities, resistances, immunities, and condition immunities
- [QuteBackground](QuteBackground.md): 5eTools background attributes (`background2md.txt`).
- [QuteClass](QuteClass.md): 5eTools class attributes (`class2md.txt`)
- [QuteDeck](QuteDeck.md): 5eTools deck attributes (`deck2md.txt`)
- [QuteDeck](QuteDeck/README.md): 5eTools deck attributes (`deck2md.txt`)
- [QuteDeity](QuteDeity.md): 5eTools deity attributes (`deity2md.txt`)
- [QuteFeat](QuteFeat.md): 5eTools feat and optional feat attributes (`feat2md.txt`)
- [QuteHazard](QuteHazard.md): 5eTools hazard attributes (`hazard2md.txt`)
- [QuteItem](QuteItem.md): 5eTools item attributes (`item2md.txt`)
- [QuteMonster](QuteMonster.md): 5eTools creature attributes (`monster2md.txt`)
- [QuteItem](QuteItem/README.md): 5eTools item attributes (`item2md.txt`)
- [QuteMonster](QuteMonster/README.md): 5eTools creature attributes (`monster2md.txt`)
- [QuteObject](QuteObject.md): 5eTools object attributes (`object2md.txt`)
- [QutePsionic](QutePsionic.md): 5eTools psionic talent attributes (`psionic2md.txt`)
- [QuteRace](QuteRace.md): 5eTools race attributes (`race2md.txt`)
- [QuteReward](QuteReward.md): 5eTools reward attributes (`reward2md.txt`)
- [QuteSpell](QuteSpell.md): 5eTools spell attributes (`spell2md.txt`)
- [QuteSubclass](QuteSubclass.md): 5eTools subclass attributes (`subclass2md.txt`)
- [QuteVehicle](QuteVehicle.md): 5eTools vehicle attributes (`vehicle2md.txt`)
- [QuteVehicle](QuteVehicle/README.md): 5eTools vehicle attributes (`vehicle2md.txt`)
- [Tools5eQuteBase](Tools5eQuteBase.md): Attributes for notes that are generated from the 5eTools data.
- [Tools5eQuteNote](Tools5eQuteNote.md): Attributes for notes that are generated from the 5eTools data.
2 changes: 1 addition & 1 deletion docs/templates/pf2e/QuteAbility.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Return a comma-separated list of trait links

### traits

Collection of trait links. Use `{#for}` or `{#each}` to iterate over the collection. See [traitList](#traitList) or [bareTraitList](#bareTraitList).
Collection of trait links. Use `{#for}` or `{#each}` to iterate over the collection. See [traitList](#traitlist) or [bareTraitList](#baretraitlist).

### trigger

Expand Down
18 changes: 9 additions & 9 deletions docs/templates/pf2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
- [Pf2eQuteBase](Pf2eQuteBase.md): Attributes for notes that are generated from the Pf2eTools data.
- [Pf2eQuteNote](Pf2eQuteNote.md): Attributes for notes that are generated from the Pf2eTools data.
- [QuteAbility](QuteAbility.md): Pf2eTools Ability attributes (`ability2md.txt` or `inline-ability2md.txt`).
- [QuteAction](QuteAction.md): Pf2eTools Action attributes (`action2md.txt`)
- [QuteAction](QuteAction/README.md): Pf2eTools Action attributes (`action2md.txt`)
- [QuteAffliction](QuteAffliction.md): Pf2eTools Affliction attributes for standalone notes (`affliction2md.txt`)
- [QuteArchetype](QuteArchetype.md): Pf2eTools Archetype attributes (`archetype2md.txt`)
- [QuteBackground](QuteBackground.md): Pf2eTools Background attributes (`background2md.txt`)
- [QuteBook](QuteBook.md): Pf2eTools Book attributes (`book2md.txt`)
- [QuteBook](QuteBook/README.md): Pf2eTools Book attributes (`book2md.txt`)
- [QuteDataActivity](QuteDataActivity.md): Pf2eTools activity attributes
- [QuteDataArmorClass](QuteDataArmorClass.md): Pf2eTools armor class attributes
- [QuteDataDefenses](QuteDataDefenses.md): Pf2eTools Armor class, Saving Throws, and other attributes describing defenses
- [QuteDataDefenses](QuteDataDefenses/README.md): Pf2eTools Armor class, Saving Throws, and other attributes describing defenses
- [QuteDataHpHardness](QuteDataHpHardness.md): Pf2eTools Hit Points and Hardiness attributes
- [QuteDeity](QuteDeity.md): Pf2eTools Deity attributes (`deity2md.txt`)
- [QuteDeity](QuteDeity/README.md): Pf2eTools Deity attributes (`deity2md.txt`)
- [QuteFeat](QuteFeat.md): Pf2eTools Feat attributes (`feat2md.txt`)
- [QuteHazard](QuteHazard.md): Pf2eTools Hazard attributes (`hazard2md.txt`)
- [QuteInlineAffliction](QuteInlineAffliction.md): Pf2eTools Affliction attributes (inline/embedded, `inline-affliction2md.txt`)
- [QuteHazard](QuteHazard/README.md): Pf2eTools Hazard attributes (`hazard2md.txt`)
- [QuteInlineAffliction](QuteInlineAffliction/README.md): Pf2eTools Affliction attributes (inline/embedded, `inline-affliction2md.txt`)
- [QuteInlineAttack](QuteInlineAttack.md): Pf2eTools Attack attributes (inline/embedded, `inline-attack2md.txt`)
- [QuteItem](QuteItem.md): Pf2eTools Item attributes
- [QuteRitual](QuteRitual.md): Pf2eTools Ritual attributes (`ritual2md.txt`)
- [QuteSpell](QuteSpell.md): Pf2eTools Spell attributes (`spell2md.txt`)
- [QuteItem](QuteItem/README.md): Pf2eTools Item attributes
- [QuteRitual](QuteRitual/README.md): Pf2eTools Ritual attributes (`ritual2md.txt`)
- [QuteSpell](QuteSpell/README.md): Pf2eTools Spell attributes (`spell2md.txt`)
- [QuteTrait](QuteTrait.md): Pf2eTools Trait attributes (`trait2md.txt`)
- [QuteTraitIndex](QuteTraitIndex.md): Pf2eTools Trait index attributes (`indexTrait.md`)
39 changes: 32 additions & 7 deletions src/main/java/dev/ebullient/convert/io/MarkdownDoclet.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ protected void processFiles(DocletEnvironment environment) throws IOException {

Set<? extends Element> elements = environment.getIncludedElements();

// Print package indexes (README.md)
for (PackageElement p : ElementFilter.packagesIn(elements)) {
writeReadmeFile(docTrees, p);
}

Map<TypeElement, List<TypeElement>> innerClasses = ElementFilter.typesIn(elements).stream()
.filter(t -> t.getKind() != ElementKind.INTERFACE)
.filter(t -> t.getNestingKind() != NestingKind.TOP_LEVEL)
Expand All @@ -154,6 +149,11 @@ protected void processFiles(DocletEnvironment environment) throws IOException {
classNameMapping.put(reference, reference + ".README");
}

// Print package indexes (README.md)
for (PackageElement p : ElementFilter.packagesIn(elements)) {
writeReadmeFile(docTrees, p);
}

for (TypeElement t : ElementFilter.typesIn(elements)) {
if (t.getKind() == ElementKind.INTERFACE) {
continue;
Expand Down Expand Up @@ -251,8 +251,16 @@ void writeReadmeFile(DocTrees docTrees, PackageElement p) throws IOException {
}

Aggregator elements = new Aggregator();
members.values().forEach(te -> elements.add("- [" + te.getSimpleName() + "](" + te.getSimpleName() + ".md)"
+ getDescription(docTrees, te) + "\n"));
members.values().forEach(te -> {
var ref = classNameMapping.get(te.getQualifiedName().toString());
if (ref == null) {
elements.add("- [" + te.getSimpleName() + "](" + te.getSimpleName() + ".md)"
+ getDescription(docTrees, te) + "\n");
} else {
elements.add("- [" + te.getSimpleName() + "](" + te.getSimpleName() + "/README.md)"
+ getDescription(docTrees, te) + "\n");
}
});

String result = elements.toString();
if (!result.isEmpty()) {
Expand Down Expand Up @@ -311,6 +319,9 @@ String qualifiedNameToPath(QualifiedNameable element) {
String qualifiedNameToPath(String reference) {
if (reference.endsWith("qute")) {
reference += ".README";
} else if (!isValidClass(reference.replace(".README", ""))) {
// Check if the reference is a valid class
throw new RuntimeException("Invalid class reference: " + reference);
}
return reference
.replace("dev.ebullient.convert.", "")
Expand Down Expand Up @@ -516,4 +527,18 @@ private String replacementFor(String str) {
return str;
}
}

private boolean isValidClass(String className) {
try {
Class.forName(className);
return true;
} catch (ClassNotFoundException e) {
int pos = className.lastIndexOf(".");
if (pos > -1) {
String innerClass = className.substring(0, pos) + "$" + className.substring(pos + 1);
return isValidClass(innerClass);
}
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* 5eTools background attributes ({@code background2md.txt}).
* <p>
* Extension of {@link dev.ebullient.convert.tools.dnd5e.Tools5eQuteBase}.
* Extension of {@link dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase}.
* </p>
*/
@TemplateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* 5eTools class attributes ({@code class2md.txt})
* <p>
* Extension of {@link dev.ebullient.convert.tools.dnd5e.Tools5eQuteBase}.
* Extension of {@link dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase}.
* </p>
*/
@TemplateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* 5eTools deck attributes ({@code deck2md.txt})
* <p>
* Extension of {@link dev.ebullient.convert.tools.dnd5e.Tools5eQuteBase}.
* Extension of {@link dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase}.
* </p>
*/
@TemplateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* 5eTools deity attributes ({@code deity2md.txt})
* <p>
* Extension of {@link dev.ebullient.convert.tools.dnd5e.Tools5eQuteBase}.
* Extension of {@link dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase}.
* </p>
*/
@TemplateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* 5eTools feat and optional feat attributes ({@code feat2md.txt})
* <p>
* Extension of {@link dev.ebullient.convert.tools.dnd5e.Tools5eQuteBase}.
* Extension of {@link dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase}.
* </p>
*/
@TemplateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* 5eTools hazard attributes ({@code hazard2md.txt})
* <p>
* Extension of {@link dev.ebullient.convert.tools.dnd5e.Tools5eQuteBase}.
* Extension of {@link dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase}.
* </p>
*/
@TemplateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* 5eTools item attributes ({@code item2md.txt})
* <p>
* Extension of {@link dev.ebullient.convert.tools.dnd5e.Tools5eQuteBase}.
* Extension of {@link dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase}.
* </p>
*/
@TemplateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* 5eTools creature attributes ({@code monster2md.txt})
* <p>
* Extension of {@link dev.ebullient.convert.tools.dnd5e.Tools5eQuteBase}.
* Extension of {@link dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase}.
* </p>
*/
@TemplateData
Expand All @@ -46,7 +46,7 @@ public class QuteMonster extends Tools5eQuteBase {
/** Creature ability scores as {@link dev.ebullient.convert.tools.dnd5e.qute.AbilityScores} */
public final AbilityScores scores;
/**
* Creature saving throws and skill modifiers as {@link dev.ebullient.convert.tools.dnd5e.qute.SavesAndSkills}
* Creature saving throws and skill modifiers as {@link dev.ebullient.convert.tools.dnd5e.qute.QuteMonster.SavesAndSkills}
*/
public final SavesAndSkills savesSkills;
/** Comma-separated string of creature senses (if present). */
Expand Down Expand Up @@ -80,7 +80,7 @@ public class QuteMonster extends Tools5eQuteBase {
* Markdown link to legendary group (can be embedded).
*/
public final String legendaryGroupLink;
/** Creature abilities as a list of {@link dev.ebullient.convert.tools.dnd5e.qute.Spellcasting} attributes */
/** Creature abilities as a list of {@link dev.ebullient.convert.tools.dnd5e.qute.QuteMonster.Spellcasting} attributes */
public final List<Spellcasting> spellcasting;
/** Formatted text containing the creature description. Same as `{resource.text}` */
public final String description;
Expand Down Expand Up @@ -364,7 +364,7 @@ public static class Spellcasting {
public Map<String, List<String>> daily;
/**
* Map: key = spell level, value: spell level information as
* {@link dev.ebullient.convert.tools.dnd5e.qute.QuteSpell.Spells}
* {@link dev.ebullient.convert.tools.dnd5e.qute.QuteMonster.Spells}
*/
public Map<String, Spells> spells;
/** Formatted text that should be printed after the list of spells */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* 5eTools object attributes ({@code object2md.txt})
* <p>
* Extension of {@link dev.ebullient.convert.tools.dnd5e.Tools5eQuteBase}.
* Extension of {@link dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase}.
* </p>
*/
@TemplateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* 5eTools psionic talent attributes ({@code psionic2md.txt})
* <p>
* Extension of {@link dev.ebullient.convert.tools.dnd5e.Tools5eQuteBase}.
* Extension of {@link dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase}.
* </p>
*/
@TemplateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* 5eTools race attributes ({@code race2md.txt})
* <p>
* Extension of {@link dev.ebullient.convert.tools.dnd5e.Tools5eQuteBase}.
* Extension of {@link dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase}.
* </p>
*/
@TemplateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* 5eTools reward attributes ({@code reward2md.txt})
* <p>
* Extension of {@link dev.ebullient.convert.tools.dnd5e.Tools5eQuteBase}.
* Extension of {@link dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase}.
* </p>
*/
@TemplateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* 5eTools spell attributes ({@code spell2md.txt})
* <p>
* Extension of {@link dev.ebullient.convert.tools.dnd5e.Tools5eQuteBase}.
* Extension of {@link dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase}.
* </p>
*/
@TemplateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* 5eTools subclass attributes ({@code subclass2md.txt})
* <p>
* Extension of {@link dev.ebullient.convert.tools.dnd5e.Tools5eQuteBase}.
* Extension of {@link dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase}.
* </p>
*/
@TemplateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* They can have very different properties. Treat most as optional.
* </p>
* <p>
* Extension of {@link dev.ebullient.convert.tools.dnd5e.Tools5eQuteBase}.
* Extension of {@link dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase}.
* </p>
*/
@TemplateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class QuteAbility extends Pf2eQuteNote {

/**
* Collection of trait links. Use `{#for}` or `{#each}` to iterate over the collection.
* See <a href="#traitList">traitList</a> or <a href="#bareTraitList">bareTraitList</a>.
* See <a href="#traitlist">traitList</a> or <a href="#baretraitlist">bareTraitList</a>.
*/
public final Collection<String> traits;
/** Formatted string. Components required to activate this ability (embedded/inline only) */
Expand Down

0 comments on commit 870ac79

Please sign in to comment.