Skip to content

Commit

Permalink
translation
Browse files Browse the repository at this point in the history
  • Loading branch information
clagomess committed Mar 6, 2024
1 parent a434690 commit f14ff9a
Show file tree
Hide file tree
Showing 28 changed files with 243 additions and 249 deletions.
44 changes: 22 additions & 22 deletions core/src/main/java/br/com/pirilampo/core/compilers/Compiler.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package br.com.pirilampo.core.compilers;

import br.com.pirilampo.core.dto.FeatureMetadataDto;
import br.com.pirilampo.core.dto.ParametroDto;
import br.com.pirilampo.core.enums.ArtefatoEnum;
import br.com.pirilampo.core.enums.CompilacaoEnum;
import br.com.pirilampo.core.dto.ParametersDto;
import br.com.pirilampo.core.enums.CompilationArctifactEnum;
import br.com.pirilampo.core.enums.CompilationTypeEnum;
import org.apache.commons.io.input.BOMInputStream;

import java.io.*;
Expand Down Expand Up @@ -31,7 +31,7 @@ protected List<File> listFolder(File curDir) throws Exception {

private void listFolder(List<File> buffer, File curDir) throws Exception {
File[] filesList = curDir.listFiles();
if(filesList == null) throw new Exception("Pasta não localizada!");
if(filesList == null) throw new Exception("*.features not found");

for (File f : filesList) {
if (f.isDirectory()) listFolder(buffer, f);
Expand All @@ -42,12 +42,12 @@ private void listFolder(List<File> buffer, File curDir) throws Exception {
}
}

protected FeatureMetadataDto getFeatureMetadata(ParametroDto parametro, File feature){
protected FeatureMetadataDto getFeatureMetadata(ParametersDto parameters, File feature){
String htmlFeatureRoot = feature.getAbsolutePath()
.replace(parametro.getTxtSrcFonte().getAbsolutePath(), "");
.replace(parameters.getProjectSource().getAbsolutePath(), "");

if(parametro.getTxtSrcFonteMaster() != null){
htmlFeatureRoot = htmlFeatureRoot.replace(parametro.getTxtSrcFonteMaster().getAbsolutePath(), "");
if(parameters.getProjectMasterSource() != null){
htmlFeatureRoot = htmlFeatureRoot.replace(parameters.getProjectMasterSource().getAbsolutePath(), "");
}

htmlFeatureRoot = htmlFeatureRoot.replace(feature.getName(), "")
Expand All @@ -63,27 +63,27 @@ protected FeatureMetadataDto getFeatureMetadata(ParametroDto parametro, File fea
return result;
}

protected File getOutArtifact(ParametroDto parametro){
if(parametro.getTipCompilacao() == CompilacaoEnum.PASTA){
File targetDir = parametro.getTxtOutputTarget() != null ?
new File(parametro.getTxtOutputTarget(), "html") :
new File(parametro.getTxtSrcFonte().getParent(), "html");
protected File getOutArtifact(ParametersDto parameters){
if(parameters.getCompilationType() == CompilationTypeEnum.FOLDER){
File targetDir = parameters.getProjectTarget() != null ?
new File(parameters.getProjectTarget(), "html") :
new File(parameters.getProjectSource().getParent(), "html");

if(!targetDir.exists() && !targetDir.mkdir()){
throw new RuntimeException(String.format("Failed to create dir: %s", targetDir.getAbsolutePath()));
}

return new File(targetDir, parametro.getArtefato() == ArtefatoEnum.HTML ? "index.html" : "index.pdf");
return new File(targetDir, parameters.getCompilationArctifact() == CompilationArctifactEnum.HTML ? "index.html" : "index.pdf");
}else{
String filename = String.format(
"%s.%s",
getFeatureMetadata(parametro, parametro.getTxtSrcFonte()).getName(),
parametro.getArtefato() == ArtefatoEnum.HTML ? "html" : "pdf"
getFeatureMetadata(parameters, parameters.getProjectSource()).getName(),
parameters.getCompilationArctifact() == CompilationArctifactEnum.HTML ? "html" : "pdf"
);

File targetDir = parametro.getTxtOutputTarget() != null ?
parametro.getTxtOutputTarget() :
new File(parametro.getTxtSrcFonte().getParent());
File targetDir = parameters.getProjectTarget() != null ?
parameters.getProjectTarget() :
new File(parameters.getProjectSource().getParent());

return new File(targetDir, filename);
}
Expand Down Expand Up @@ -127,11 +127,11 @@ public String getFeaturePathWithoutAbsolute(File base, File feature){
return resultDiff.replace(File.separator, "/");
}

public File getAbsolutePathFeatureAsset(ParametroDto parametro, File feature, String fileName){
public File getAbsolutePathFeatureAsset(ParametersDto parameters, File feature, String fileName){
Set<File> basePaths = new LinkedHashSet<File>() {{
add(feature.getParentFile());
add(parametro.getTxtSrcFonte());
if(parametro.getTxtSrcFonteMaster() != null) add(parametro.getTxtSrcFonteMaster());
add(parameters.getProjectSource());
if(parameters.getProjectMasterSource() != null) add(parameters.getProjectMasterSource());
}};

for (File basePath : basePaths) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
package br.com.pirilampo.core.compilers;

import br.com.pirilampo.core.dto.FeatureMetadataDto;
import br.com.pirilampo.core.dto.ParametroDto;
import br.com.pirilampo.core.dto.ParametersDto;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class FeatureToHTMLCompiler extends Compiler {
private final ParametroDto parametro;
private final ParametersDto parameters;
private final File feature;
private final FeatureMetadataDto featureMetadataDto;

public FeatureToHTMLCompiler(ParametroDto parametro) {
this.parametro = parametro;
this.feature = parametro.getTxtSrcFonte();
this.featureMetadataDto = getFeatureMetadata(parametro, feature);
public FeatureToHTMLCompiler(ParametersDto parameters) {
this.parameters = parameters;
this.feature = parameters.getProjectSource();
this.featureMetadataDto = getFeatureMetadata(parameters, feature);
}

public void build() throws Exception {
ParseDocument parseDocument = new ParseDocument(parametro, feature);
ParseDocument parseDocument = new ParseDocument(parameters, feature);

try (
FileOutputStream fos = new FileOutputStream(getOutArtifact(parametro));
FileOutputStream fos = new FileOutputStream(getOutArtifact(parameters));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, StandardCharsets.UTF_8));
PrintWriter out = new PrintWriter(bw);
){
out.print("<!DOCTYPE html><html lang=\"en\"><head>");
out.print("<meta charset=\"utf-8\">");
out.print("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">");
out.print("<meta name=\"viewport\" content=\"width=device-width, shrink-to-fit=no, initial-scale=1\">");
out.print(String.format("<title>%s</title>", parametro.getTxtNome()));
out.print(String.format("<title>%s</title>", parameters.getProjectName()));
out.print("<style>");
writeResourceToOut("htmlTemplate/dist/feature.min.css", out);
out.print("</style>");
out.print("</head><body>");
out.print("<div class=\"container\"><div class=\"row\"><div class=\"col-sm-12\">");
out.print(String.format(
"<h1 class=\"page-header\">%s <small>%s <em>%s</em></small></h1>",
parametro.getTxtNome(),
parameters.getProjectName(),
featureMetadataDto.getName(),
parametro.getTxtVersao()
parameters.getProjectVersion()
));

parseDocument.build(out);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package br.com.pirilampo.core.compilers;

import br.com.pirilampo.core.dto.FeatureMetadataDto;
import br.com.pirilampo.core.dto.ParametroDto;
import br.com.pirilampo.core.dto.ParametersDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -13,14 +13,14 @@
@Slf4j
@RequiredArgsConstructor
public class FeatureToPDFCompiler extends Compiler {
private final ParametroDto parametro;
private final ParametersDto parameters;
private final File feature;
private final FeatureMetadataDto featureMetadataDto;

public FeatureToPDFCompiler(ParametroDto parametro) {
this.parametro = parametro;
this.feature = parametro.getTxtSrcFonte();
this.featureMetadataDto = getFeatureMetadata(parametro, feature);
public FeatureToPDFCompiler(ParametersDto parameters) {
this.parameters = parameters;
this.feature = parameters.getProjectSource();
this.featureMetadataDto = getFeatureMetadata(parameters, feature);
}

public void build() throws Exception {
Expand All @@ -36,27 +36,27 @@ public void build() throws Exception {
out.print("<h1 class=\"page-header\">");
out.print(String.format(
"%s <small>%s <em>%s</em></small>",
parametro.getTxtNome(),
parameters.getProjectName(),
featureMetadataDto.getName(),
parametro.getTxtVersao()
parameters.getProjectVersion()
));
out.print("</h1>");

new ParseDocument(parametro, feature).build(out);
new ParseDocument(parameters, feature).build(out);

out.print("</body></html>");
}

// @TODO: maibe a pipe with these streams?

try (
FileOutputStream fos = new FileOutputStream(getOutArtifact(parametro));
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 ParsePdf().build(fos, html, css, parametro.getTipLayoutPdf());
new ParsePdf().build(fos, html, css, parameters.getLayoutPdf());
}

// @TODO: remove buffer file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import br.com.pirilampo.core.dto.FeatureIndexDto;
import br.com.pirilampo.core.dto.FeatureMasterDto;
import br.com.pirilampo.core.dto.FeatureMetadataDto;
import br.com.pirilampo.core.dto.ParametroDto;
import br.com.pirilampo.core.dto.ParametersDto;
import br.com.pirilampo.core.enums.DiffEnum;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -23,49 +23,49 @@
@RequiredArgsConstructor
public class FolderToHTMLCompiler extends Compiler {
private final ParseImage parseImage = new ParseImage();
private final ParametroDto parametro;
private final ParametersDto parameters;
private final Map<String, FeatureIndexDto> indice = new HashMap<>();
private List<FeatureMasterDto> masterFiles = null;

public static final String HTML_OPEN_TEMPLATE = "<script type=\"text/ng-template\" id=\"%s\">";
public static final String HTML_CLOSE_TEMPLATE = "</script>\n";

protected DiffEnum diffMaster(FeatureMetadataDto featureMetadataDto, File featureBranch, PrintWriter out) throws Exception {
if(parametro.getTxtSrcFonteMaster() == null) return DiffEnum.NAO_COMPARADO;
if(parameters.getProjectMasterSource() == null) return DiffEnum.NOT_COMPARED;

if(masterFiles == null){
masterFiles = listFolder(parametro.getTxtSrcFonteMaster()).stream()
masterFiles = listFolder(parameters.getProjectMasterSource()).stream()
.map(item -> new FeatureMasterDto(
getFeaturePathWithoutAbsolute(parametro.getTxtSrcFonteMaster(), item),
getFeaturePathWithoutAbsolute(parameters.getProjectMasterSource(), item),
item
)).collect(Collectors.toList());
}

if(masterFiles.isEmpty()) return DiffEnum.NAO_COMPARADO;
if(masterFiles.isEmpty()) return DiffEnum.NOT_COMPARED;

String pathFeatureBranch = getFeaturePathWithoutAbsolute(parametro.getTxtSrcFonte(), featureBranch);
String pathFeatureBranch = getFeaturePathWithoutAbsolute(parameters.getProjectSource(), featureBranch);

Optional<FeatureMasterDto> optFeatureMaster = masterFiles.stream()
.filter(item -> item.getPath().equals(pathFeatureBranch))
.findFirst();

DiffEnum diff = DiffEnum.NOVO;
DiffEnum diff = DiffEnum.NEW;
if(optFeatureMaster.isPresent()) {
if (FileUtils.contentEquals(featureBranch, optFeatureMaster.get().getFeature())) {
diff = DiffEnum.IGUAL;
diff = DiffEnum.EQUAL;
} else {
diff = DiffEnum.DIFERENTE;
diff = DiffEnum.DIFFERENT;
}
}

log.info("Diff Master/Branch: {} - {}", diff, featureBranch.getAbsolutePath());

// pula para o proximo
if(diff.equals(DiffEnum.IGUAL)) return diff;
if(diff.equals(DiffEnum.EQUAL)) return diff;

if(optFeatureMaster.isPresent()) {
out.print(String.format(HTML_OPEN_TEMPLATE, "master_" + featureMetadataDto.getIdHtml()));
new ParseDocument(parametro, optFeatureMaster.get().getFeature()).build(out);
new ParseDocument(parameters, optFeatureMaster.get().getFeature()).build(out);
out.print(HTML_CLOSE_TEMPLATE);

out.print(String.format(HTML_OPEN_TEMPLATE, "master_" + featureMetadataDto.getIdFeature()));
Expand All @@ -85,14 +85,14 @@ protected void buildMenu(PrintWriter out){
out.print("<ul class=\"sidebar-nav\">");
out.print("<li class=\"sidebar-brand\">");

if(parametro.getTxtLogoSrc() != null){
String logoString = parseImage.parse(parametro, parametro.getTxtLogoSrc()); //@TODO: transformar em buffer
if(parameters.getProjectLogo() != null){
String logoString = parseImage.parse(parameters, parameters.getProjectLogo()); //@TODO: transformar em buffer
out.print(String.format("<a href=\"#/\"><img class=\"logo\" src=\"%s\"></a>", logoString));
}else{
out.print(String.format(
"<a href=\"#/\">%s <small><em>%s</em></small></a>",
parametro.getTxtNome(),
parametro.getTxtVersao()
parameters.getProjectName(),
parameters.getProjectVersion()
));
}

Expand All @@ -105,8 +105,8 @@ protected void buildMenu(PrintWriter out){
protected void buildTemplateIndex(PrintWriter out){
out.print(String.format(HTML_OPEN_TEMPLATE, "index.html"));
out.print("<div style=\"text-align: center\">");
out.print(String.format("<h1>%s</h1>", parametro.getTxtNome()));
out.print(String.format("<small><em>%s</em></small>", parametro.getTxtVersao()));
out.print(String.format("<h1>%s</h1>", parameters.getProjectName()));
out.print(String.format("<small><em>%s</em></small>", parameters.getProjectVersion()));
out.print("</div>");
out.print(HTML_CLOSE_TEMPLATE);
}
Expand All @@ -118,41 +118,40 @@ protected void buildIndex(PrintWriter out) throws JsonProcessingException {
}

public void build() throws Exception {
ParseMenu parseMenu = new ParseMenu(parametro);
ParseMenu parseMenu = new ParseMenu(parameters);

// Popula com arquivos feature
final List<File> arquivos = listFolder(parametro.getTxtSrcFonte());
final List<File> arquivos = listFolder(parameters.getProjectSource());
if(arquivos.isEmpty()) return;

try (
FileOutputStream fos = new FileOutputStream(getOutArtifact(parametro));
FileOutputStream fos = new FileOutputStream(getOutArtifact(parameters));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, StandardCharsets.UTF_8));
PrintWriter out = new PrintWriter(bw);
){
out.print("<!DOCTYPE html><html lang=\"en\" data-ng-app=\"pirilampoApp\"><head>");
out.print("<meta charset=\"utf-8\">");
out.print("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">");
out.print("<meta name=\"viewport\" content=\"width=device-width, shrink-to-fit=no, initial-scale=1\">");
out.print(String.format("<title>%s</title>", parametro.getTxtNome()));
out.print(String.format("<title>%s</title>", parameters.getProjectName()));
out.print("<style>");
writeResourceToOut("htmlTemplate/dist/feature-pasta.min.css", out);
out.print("\n\n");
out.print(String.format(
"#sidebar-wrapper {background: %s;}",
parametro.getClrMenu()
parameters.getMenuColor()
));
out.print(String.format(
"#menu-toggle {background: %s; color: %s;}",
parametro.getClrMenu(),
parametro.getClrTextoMenu()
parameters.getMenuColor(),
parameters.getMenuTextColor()
));
out.print(String.format(
".sidebar-nav li a:hover, .sidebar-nav li a { color: %s;}",
parametro.getClrTextoMenu()
parameters.getMenuTextColor()
));
out.print(String.format(
".sidebar-nav > li {border-bottom: 1px solid %s;}",
parametro.getClrTextoMenu()
parameters.getMenuTextColor()
));
out.print("</style>");
out.print("</head><body>\n");
Expand All @@ -169,14 +168,14 @@ public void build() throws Exception {
progressNum++;

// monta nome menu
FeatureMetadataDto featureMetadataDto = getFeatureMetadata(parametro, f);
FeatureMetadataDto featureMetadataDto = getFeatureMetadata(parameters, f);

// Processa Diff Master
DiffEnum diff = diffMaster(featureMetadataDto, f, out);
if(diff == DiffEnum.IGUAL) continue;
if(diff == DiffEnum.EQUAL) continue;

// Gera a feture
ParseDocument pd = new ParseDocument(parametro, f);
ParseDocument pd = new ParseDocument(parameters, f);
out.print(String.format(HTML_OPEN_TEMPLATE, featureMetadataDto.getIdHtml()));
pd.build(out);
out.print(HTML_CLOSE_TEMPLATE);
Expand Down
Loading

0 comments on commit f14ff9a

Please sign in to comment.