Skip to content

Commit

Permalink
Merge pull request #42 from trivago/template_refactoring
Browse files Browse the repository at this point in the history
Template refactoring
  • Loading branch information
Benjamin Bischoff authored Apr 18, 2018
2 parents 3164fc4 + 86a6470 commit be17fcb
Show file tree
Hide file tree
Showing 45 changed files with 937 additions and 926 deletions.
2 changes: 1 addition & 1 deletion example-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.benjamin-bischoff</groupId>
<artifactId>cluecumber-test-project</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
6 changes: 3 additions & 3 deletions plugin-code/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.trivago.rta</groupId>
<artifactId>cluecumber-report-plugin</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<url>https://github.com/trivago/cluecumber-report-plugin</url>

<name>Cluecumber Maven Plugin for Cucumber Reports</name>
Expand Down Expand Up @@ -83,9 +83,9 @@
<junit.version>4.12</junit.version>

<gson.version>2.8.2</gson.version>
<gsonfire.version>1.8.1</gsonfire.version>
<gsonfire.version>1.8.3</gsonfire.version>
<chart.version>2.3.1</chart.version>
<freemarker.version>2.3.27-incubating</freemarker.version>
<freemarker.version>2.3.28</freemarker.version>
</properties>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void execute() throws CluecumberPluginException {
}
reportGenerator.generateReport(startPageCollection);
logger.info("Converted " + startPageCollection.getTotalNumberOfFeatures() + " features into test report:");
logger.info("- " + propertyManager.getGeneratedHtmlReportDirectory() + "/" + PluginSettings.SUITE_OVERVIEW_PAGE_PATH);
logger.info("- " + propertyManager.getGeneratedHtmlReportDirectory() + "/" + PluginSettings.SUITE_OVERVIEW_PAGE_PATH + PluginSettings.HTML_FILE_EXTENSION);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@
*/
public class PluginSettings {
public final static String NAME = "Cluecumber Report Plugin";
public static final String TEMPLATE_FILE_EXTENSION = ".ftl";
public static final String HTML_FILE_EXTENSION = ".html";

public static final String BASE_TEMPLATE_PATH = "/template";
public static final String PAGES_DIRECTORY = "pages";

public final static String SCENARIO_DETAIL_PAGE_NAME = "Suite Overview";
public final static String SCENATIO_DETAIL_PAGE_PATH = PAGES_DIRECTORY + "/scenario-detail/scenario-detail.html";
public final static String SCENARIO_DETAIL_PAGE_NAME = "Scenario Details";
public final static String SCENATIO_DETAIL_PAGE_PATH = "scenario-detail";
public static final String SCENARIO_DETAIL_PAGE_FRAGMENT = "/scenario-detail/scenario_";

public final static String SUITE_OVERVIEW_PAGE_NAME = "Suite Overview";
public final static String SUITE_OVERVIEW_PAGE_PATH = "index.html";
public final static String SUITE_OVERVIEW_PAGE_PATH = "index";

public final static String TAG_SUMMARY_PAGE_NAME = "Tag Summary";
public final static String TAG_SUMMARY_PAGE_PATH = PAGES_DIRECTORY + "/tag-summary.html";
public final static String TAG_SUMMARY_PAGE_PATH = "tag-summary";
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ public void setLine(final int line) {
this.line = line;
}

public String getEncodedName(){
return RenderingUtils.escapeHTML(getName());
}

public String getName() {
return !name.isEmpty() ? name : "[Unnamed]";
}
Expand All @@ -72,10 +68,6 @@ public void setName(final String name) {
this.name = name;
}

public String getEncodedDescription(){
return RenderingUtils.escapeHTML(getDescription());
}

public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.trivago.rta.json.pojo;

import com.google.gson.annotations.SerializedName;
import com.trivago.rta.rendering.RenderingUtils;

public class Embedding {
private String data;
Expand All @@ -27,10 +26,6 @@ public class Embedding {

private transient String filename;

public String getEncodedData(){
return RenderingUtils.escapeHTML(getData());
}

public String getData() {
return data;
}
Expand Down
10 changes: 0 additions & 10 deletions plugin-code/src/main/java/com/trivago/rta/json/pojo/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.trivago.rta.json.pojo;

import com.trivago.rta.rendering.RenderingUtils;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -46,10 +44,6 @@ public void setElements(final List<Element> elements) {
this.elements = elements;
}

public String getEncodedName() {
return RenderingUtils.escapeHTML(getName());
}

public String getName() {
return !name.isEmpty() ? name : "[Unnamed]";
}
Expand All @@ -58,10 +52,6 @@ public void setName(final String name) {
this.name = name;
}

public String getEncodedDescription() {
return RenderingUtils.escapeHTML(getDescription());
}

public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ public String getErrorMessage() {
return errorMessage;
}

public String getEncodedErrorMessage() {
return RenderingUtils.escapeHTML(errorMessage);
}

public void setErrorMessage(final String errorMessage) {
this.errorMessage = errorMessage;
}
Expand Down
10 changes: 0 additions & 10 deletions plugin-code/src/main/java/com/trivago/rta/json/pojo/Step.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.trivago.rta.json.pojo;

import com.trivago.rta.rendering.RenderingUtils;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -73,14 +71,6 @@ public List<String> getOutput() {
return output;
}

public List<String> getEncodedOutput() {
List<String> encodedOutput = new ArrayList<>();
for (String outputString : output) {
encodedOutput.add(RenderingUtils.escapeHTML(outputString));
}
return encodedOutput;
}

public void setOutput(final List<String> output) {
this.output = output;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,6 @@ public static long convertMicrosecondsToMilliseconds(final long microseconds) {
return Duration.ofMillis(microseconds / MICROSECOND_FACTOR).toMillis();
}

/**
* Escape HTML tags in a string.
*
* @param sourceString The source string.
* @return The escaped string.
*/
public static String escapeHTML(final String sourceString) {
StringBuilder stringBuilder = new StringBuilder(Math.max(16, sourceString.length()));
for (int i = 0; i < sourceString.length(); i++) {
char character = sourceString.charAt(i);
if (character > 127 || character == '"' || character == '<' || character == '>' || character == '&') {
stringBuilder.append("&#");
stringBuilder.append((int) character);
stringBuilder.append(';');
} else {
stringBuilder.append(character);
}
}
return stringBuilder.toString();
}

/**
* Return the current Cluecumber version.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ private void generateTagSummaryPage(final List<Report> reports) throws Cluecumbe
TagSummaryPageCollection tagSummaryPageCollection = new TagSummaryPageCollection(reports);
fileIO.writeContentToFile(
templateEngine.getRenderedTagSummaryPageContent(tagSummaryPageCollection),
propertyManager.getGeneratedHtmlReportDirectory() + "/" + PluginSettings.TAG_SUMMARY_PAGE_PATH);
propertyManager.getGeneratedHtmlReportDirectory() + "/" + PluginSettings.PAGES_DIRECTORY + "/" +
PluginSettings.TAG_SUMMARY_PAGE_PATH + PluginSettings.HTML_FILE_EXTENSION);
}

private void generateStartPage(final StartPageCollection startPageCollection) throws CluecumberPluginException {
fileIO.writeContentToFile(
templateEngine.getRenderedStartPageContent(startPageCollection),
propertyManager.getGeneratedHtmlReportDirectory() + "/" + PluginSettings.SUITE_OVERVIEW_PAGE_PATH);
propertyManager.getGeneratedHtmlReportDirectory() + "/" +
PluginSettings.SUITE_OVERVIEW_PAGE_PATH + PluginSettings.HTML_FILE_EXTENSION);
}

private void generateScenarioDetailPages(final List<Report> reports) throws CluecumberPluginException {
Expand All @@ -87,8 +89,8 @@ private void generateScenarioDetailPages(final List<Report> reports) throws Clue
fileIO.writeContentToFile(
templateEngine.getRenderedDetailPageContent(detailPageCollection),
propertyManager.getGeneratedHtmlReportDirectory() + "/" +
PluginSettings.PAGES_DIRECTORY + "/scenario-detail/scenario_" +
element.getScenarioIndex() + ".html");
PluginSettings.PAGES_DIRECTORY + PluginSettings.SCENARIO_DETAIL_PAGE_FRAGMENT +
element.getScenarioIndex() + PluginSettings.HTML_FILE_EXTENSION);
}
}
}
Expand All @@ -103,16 +105,16 @@ private void copyReportAssets() throws CluecumberPluginException {
// Copy CSS resources
copyFileFromJarToFilesystem("/css/bootstrap.min.css");
copyFileFromJarToFilesystem("/css/cluecumber.css");
copyFileFromJarToFilesystem("/css/dataTables.bootstrap4.min.css");
copyFileFromJarToFilesystem("/css/datatables.min.css");
copyFileFromJarToFilesystem("/css/jquery.fancybox.min.css");
copyFileFromJarToFilesystem("/css/dataTables.bootstrap4.min.css");

// Copy Javascript resources
copyFileFromJarToFilesystem("/js/jquery-3.2.1.slim.min.js");
copyFileFromJarToFilesystem("/js/jquery.min.js");
copyFileFromJarToFilesystem("/js/bootstrap.min.js");
copyFileFromJarToFilesystem("/js/popper.min.js");
copyFileFromJarToFilesystem("/js/Chart.bundle.min.js");
copyFileFromJarToFilesystem("/js/dataTables.bootstrap4.min.js");
copyFileFromJarToFilesystem("/js/jquery.dataTables.min.js");
copyFileFromJarToFilesystem("/js/datatables.min.js");
copyFileFromJarToFilesystem("/js/jquery.fancybox.min.js");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.trivago.rta.rendering;

import com.trivago.rta.constants.PluginSettings;
import com.trivago.rta.exceptions.CluecumberPluginException;
import freemarker.template.Configuration;
import freemarker.template.Template;
Expand All @@ -12,7 +13,7 @@ public class TemplateConfiguration {
private Configuration cfg;

void init(final Class rootClass, final String basePath) {
cfg = new Configuration(Configuration.VERSION_2_3_27);
cfg = new Configuration(Configuration.VERSION_2_3_28);
cfg.setClassForTemplateLoading(rootClass, basePath);
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
Expand All @@ -22,7 +23,7 @@ void init(final Class rootClass, final String basePath) {
Template getTemplate(final String templateName) throws CluecumberPluginException {
Template template = null;
try {
template = cfg.getTemplate(templateName);
template = cfg.getTemplate(templateName + PluginSettings.TEMPLATE_FILE_EXTENSION);
} catch (Exception e) {
throw new CluecumberPluginException("Template '" + templateName + "' was not found or not parsable: " +
e.getMessage());
Expand Down
8 changes: 4 additions & 4 deletions plugin-code/src/main/resources/template/css/bootstrap.min.css

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion plugin-code/src/main/resources/template/css/cluecumber.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ body {
}

.card, img {
margin: 0 0 1rem 0;
margin: 0 0 .5rem 0;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
}

Expand All @@ -56,6 +56,10 @@ code {
padding: 1rem;
}

.list-group-item .row:hover{
background-color: rgba(0,0,0,.075);
}

div.tooltip-inner {
max-width: 100%;
white-space: nowrap;
Expand Down
Loading

0 comments on commit be17fcb

Please sign in to comment.