Skip to content

feat: add clazz attribute to DemoSource annotation #97

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 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading