diff --git a/CHANGELOG.md b/CHANGELOG.md index 63041642dd..e73e41446d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# v0.7.2 + +## New Features + +* Added `cssClass` and `color` attributes to `@IsTag` to customize tags in HTML reports [#69](https://github.com/TNG/JGiven/pull/69) + +## Fixed Issues + +* Custom CSS files are now copied to the target folder when generating HTML5 reports [#70](https://github.com/TNG/JGiven/issues/70) + # v0.7.1 ## New Features diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/annotation/IsTag.java b/jgiven-core/src/main/java/com/tngtech/jgiven/annotation/IsTag.java index 201eb87907..8c62474a4e 100644 --- a/jgiven-core/src/main/java/com/tngtech/jgiven/annotation/IsTag.java +++ b/jgiven-core/src/main/java/com/tngtech/jgiven/annotation/IsTag.java @@ -79,4 +79,30 @@ * Whether the type should be prepended to the tag if the tag has a value. */ boolean prependType() default false; + + /** + * Sets a CSS class that should be used in HTML reports for this tag. + *
+ * The default CSS class is {@code 'tag-
+ * Non-HTML reports ignore this attribute
+ *
+ * @since 0.7.2
+ */
+ String cssClass() default "";
+
+ /**
+ * A color that should be used in reports for this tag.
+ *
+ * It depends on the type of the report whether and how this value is interpreted.
+ * HTML reports take this value as the background color for the tag.
+ *
+ * Example values for the HTML report are 'red', '#ff0000', 'rgba(100,0,0,0.5)'
+ *
+ * This attribute is for simple use cases.
+ * For advanced styling options use the {@link #cssClass()} attribute instead.
+ *
+ * @since 0.7.2
+ */
+ String color() default "";
}
diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/config/TagConfiguration.java b/jgiven-core/src/main/java/com/tngtech/jgiven/config/TagConfiguration.java
index e87544ecc8..ec4c58d18f 100644
--- a/jgiven-core/src/main/java/com/tngtech/jgiven/config/TagConfiguration.java
+++ b/jgiven-core/src/main/java/com/tngtech/jgiven/config/TagConfiguration.java
@@ -15,6 +15,8 @@ public class TagConfiguration {
private boolean prependType;
private String defaultValue = "";
private String description = "";
+ private String color = "";
+ private String cssClass = "";
private Class extends TagDescriptionGenerator> descriptionGenerator = DefaultTagDescriptionGenerator.class;
private String type = "";
@@ -59,6 +61,17 @@ public Builder prependType( boolean b ) {
configuration.prependType = b;
return this;
}
+
+ public Builder cssClass( String cssClass ) {
+ configuration.cssClass = cssClass;
+ return this;
+ }
+
+ public Builder color( String color ) {
+ configuration.color = color;
+ return this;
+ }
+
}
/**
@@ -117,6 +130,22 @@ public boolean isPrependType() {
return prependType;
}
+ /**
+ * {@link com.tngtech.jgiven.annotation.IsTag#color()}
+ * @see com.tngtech.jgiven.annotation.IsTag
+ */
+ public String getColor() {
+ return color;
+ }
+
+ /**
+ * {@link com.tngtech.jgiven.annotation.IsTag#cssClass()}
+ * @see com.tngtech.jgiven.annotation.IsTag
+ */
+ public String getCssClass() {
+ return cssClass;
+ }
+
public static TagConfiguration fromIsTag( IsTag isTag ) {
TagConfiguration result = new TagConfiguration();
result.defaultValue = isTag.value();
@@ -126,6 +155,8 @@ public static TagConfiguration fromIsTag( IsTag isTag ) {
result.prependType = isTag.prependType();
result.type = isTag.type();
result.descriptionGenerator = isTag.descriptionGenerator();
+ result.cssClass = isTag.cssClass();
+ result.color = isTag.color();
return result;
}
}
diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/report/ReportGenerator.java b/jgiven-core/src/main/java/com/tngtech/jgiven/report/ReportGenerator.java
index 1fd670f05d..3451a83dea 100644
--- a/jgiven-core/src/main/java/com/tngtech/jgiven/report/ReportGenerator.java
+++ b/jgiven-core/src/main/java/com/tngtech/jgiven/report/ReportGenerator.java
@@ -110,11 +110,15 @@ public void generate() throws Exception {
private void generateStaticHtmlReport( CompleteReportModel reportModel ) throws IOException {
new StaticHtmlReportGenerator().generate( reportModel, getTargetDirectory() );
+ copyCustomCssFile( getTargetDirectory() );
+ }
+
+ private void copyCustomCssFile( File targetDirectory ) throws IOException {
if( getCustomCssFile() != null ) {
if( !getCustomCssFile().canRead() ) {
log.info( "Cannot read customCssFile " + getCustomCssFile() + " skipping" );
} else {
- Files.copy( getCustomCssFile(), new File( getTargetDirectory(), "custom.css" ) );
+ Files.copy( getCustomCssFile(), new File( targetDirectory, "custom.css" ) );
}
}
}
@@ -132,6 +136,7 @@ private void generateHtml5Report( CompleteReportModel reportModel ) throws IOExc
}
reportGenerator.generate( reportModel, getTargetDirectory() );
+ copyCustomCssFile( new File( getTargetDirectory(), "css" ) );
}
private static void printUsageAndExit() {
diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/report/html/HtmlTocWriter.java b/jgiven-core/src/main/java/com/tngtech/jgiven/report/html/HtmlTocWriter.java
index d5c5211d2d..1f888399f3 100644
--- a/jgiven-core/src/main/java/com/tngtech/jgiven/report/html/HtmlTocWriter.java
+++ b/jgiven-core/src/main/java/com/tngtech/jgiven/report/html/HtmlTocWriter.java
@@ -8,7 +8,6 @@
import java.util.List;
import com.google.common.base.Function;
-import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimaps;
@@ -159,14 +158,7 @@ private void writeTagLink( Tag tag, List
+ * Is either {@code true} or {@code null}
+ */
+ private Boolean prependType;
+
+ /**
+ * An optional color that is used in reports
+ */
+ private String color;
+
+ /**
+ * An optional cssClass used in HTML reports
*/
- private boolean prependType;
+ private String cssClass;
public Tag( String name ) {
this.name = name;
@@ -43,7 +58,7 @@ public String getName() {
}
public boolean isPrependType() {
- return prependType;
+ return prependType == null ? false : true;
}
public String getDescription() {
@@ -54,6 +69,26 @@ public void setDescription( String description ) {
this.description = description;
}
+ public void setColor( String color ) {
+ this.color = color;
+ }
+
+ public String getColor() {
+ return color;
+ }
+
+ public void setCssClass( String cssClass ) {
+ this.cssClass = cssClass;
+ }
+
+ public String getCssClass() {
+ return cssClass;
+ }
+
+ public String getCssClassOrDefault() {
+ return cssClass == null ? "tag-" + getName() : cssClass;
+ }
+
@SuppressWarnings( "unchecked" )
public List", getCaseId() ) );
writeStatusIcon( scenarioCase.success );
- writer.print( format( " Case %d: ", scenarioCase.getCaseNr()) );
+ writer.print( format( " Case %d: ", scenarioCase.getCaseNr() ) );
for( int i = 0; i < scenarioCase.getExplicitArguments().size(); i++ ) {
if( scenarioModel.getExplicitParameters().size() > i ) {
diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/report/model/ReportModelBuilder.java b/jgiven-core/src/main/java/com/tngtech/jgiven/report/model/ReportModelBuilder.java
index bd82160aba..c31ee06613 100644
--- a/jgiven-core/src/main/java/com/tngtech/jgiven/report/model/ReportModelBuilder.java
+++ b/jgiven-core/src/main/java/com/tngtech/jgiven/report/model/ReportModelBuilder.java
@@ -354,6 +354,14 @@ public List
Cases
diff --git a/jgiven-tests/src/test/java/com/tngtech/jgiven/report/html5/WhenHtml5Report.java b/jgiven-tests/src/test/java/com/tngtech/jgiven/report/html5/WhenHtml5Report.java
index 1f9c5bb8ab..b4cdb6385f 100644
--- a/jgiven-tests/src/test/java/com/tngtech/jgiven/report/html5/WhenHtml5Report.java
+++ b/jgiven-tests/src/test/java/com/tngtech/jgiven/report/html5/WhenHtml5Report.java
@@ -37,11 +37,11 @@ public SELF the_All_Scenarios_page_is_opened() throws MalformedURLException {
}
public SELF the_tag_with_name_$_is_clicked( String tagName ) {
- List