com.github.bogdanlivadariu.reporting.cucumber.helpers.Helpers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cucumber-reporting-handlebars Show documentation
Show all versions of cucumber-reporting-handlebars Show documentation
Module used to generate cucumber reports using handlebars
package com.github.bogdanlivadariu.reporting.cucumber.helpers;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import java.util.UUID;
import org.joda.time.Period;
import org.joda.time.format.PeriodFormatter;
import org.joda.time.format.PeriodFormatterBuilder;
import com.github.bogdanlivadariu.reporting.cucumber.json.models.Row;
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;
public class Helpers {
private Handlebars handlebar;
public Helpers(Handlebars handlebar) {
this.handlebar = handlebar;
}
public Handlebars registerHelpers() {
handlebar.registerHelper("date", dateHelper());
handlebar.registerHelper("embedding", embeddingHelper());
handlebar.registerHelper("result-color", resultColorHelper());
handlebar.registerHelper("resolve-title", resolveTitleHelper());
handlebar.registerHelper("is-collapsed", isCollapsedHelper());
handlebar.registerHelper("now", nowHelper());
handlebar.registerHelper("do_table", doTableHelper());
return handlebar;
}
private Helper dateHelper() {
return new Helper() {
public CharSequence apply(Long arg0, Options arg1) throws IOException {
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendDays()
.appendSuffix(" d : ")
.appendHours()
.appendSuffix(" h : ")
.appendMinutes()
.appendSuffix(" m : ")
.appendSeconds()
.appendSuffix(" s : ")
.appendMillis()
.appendSuffix(" ms")
.toFormatter();
return formatter.print(new Period((arg0 * 1) / 1000000));
}
};
}
private Helper embeddingHelper() {
return new Helper() {
@Override
public CharSequence apply(String arg0, Options arg1) throws IOException {
String toReturn;
String id = UUID.randomUUID().toString();
int index = arg1.param(1);
if (arg1.param(0).toString().contains("image")) {
toReturn =
"";
toReturn +=
""
+ " "
+ " "
+ " "
+ " ";
} else {
toReturn = "" + arg0 + "
";
}
return toReturn;
}
};
}
private Helper resultColorHelper() {
return new Helper() {
@Override
public CharSequence apply(String arg0, Options arg1) throws IOException {
return checkState(
arg0.toLowerCase(),
Constants.INFO,
Constants.SUCCESS,
Constants.DANGER,
Constants.WARNING);
}
};
}
private Helper resolveTitleHelper() {
return new Helper() {
@Override
public CharSequence apply(String arg0, Options arg1) throws IOException {
return checkState(
arg0.toLowerCase(),
Constants.THIS_STEP_HAS_BEEN_SKIPPED,
Constants.THIS_STEP_HAS_PASSED,
Constants.THIS_STEP_HAS_FAILED,
Constants.THIS_STEP_HAS_NOT_BEEN_DEFINED);
}
};
}
private Helper isCollapsedHelper() {
return new Helper() {
@Override
public CharSequence apply(String arg0, Options arg1) throws IOException {
return checkState(
arg0.toLowerCase(),
Constants.COLLAPSE_IN,
Constants.COLLAPSE,
Constants.COLLAPSE_IN,
Constants.COLLAPSE_IN);
}
};
}
private Helper
© 2015 - 2024 Weber Informatics LLC | Privacy Policy