Skip to content

Commit

Permalink
feat: add clazz attribute to DemoSource annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
javier-godoy authored and mlopezFC committed Jun 25, 2024
1 parent e9a1204 commit b37ff72
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
27 changes: 19 additions & 8 deletions src/main/java/com/flowingcode/vaadin/addons/demo/DemoSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Commons Demo
* %%
* Copyright (C) 2020 - 2023 Flowing Code
* Copyright (C) 2020 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -29,12 +29,12 @@

/**
* This annotation is used for configuring the source code URL in a {@link TabbedDemo}. If no {@code
* value} is specified, and the demo view is annotated with {@link GithubLink}, then the source URL
* defaults to the location of the annotated class under {@code src/test/java} and the branch is
* determined from the value of {@link GithubBranch} in the demo view class (if the annotation is
* present) or the containing package of the demo view class. If the source URL is defaulted and no
* {@code GithubBranch} annotation is present either in the demo view class or its containing
* package, then the branch defaults to {@code master}.
* value} or {@code clazz} is specified, and the demo view is annotated with {@link GithubLink},
* then the source URL defaults to the location of the annotated class under {@code src/test/java}
* and the branch is determined from the value of {@link GithubBranch} in the demo view class (if
* the annotation is present) or the containing package of the demo view class. If the source URL is
* defaulted and no {@code GithubBranch} annotation is present either in the demo view class or its
* containing package, then the branch defaults to {@code master}.
*
* @author Javier Godoy / Flowing Code
*/
Expand All @@ -47,9 +47,20 @@

static final String DEFAULT_VALUE = "__DEFAULT__";

/** A link to the source code, if different from the annotated class. */
/**
* A link to the source code, if different from the annotated class.
* <p>
* It is an error if both {@code value} and {@link #clazz()} are specified.
*/
String value() default GITHUB_SOURCE;

/**
* The class to display, if different from the annotated class.
* <p>
* It is an error if both {@link #value()} and {@code clazz} are specified.
*/
Class<?> clazz() default DemoSource.class;

/**
* The caption of the source tab (displayed if several sources are provided). Default to the file
* name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ private Optional<SourceCodeTab> createSourceCodeTab(Class<?> annotatedClass, Dem
String demoFile;
String url = annotation.value();
if (url.equals(DemoSource.GITHUB_SOURCE)) {
String className = annotatedClass.getName().replace('.', '/');
String className;
if (annotation.clazz() == DemoSource.class) {
className = annotatedClass.getName().replace('.', '/');
} else {
className = annotation.clazz().getName().replace('.', '/');
}
demoFile = "src/test/java/" + className + ".java";
} else if (url.startsWith("/src/test/")) {
demoFile = url.substring(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@

@Route(value = "demo/multisource", layout = Demo.class)
@PageTitle("Demo with multiple sources")
// show-source @DemoSource
// show-source @DemoSource("/src/test/resources/META-INF/resources/frontend/multi-source-demo.css")
// show-source @DemoSource(clazz = Demo.class)
@DemoSource
@DemoSource(value = "/src/test/resources/META-INF/resources/frontend/multi-source-demo.css")
@DemoSource("/src/test/resources/META-INF/resources/frontend/multi-source-demo.css")
@DemoSource(clazz = Demo.class)
@StyleSheet("./multi-source-demo.css")
public class MultiSourceDemo extends Div {
public MultiSourceDemo() {
Expand Down

0 comments on commit b37ff72

Please sign in to comment.