Skip to content

Commit

Permalink
Fixes #1.5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
rmpestano committed Sep 5, 2020
1 parent f91c6cd commit 4ad1e9a
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 138 deletions.
2 changes: 0 additions & 2 deletions cukedoctor-converter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<artifactId>cukedoctor-extension</artifactId>
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>io.github.robwin</groupId>
<artifactId>markup-document-builder</artifactId>
Expand All @@ -52,7 +51,6 @@
<version>1.11.3</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
Expand Down
11 changes: 0 additions & 11 deletions cukedoctor-extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.jruby</groupId>
<artifactId>jruby-complete</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-complete</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.asciidoctor.Asciidoctor;
import org.asciidoctor.extension.ExtensionGroup;
import org.asciidoctor.extension.spi.ExtensionRegistry;
import org.asciidoctor.jruby.extension.spi.ExtensionRegistry;

public class CukedoctorExtensionRegistry implements ExtensionRegistry {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
package com.github.cukedoctor.extension;

import static com.github.cukedoctor.extension.CukedoctorExtensionRegistry.*;

import org.asciidoctor.ast.Document;
import org.asciidoctor.extension.Postprocessor;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.Map;
import static com.github.cukedoctor.extension.CukedoctorExtensionRegistry.FILTER_DISABLE_EXT_KEY;

/**
* Created by pestano on 20/07/15.
* adds search box to rendered html documentation
*/
public class CukedoctorFilterExtension extends Postprocessor {

public CukedoctorFilterExtension(Map<String, Object> config) {
super(config);
}

@Override
public String process(Document document, String output) {
if (document.basebackend("html") && System.getProperty(FILTER_DISABLE_EXT_KEY) == null) {
if (document.isBasebackend("html") && System.getProperty(FILTER_DISABLE_EXT_KEY) == null) {
org.jsoup.nodes.Document doc = Jsoup.parse(output, "UTF-8");

Elements sect1 = doc.getElementsByClass("sect1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,43 @@
*/
public class CukedoctorFooterExtension extends Postprocessor {

private static final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT);

public CukedoctorFooterExtension(Map<String, Object> config) {
super(config);
}

@Override
public String process(Document document, String output) {
if (document.basebackend("html") && System.getProperty("cukedoctor.disable.footer") == null) {
String stopWatch = System.getProperty("cukedoctor.stopwatch");
Double generationTimeInSeconds = new Double(0);
String documentationDate = dateFormat.format(new Date());
String cukedoctorVersion = "";
try {
ResourceBundle bundle = new PropertyResourceBundle(CukedoctorFooterExtension.class.getResourceAsStream("/cukedoctor-extension.properties"));
cukedoctorVersion = bundle.getString("cukedoctor.version");
} catch (Exception e) {
Logger.getLogger(getClass().getName()).warning("Could not find bundle cukedoctor-extension");
}

if (stopWatch != null && !"".equals(stopWatch)) {
long begin = 0;
try {
begin = Long.parseLong(stopWatch);
generationTimeInSeconds = (System.currentTimeMillis() - begin) / 1000.0;
} catch (NumberFormatException e) {
private static final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT);

@Override
public String process(Document document, String output) {
if (document.isBasebackend("html") && System.getProperty("cukedoctor.disable.footer") == null) {
String stopWatch = System.getProperty("cukedoctor.stopwatch");
Double generationTimeInSeconds = new Double(0);
String documentationDate = dateFormat.format(new Date());
String cukedoctorVersion = "";
try {
ResourceBundle bundle = new PropertyResourceBundle(CukedoctorFooterExtension.class.getResourceAsStream("/cukedoctor-extension.properties"));
cukedoctorVersion = bundle.getString("cukedoctor.version");
} catch (Exception e) {
Logger.getLogger(getClass().getName()).warning("Could not find bundle cukedoctor-extension");
}

if (stopWatch != null && !"".equals(stopWatch)) {
long begin = 0;
try {
begin = Long.parseLong(stopWatch);
generationTimeInSeconds = (System.currentTimeMillis() - begin) / 1000.0;
} catch (NumberFormatException e) {
}
}
org.jsoup.nodes.Document doc = Jsoup.parse(output, "UTF-8");
Element contentElement = doc.getElementById("footer");
contentElement.attr("style", "color:gray;font-size:11px");
contentElement.text("Generated by ").append("<a href=https://github.com/rmpestano/cukedoctor target=\"_blank\"> Cukedoctor " +
cukedoctorVersion +
"</a>");
contentElement.append(" - " + documentationDate);
contentElement.append("<span style=\"float:right;font-size:11px\"> Execution time: " +
+generationTimeInSeconds + " seconds</span>");
return doc.html();
} else {
return output;
}
}
org.jsoup.nodes.Document doc = Jsoup.parse(output, "UTF-8");
Element contentElement = doc.getElementById("footer");
contentElement.attr("style","color:gray;font-size:11px");
contentElement.text("Generated by ").append("<a href=https://github.com/rmpestano/cukedoctor target=\"_blank\"> Cukedoctor " +
cukedoctorVersion +
"</a>");
contentElement.append(" - " + documentationDate);
contentElement.append("<span style=\"float:right;font-size:11px\"> Execution time: " +
+ generationTimeInSeconds + " seconds</span>");
return doc.html();
} else {
return output;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,17 @@

import org.asciidoctor.ast.StructuralNode;
import org.asciidoctor.extension.BlockMacroProcessor;
import org.asciidoctor.extension.Reader;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
* Created by pestano on 20/07/15.
*/
public class CukedoctorMinMaxExtension extends BlockMacroProcessor {

public CukedoctorMinMaxExtension(String name, Map<String, Object> config) {
super(name, config);
}

@Override
public Object process(StructuralNode parent, String target, Map<String, Object> map) {
String backend = parent.getAttribute("backend") != null ? parent.getAttribute("backend").toString() : "";
if (backend.contains("html")) {
if (!parent.getDocument().isBasebackend("pdf")) {
StringBuilder minMax = new StringBuilder();
minMax.append("<span class=\"fa fa-minus-square fa-fw\" style=\"cursor:pointer;float:right;margin-top:-30px\" ").
append(" title=\"Minimize\" onclick=\"hideFeatureScenarios('").
Expand All @@ -31,10 +23,9 @@ public Object process(StructuralNode parent, String target, Map<String, Object>
append("<span id=\"hidden-").append(target).append("\"").
append(" class=\"fa fa-plus-square fa-fw\" style=\"cursor:pointer;float:right;display:none;margin-top:-30px\" title=\"Maximize feature\" onclick=\"showFeatureScenarios('").
append(target).append("');").append("this.style.display = 'none'\"> </span>");

return createBlock(parent, "pass", Arrays.asList(minMax.toString()), this.getConfig(),new HashMap<Object, Object>());
return createBlock(parent, "pass", minMax.toString());
} else {
return parent;
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ public class CukedoctorScriptExtension extends Postprocessor {

private static final Boolean HIDE_FEATURES_SECTION = System.getProperty("HIDE_FEATURES_SECTION") == null ? Boolean.FALSE : Boolean.valueOf(System.getProperty("HIDE_FEATURES_SECTION"));

public CukedoctorScriptExtension(Map<String, Object> config) {
super(config);
}

@Override
public String process(Document document, String output) {
if (document.isBasebackend("html")) {
Expand Down Expand Up @@ -171,7 +167,7 @@ private String getMinMaxScriptForDocWithoutFeaturesSection() {

private void addSearchScript(Element contentElement) {
String searchScripts = "<script type = \"text/javascript\" >\n" +
"var allLevel2ListItens = null;\n" +
"var allLevel2ListItems = null;\n" +
"\n" +
"function searchFeature(criteria) {\n" +
" if (criteria != null && criteria.length >= 3) {\n" +
Expand All @@ -187,7 +183,7 @@ private void addSearchScript(Element contentElement) {
" }\n" +
" }\n" +
" if (h3 != null && h3.id != null) {\n" +
" if (!h3.id.toLowerCase().match(criteria.toLowerCase())) {\n" +
" if (h3.id.toLowerCase().replaceAll('-',' ').indexOf(criteria.toLowerCase()) == -1) {\n" +
" sect2List[i].style.display = 'none';\n" +
" } else {//match\n" +
" sect2List[i].style.display = 'inline';\n" +
Expand Down Expand Up @@ -221,27 +217,27 @@ private void addSearchScript(Element contentElement) {
" }//end for\n" +
" }//end elements != null\n" +
"\n" +
" if (allLevel2ListItens == null) {\n" +
" if (allLevel2ListItems == null) {\n" +
" collectallLevel2IListItens();\n" +
" }\n" +
" for (var z = 0; z < allLevel2ListItens.length; z++) {\n" +
" allLevel2ListItens[z].style.display = 'inline';\n" +
" for (var z = 0; z < allLevel2ListItems.length; z++) {\n" +
" allLevel2ListItems[z].style.display = 'inline';\n" +
" }\n" +
" if (document.getElementById('input-search')) {\n" +
" document.getElementById('input-search').value = 'Filter...';\n" +
" }\n" +
"}\n" +
"\n" +
"function filterToc(criteria) {\n" +
" if (allLevel2ListItens == null) {\n" +
" if (allLevel2ListItems == null) {\n" +
" collectallLevel2IListItens();\n" +
" }\n" +
" for (var z = 0; z < allLevel2ListItens.length; z++) {\n" +
" if (allLevel2ListItens[z].childNodes[0].tagName && allLevel2ListItens[z].childNodes[0].tagName.toLowerCase() == \"a\") {\n" +
" if (allLevel2ListItens[z].childNodes[0].getAttribute(\"href\").toUpperCase().substring(1).match(criteria.toUpperCase())) {\n" +
" allLevel2ListItens[z].style.display = 'inline';\n" +
" for (var z = 0; z < allLevel2ListItems.length; z++) {\n" +
" if (allLevel2ListItems[z].childNodes[0].tagName && allLevel2ListItems[z].childNodes[0].tagName.toLowerCase() == \"a\") {\n" +
" if (allLevel2ListItems[z].childNodes[0].getAttribute(\"href\").toLowerCase().replaceAll('-',' ').substring(1).indexOf(criteria.toLowerCase()) !== -1) {\n" +
" allLevel2ListItems[z].style.display = 'inline';\n" +
" } else {\n" +
" allLevel2ListItens[z].style.display = 'none';\n" +
" allLevel2ListItems[z].style.display = 'none';\n" +
" }\n" +
" }\n" +
" }//end for allListItens\n" +
Expand All @@ -263,13 +259,13 @@ private void addSearchScript(Element contentElement) {
"}\n" +
"\n" +
"function collectallLevel2IListItens() {\n" +
" allLevel2ListItens = new Array();\n" +
" allLevel2ListItems = new Array();\n" +
" var uls = document.getElementsByClassName('sectlevel2');\n" +
" for (var i = 0; i < uls.length; i++) {\n" +
" for (var j = 0; j < uls[i].childNodes.length; j++) {\n" +
" if (uls[i].childNodes[j].tagName) {\n" +
" if (uls[i].childNodes[j].tagName.toLowerCase() == 'li') {\n" +
" allLevel2ListItens.push(uls[i].childNodes[j]);\n" +
" allLevel2ListItems.push(uls[i].childNodes[j]);\n" +
" }\n" +
"\n" +
" }\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,63 +27,52 @@ public class CukedoctorStyleExtension extends Postprocessor {

private static final Logger LOG = Logger.getLogger(CukedoctorStyleExtension.class.getName());

public static final String BASE_DIR = Files.exists(Paths.get("target")) ? Paths.get("target").toString() :
public static final String BASE_DIR = Files.exists(Paths.get("target")) ? Paths.get("target").toString() :
Files.exists(Paths.get("bin")) ? Paths.get("bin").toString() : Paths.get("").toString();

public static final String CUKEDOCTOR_CUSTOMIZATION_DIR = getProperty("CUKEDOCTOR_CUSTOMIZATION_DIR") == null ? BASE_DIR : getProperty("CUKEDOCTOR_CUSTOMIZATION_DIR");


public CukedoctorStyleExtension(Map<String, Object> config) {
super(config);
}

@Override
public String process(Document document, String output) {
if (document.basebackend("html")) {
org.jsoup.nodes.Document doc = Jsoup.parse(output, "UTF-8");


if (System.getProperty(STYLE_DISABLE_EXT_KEY) == null) {
Element contentElement = doc.getElementById("footer");
addFooterStyle(contentElement);
addCukedoctorCss(doc);
}

return doc.html();

} else {
return output;
}
}

private void addFooterStyle(Element contentElement) {
String styleClass = " <style> \n" + "\n" + "#content:padding:0!important;\n" + ".sidebarblock, .sectionbody, .content{\n" + "overflow:auto!important;\n" + "}\ndiv.sidebarblock {overflow-y:hidden;overflow-x:auto}\n body .exampleblock > .content{ background:#fff}";

contentElement.after(styleClass);
}

private void addCukedoctorCss(org.jsoup.nodes.Document document) {
List<String> files = FileUtil.findFiles(CUKEDOCTOR_CUSTOMIZATION_DIR, "cukedoctor.css", true);
if(files != null && !files.isEmpty()) {
if (files != null && !files.isEmpty()) {
String themePath = files.get(0);
themePath = themePath.replaceAll("\\\\","/");
themePath = themePath.replaceAll("\\\\", "/");
try {
String customCss = IOUtils.toString(new FileInputStream(themePath));
Elements head = document.getElementsByTag("head");
head.append(" <style> "+customCss+"</style>");
head.append(" <style> " + customCss + "</style>");
} catch (IOException e) {
LOG.log(Level.SEVERE, "Could not copy cukedoctor css from: " + themePath, e);
}
}
}

private static String getProperty(String property) {
if(System.getProperty(property) == null){
if (System.getProperty(property) == null) {
return null;
}
return System.getProperty(property);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
*/
public class CukedoctorThemeExtension extends Postprocessor {

public CukedoctorThemeExtension(Map<String, Object> config) {
super(config);
}

@Override
public String process(Document document, String output) {
if (document.basebackend("html") && System.getProperty(THEME_DISABLE_EXT_KEY) == null) {
Expand Down
9 changes: 2 additions & 7 deletions cukedoctor-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@
<artifactId>cukedoctor-converter</artifactId>
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj-pdf</artifactId>
</dependency>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj</artifactId>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-complete</artifactId>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj-pdf</artifactId>
</dependency>
<dependency>
<groupId>com.beust</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.github.cukedoctor.parser.FeatureParser;
import com.github.cukedoctor.util.FileUtil;
import org.asciidoctor.Asciidoctor;
import org.asciidoctor.Attributes;
import org.asciidoctor.OptionsBuilder;
import org.asciidoctor.SafeMode;
import org.asciidoctor.extension.ExtensionGroup;
Expand Down Expand Up @@ -260,7 +259,6 @@ public String execute(List<Feature> features, DocumentAttributes documentAttribu
if (documentAttributes.getBackend().equalsIgnoreCase("pdf")) {
cukedoctorExtensionGroup.unregister();
}

OptionsBuilder ob = OptionsBuilder.options()
.safe(SafeMode.UNSAFE)
.backend(documentAttributes.getBackend())
Expand Down
Loading

0 comments on commit 4ad1e9a

Please sign in to comment.