Skip to content

Commit

Permalink
docs: pretty titles for Apache Wicket in Storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbert committed Dec 31, 2024
1 parent feb4c19 commit 86274b3
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,42 +72,55 @@ public class GenerateMarkdownAndStorybookExamples {

@Test
void generateAlertComponent() {
new MarkdownDocumentationExamplesGenerator(AlertExamplesPanel.class, UtrechtAlert.class, "alert").generate();
new MarkdownDocumentationExamplesGenerator(
AlertExamplesPanel.class,
UtrechtAlert.class,
"alert",
"Alert"
).generate();
}

@Test
void generateBadgeListComponent() {

tester.startComponentInPage(BadgeListExamplesPanel.class);
String renderedHtml = tester.getLastResponseAsString();

new MarkdownDocumentationExamplesGenerator(
BadgeListExamplesPanel.class,
UtrechtBadgeListBorder.class,
"badge-list",
"Badge List",
renderedHtml
).generate();
}

@Test
void generateBodyComponent() {
new MarkdownDocumentationExamplesGenerator(BodyExamplesPanel.class, BodyExamplesPanel.class, "body").generate();
new MarkdownDocumentationExamplesGenerator(
BodyExamplesPanel.class,
BodyExamplesPanel.class,
"body",
"Body"
).generate();
}

@Test
void generateButtonGroupComponent() {
new MarkdownDocumentationExamplesGenerator(
ButtonGroupExamplesPanel.class,
UtrechtButtonGroupBorder.class,
"button-group").generate();
"button-group",
"Button Group"
).generate();
}

@Test
void generateCodeBlockComponent() {
new MarkdownDocumentationExamplesGenerator(
CodeBlockExamplesPanel.class,
UtrechtCodeBlock.class,
"code-block"
"code-block",
"Code Block"
).generate();
}

Expand All @@ -116,7 +129,8 @@ void generateColumnLayoutComponent() {
new MarkdownDocumentationExamplesGenerator(
ColumnLayoutExamplesPanel.class,
UtrechtColumnLayoutBorder.class,
"column-layout"
"column-layout",
"Column Layout"
).generate();
}

Expand All @@ -125,7 +139,8 @@ void generateFormFieldCheckboxComponent() {
new MarkdownDocumentationExamplesGenerator(
FormFieldCheckboxExamplesPanel.class,
UtrechtFormFieldCheckbox.class,
"form-field-checkbox"
"form-field-checkbox",
"Form Field Checkbox"
).generate();
}

Expand All @@ -134,20 +149,21 @@ void generateFormFieldLabelComponent() {
new MarkdownDocumentationExamplesGenerator(
FormFieldLabelExamplesPanel.class,
UtrechtFormLabel.class,
"form-field-label"
"form-field-label",
"Form Field Label"
).generate();
}

@Test
void generateHeadingComponent() {

tester.startComponentInPage(HeadingExamplesPanel.class);
String renderedHtml = tester.getLastResponseAsString();

new MarkdownDocumentationExamplesGenerator(
HeadingExamplesPanel.class,
UtrechtHeading.class,
"heading",
"Heading",
renderedHtml
).generate();
}
Expand All @@ -157,111 +173,139 @@ void generateHeadingGroupComponent() {
new MarkdownDocumentationExamplesGenerator(
HeadingGroupExamplesPanel.class,
UtrechtHeadingGroupBorder.class,
"heading-group").generate();
"heading-group",
"Heading Group"
).generate();
}

@Test
void generateHtmlContentComponent() {
new MarkdownDocumentationExamplesGenerator(
HtmlContentExamplesPanel.class,
UtrechtHtmlContentBorder.class,
"html-content").generate();
"html-content",
"HTML Content"
).generate();
}

@Test
void generateRotterdamLogoImage() {
new MarkdownDocumentationExamplesGenerator(
RotterdamLogoImageExamplesPanel.class,
RotterdamLogoImage.class,
"rotterdam-logo-image").generate();
"rotterdam-logo-image",
"Rotterdam Logo Image"
).generate();
}

@Test
void generateUtrechtLogo() {
new MarkdownDocumentationExamplesGenerator(
UtrechtLogoExamplesPanel.class,
UtrechtLogoBorder.class,
"utrecht-logo").generate();
"utrecht-logo",
"Logo"
).generate();
}

@Test
void generateUtrechtIcon() {
new MarkdownDocumentationExamplesGenerator(
IconExamplesPanel.class,
UtrechtIconBorder.class,
"utrecht-icon").generate();
"utrecht-icon",
"Icon"
).generate();
}

@Test
void generateUtrechtNumberBadge() {
new MarkdownDocumentationExamplesGenerator(
UtrechtNumberBadgeExamplesPanel.class,
UtrechtNumberBadge.class,
"utrecht-number-badge").generate();
"utrecht-number-badge",
"Number Badge"
).generate();
}

@Test
void generateUtrechtPageBody() {
new MarkdownDocumentationExamplesGenerator(
UtrechtPageBodyExamplesPanel.class,
UtrechtPageBodyBorder.class,
"utrecht-page-body").generate();
"utrecht-page-body",
"Page Body"
).generate();
}

@Test
void generateUtrechtPageFooter() {
new MarkdownDocumentationExamplesGenerator(
UtrechtPageFooterExamplesPanel.class,
UtrechtPageFooterBorder.class,
"utrecht-page-footer").generate();
"utrecht-page-footer",
"Page Footer"
).generate();
}

