...
 
Commits (2)
......@@ -46,7 +46,7 @@ public class OutputPreprocessor extends AngularPreprocessor {
Element outputElement = new Element("div");
outputElement.val("{" + model.getName().toLowerCase() + "." + field.getName() + "}");
outputElement.append("{{" + model.getName().toLowerCase() + "." + field.getName() + "}}");
copyAttributes(element, outputElement);
return outputElement;
......
......@@ -11,7 +11,7 @@ import static sk.tuke.bfi.core.preprocessor.html.BfiAttribute.BFI_FIELD;
import static sk.tuke.bfi.core.preprocessor.html.BfiAttribute.BFI_MODEL;
import static sk.tuke.bfi.core.preprocessor.html.BfiTag.BFI;
@Preprocessor("table")
@Preprocessor("tb")
public class TablePreprocessor extends AngularPreprocessor {
@Override
......@@ -21,54 +21,67 @@ public class TablePreprocessor extends AngularPreprocessor {
element.tagName(nodeName);
Element table = new Element("table");
table.appendChild(getHeader(element));
table.appendChild(getBody(element));
table.appendChild(getHeader(element.getElementsByTag("bfi-tb-header").first()));
table.appendChild(getBody(element.getElementsByTag("bfi-tb-body").first()));
element.replaceWith(table);
}
private Element getHeader(final Element column) {
private Element getHeader(final Element row) {
final Element tableHeader = new Element("thead");
final Element tableRow = new Element("tr");
tableHeader.appendChild(tableRow);
for (Element element : column.getAllElements()) {
for (Element element : row.getElementsByTag("bfi-tb-th").first().getElementsByTag("bfi-tb-td")) {
final Element tableColumn = new Element("th");
try {
tableColumn.val(getField(element).getLabel());
Field field = getField(element);
if (field == null) {
tableColumn.append(element.html());
} else {
tableColumn.append(getField(element).getLabel());
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
continue;
}
copyAttributes(element, tableColumn);
tableRow.appendChild(tableColumn);
}
return tableHeader;
}
private Element getBody(final Element column) {
private Element getBody(final Element row) {
final Element tableBody = new Element("tbody");
final Element tableRow = new Element("tr");
Model model = null;
tableBody.appendChild(tableRow);
for (Element element : column.getAllElements()) {
for (Element element : row.getElementsByTag("bfi-tb-tr").first().getElementsByTag("bfi-tb-td")) {
final Element tableColumn = new Element("td");
final Field field;
try {
field = getField(element);
if(model==null){
if (model == null && field != null) {
model = field.getModel();
}
tableColumn.val(String.format("{%s.%s}", field.getModel().getName(), field.getName()));
if (field == null) {
tableColumn.append(element.html());
} else {
String spec= element.attr("bfi-attribute");
tableColumn.append(String.format("{{item.%s}}", field.getName()) + element.html());
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
continue;
}
copyAttributes(element, tableColumn);
tableRow.appendChild(tableColumn);
}
tableRow.attr("*ngFor",String.format("let item of %s",model.getName()));
tableRow.attr("*ngFor", String.format("let item of %ss", model.getName().toLowerCase()));
return tableBody;
}
......@@ -77,11 +90,17 @@ public class TablePreprocessor extends AngularPreprocessor {
Model model = null;
final String modelName = element.attr(BFI_MODEL.toString());
final String fieldName = element.attr(BFI_FIELD.toString());
if (("").equals(modelName) || ("").equals(modelName)) {
return null;
}
model = getModel(modelName);
final Field field = model.getField(fieldName);
String[] fieldParts = fieldName.split("\\.");
final Field field = model.getField(fieldParts[0]);
if (field == null) {
throw new Exception("Field " + fieldName + " is not exist in model " + modelName);
throw new Exception("Field " + fieldParts[0] + " is not exist in model " + modelName);
}
if(fieldParts.length>0){
field.setName(fieldName);
}
return field;
}
......
......@@ -7,6 +7,8 @@ import org.apache.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Node;
import org.jsoup.parser.ParseSettings;
import org.jsoup.parser.Parser;
import org.stringtemplate.v4.ST;
import org.stringtemplate.v4.STGroup;
import sk.tuke.bfi.core.builder.impl.LanguageBuilder;
......@@ -32,6 +34,8 @@ import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import static sk.tuke.bfi.core.GeneratorState.getGeneratorState;
......@@ -155,7 +159,9 @@ public class GeneratorImpl implements sk.tuke.bfi.core.generator.Generator {
Document doc = null;
try {
doc = Jsoup.parse(file, null);
Parser parser = Parser.htmlParser();
parser.settings(new ParseSettings(true, true));
doc = parser.parseInput(new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())), "UTF-8"), "/");
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
return;
......