Skip to content

Commit

Permalink
some refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
clagomess committed Mar 7, 2024
1 parent 3d5193e commit 2d6d11d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,54 @@ public FeatureToPDFCompiler(ParametersDto parameters) {
public void build() throws Exception {
File bufferHtml = File.createTempFile("pirilampo-buffer-", ".html");
log.info("Created buffer file: {}", bufferHtml);
File outArtifact = getOutArtifact(parameters);

try (
FileOutputStream fos = new FileOutputStream(bufferHtml);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, StandardCharsets.UTF_8));
PrintWriter out = new PrintWriter(bw);
FileOutputStream fosPDF = new FileOutputStream(outArtifact);
InputStream css = Objects.requireNonNull(Thread.currentThread().getContextClassLoader()
.getResource("htmlTemplate/dist/feature-pdf.min.css"))
.openStream();
){
out.print("<!DOCTYPE html><html lang=\"en\"><body>");
out.print("<h1 class=\"page-header\">");
out.print(String.format(
"%s <small>%s <em>%s</em></small>",
parameters.getProjectName(),
featureMetadataDto.getName(),
parameters.getProjectVersion()
));
out.print("</h1>");
parameters.setEmbedImages(false);

new GherkinDocumentParser(parameters, feature).build(out);
PdfParser pdfParser = new PdfParser(parameters, css);
pdfParser.initDocument(fosPDF);

out.print("</body></html>");
}
try (
FileOutputStream fos = new FileOutputStream(bufferHtml);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, StandardCharsets.UTF_8));
PrintWriter out = new PrintWriter(bw);
){
out.print("<!DOCTYPE html><html lang=\"en\"><body>");
out.print("<h1 class=\"page-header\">");
out.print(String.format(
"%s <small>%s <em>%s</em></small>",
parameters.getProjectName(),
featureMetadataDto.getName(),
parameters.getProjectVersion()
));
out.print("</h1>");

// @TODO: maibe a pipe with these streams?
new GherkinDocumentParser(parameters, feature).build(out);

try (
FileOutputStream fos = new FileOutputStream(getOutArtifact(parameters));
InputStream html = Files.newInputStream(bufferHtml.toPath());
InputStream css = Objects.requireNonNull(Thread.currentThread().getContextClassLoader()
.getResource("htmlTemplate/dist/feature-pdf.min.css"))
.openStream();
){
// new PdfParser().build(fos, html, css, parameters.getLayoutPdf()); @TODO: fix
out.print("</body></html>");
} catch (Throwable e){
bufferHtml.delete();
throw e;
} finally {
if(bufferHtml.exists()){
pdfParser.addFeatureHTML(feature, Files.newInputStream(bufferHtml.toPath()));
}

bufferHtml.delete();
}

pdfParser.closeDocument();
} catch (Throwable e){
outArtifact.delete();
throw e;
}

// @TODO: remove buffer file
// @TODO: add done and took
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,20 @@ public void build() throws Exception {
));
out.print("</h1>");

new GherkinDocumentParser(parameters, feature).build(out);
GherkinDocumentParser parser = new GherkinDocumentParser(parameters, feature);
parser.build(out);

out.print("<span style=\"page-break-after: always\"></span>");

if(!parser.getPaginaHtmlAnexo().isEmpty()){
for(File html : parser.getPaginaHtmlAnexo()){
log.info("- appending: {}", html);
out.print(String.format("<h1>%s</h1>", html.getName()));
writeFileToOut(html, out);
out.print("<span style=\"page-break-after: always\"></span>");
}
}

out.print("</body></html>");
} catch (Throwable e){
bufferHtml.delete();
Expand Down

0 comments on commit 2d6d11d

Please sign in to comment.