@Test
void generateUtrechtPageLayout() {
new MarkdownDocumentationExamplesGenerator(
UtrechtPageLayoutExamplesPanel.class,
UtrechtPageLayoutBorder.class,
"utrecht-page-layout").generate();
"utrecht-page-layout",
"Page Layout"
).generate();
}

@Test
void generateUtrechtPreserveData() {
new MarkdownDocumentationExamplesGenerator(
UtrechtPreserveDataExamplesPanel.class,
UtrechtPreserveDataLabel.class,
"utrecht-preserve-data").generate();
"utrecht-preserve-data",
"Preserve Data"
).generate();
}

@Test
void generateUtrechtRoot() {
new MarkdownDocumentationExamplesGenerator(
UtrechtRootExamplesPanel.class,
UtrechtRootBorder.class,
"utrecht-root").generate();
"utrecht-root",
"Root"
).generate();
}

@Test
void generateUtrechtSeparator() {
new MarkdownDocumentationExamplesGenerator(
UtrechtSeparatorExamplesPanel.class,
UtrechtSeparator.class,
"utrecht-separator").generate();
"utrecht-separator",
"Separator"
).generate();
}

@Test
void generateUtrechtOrderedList() {
new MarkdownDocumentationExamplesGenerator(
UtrechtOrderedListExamplesPanel.class,
UtrechtOrderedList.class,
"utrecht-ordered-list").generate();
"utrecht-ordered-list",
"Ordered List"
).generate();
}

@Test
void generateUtrechtUnorderedList() {
new MarkdownDocumentationExamplesGenerator(
UtrechtUnorderedListExamplesPanel.class,
UtrechtUnorderedList.class,
"utrecht-unordered-list").generate();
"utrecht-unordered-list",
"Unordered List"
).generate();
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package nl.rotterdam.wicket.nl_design.docs.storybook_generator;

import static nl.rotterdam.wicket.nl_design.docs.ModuleRootResolver.resolveModuleRootPath;

import com.github.javaparser.JavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.vladsch.flexmark.html2md.converter.FlexmarkHtmlConverter;
import nl.rotterdam.wicket.docs.ComponentExample;
import org.apache.wicket.Component;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.util.string.Strings;
import org.junit.platform.commons.support.ModifierSupport;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
Expand All @@ -18,8 +14,11 @@
import java.util.Comparator;
import java.util.List;
import java.util.stream.IntStream;

import static nl.rotterdam.wicket.nl_design.docs.ModuleRootResolver.resolveModuleRootPath;
import nl.rotterdam.wicket.docs.ComponentExample;
import org.apache.wicket.Component;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.util.string.Strings;
import org.junit.platform.commons.support.ModifierSupport;

public class MarkdownDocumentationExamplesGenerator {

Expand All @@ -28,6 +27,7 @@ public class MarkdownDocumentationExamplesGenerator {
private final File markdownStorybookFile;
private final Panel headingPanel;
private final String componentName;
private final String componentTitle;
private final String componentNameCapitalized;
private final HtmlDocumentationExtractor documentationExtractor;
private final String gitHubExamplePath;
Expand All @@ -39,18 +39,24 @@ public MarkdownDocumentationExamplesGenerator(
When you have a Behavior and a component, put them in the same package.
*/
Class<? extends Component> componentClass,
String componentName) {
this(examplePanelClass, componentClass, componentName, null);
String componentName,
String componentTitle
) {
this(examplePanelClass, componentClass, componentName, componentTitle, null);
}

public MarkdownDocumentationExamplesGenerator(
Class<? extends Panel> examplePanelClass,
/*
When you have a Behavior and a component, put them in the same package.
*/
Class<? extends Component> componentClass,
String componentName,
String renderedHtml) {
String componentTitle,
String renderedHtml
) {
this.componentName = componentName;
this.componentTitle = componentTitle;
this.componentNameCapitalized = Strings.capitalize(componentName);

String moduleRootPath = resolveModuleRootPath(GenerateMarkdownAndStorybookExamples.class).getAbsolutePath();
Expand All @@ -63,11 +69,9 @@ public MarkdownDocumentationExamplesGenerator(
String exampleFilenameWithoutExtension = basePathInDocs + examplePanelClass.getSimpleName();

exampleJavaFile = new File(exampleFilenameWithoutExtension + ".java");
documentationExtractor =
renderedHtml != null
? new HtmlDocumentationExtractor(renderedHtml)
: new HtmlDocumentationExtractor(new File(exampleFilenameWithoutExtension + ".html").toPath()
);
documentationExtractor = renderedHtml != null
? new HtmlDocumentationExtractor(renderedHtml)
: new HtmlDocumentationExtractor(new File(exampleFilenameWithoutExtension + ".html").toPath());

markdownReadmeFile = new File(moduleRootPath + "/stories/" + componentName + ".md");
markdownStorybookFile = new File(moduleRootPath + "/stories/" + componentName + ".mdx");
Expand Down Expand Up @@ -156,7 +160,7 @@ private void writeStoryBookFile() throws IOException {
<Markdown>{markdown}</Markdown>
""",
componentName,
Strings.capitalize(componentName)
componentTitle
);

Files.write(markdownStorybookFile.toPath(), content.getBytes());
Expand Down

0 comments on commit 86274b3

Please sign in to comment.