public Writer run(Writer writer, List<Object> scopes) { if (codes != null) { for (Code code : codes) { writer = code.execute(writer, scopes); } } return writer; }
protected void runIdentity(Writer writer) { int length = getCodes().length; for (int i = 0; i < length; i++) { getCodes()[i].identity(writer); } }
private void walk(Code test, int depth) { for (Code code : test.getCodes()) { if (code instanceof ValueCode) { indent(depth); System.out.println("- " + code.getName()); } else if (code instanceof NotIterableCode) { System.out.println("^" + code.getName()); walk(code, depth + 2); } else if (code instanceof IterableCode) { System.out.println("#" + code.getName()); walk(code, depth + 2); } } }
/** * At compile time, this function extracts the name of the variable: * {{#toJson}}variable_name{{/toJson}} */ protected static String extractVariableName(String fn, Mustache mustache, TemplateContext tc) { Code[] codes = mustache.getCodes(); if (codes == null || codes.length != 1) { throw new MustacheException("Mustache function [" + fn + "] must contain one and only one identifier"); } try (StringWriter capture = new StringWriter()) { // Variable name is in plain text and has type WriteCode if (codes[0] instanceof WriteCode) { codes[0].execute(capture, Collections.emptyList()); return capture.toString(); } else { codes[0].identity(capture); return capture.toString(); } } catch (IOException e) { throw new MustacheException("Exception while parsing mustache function [" + fn + "] at line " + tc.line(), e); } } }
@Override public void write(TemplateContext tc, final String text) { if (text.length() > 0) { int size = list.size(); if (size > 0) { Code code = list.get(size - 1); code.append(text); } else { list.add(new WriteCode(tc, df, text)); } } }
@Override public synchronized void init() { filterText(); Code[] codes = getCodes(); if (codes != null) { for (Code code : codes) { code.init(); } } }
@Override public Node invert(Node node, String text, AtomicInteger position) { int start = position.get(); Code[] codes = getCodes(); if (codes != null) { for (Code code : codes) { Node invert = code.invert(node, text, position); if (invert == null) { position.set(start); return null; } } } return matchAppended(node, text, position, start); }
public Object clone(Set<Code> seen) { try { DefaultCode code = (DefaultCode) super.clone(); Code[] codes = code.getCodes(); if (codes != null) { // Create a new set of codes codes = codes.clone(); for (int i = 0; i < codes.length; i++) { // If the code hasn't been seen before // use this one, else clone it. if (!seen.add(codes[i])) { codes[i] = (Code) codes[i].clone(seen); seen.remove(codes[i]); } } code.setCodes(codes); } if (mustache != null) { if (!seen.add(mustache)) { code.mustache = (Mustache) mustache.clone(seen); seen.remove(mustache); } } return code; } catch (CloneNotSupportedException e) { throw new MustacheException("Clone not supported", e, tc); } }
/** * At compile time, this function extracts the name of the variable: * {{#toJson}}variable_name{{/toJson}} */ protected static String extractVariableName(String fn, Mustache mustache, TemplateContext tc) { Code[] codes = mustache.getCodes(); if (codes == null || codes.length != 1) { throw new MustacheException("Mustache function [" + fn + "] must contain one and only one identifier"); } try (StringWriter capture = new StringWriter()) { // Variable name is in plain text and has type WriteCode if (codes[0] instanceof WriteCode) { codes[0].execute(capture, Collections.emptyList()); return capture.toString(); } else { codes[0].identity(capture); return capture.toString(); } } catch (IOException e) { throw new MustacheException("Exception while parsing mustache function [" + fn + "] at line " + tc.line(), e); } } }
@Override public void write(TemplateContext tc, final String text) { if (text.length() > 0) { int size = list.size(); if (size > 0) { Code code = list.get(size - 1); code.append(text); } else { list.add(new WriteCode(tc, df, text)); } } }
@Override public synchronized void init() { filterText(); Code[] codes = getCodes(); if (codes != null) { for (Code code : codes) { code.init(); } } }
@Override public Node invert(Node node, String text, AtomicInteger position) { int start = position.get(); Code[] codes = getCodes(); if (codes != null) { for (Code code : codes) { Node invert = code.invert(node, text, position); if (invert == null) { position.set(start); return null; } } } return matchAppended(node, text, position, start); }
public Object clone(Set<Code> seen) { try { DefaultCode code = (DefaultCode) super.clone(); Code[] codes = code.getCodes(); if (codes != null) { // Create a new set of codes codes = codes.clone(); for (int i = 0; i < codes.length; i++) { // If the code hasn't been seen before // use this one, else clone it. if (!seen.add(codes[i])) { codes[i] = (Code) codes[i].clone(seen); seen.remove(codes[i]); } } code.setCodes(codes); } if (mustache != null) { if (!seen.add(mustache)) { code.mustache = (Mustache) mustache.clone(seen); seen.remove(mustache); } } return code; } catch (CloneNotSupportedException e) { throw new MustacheException("Clone not supported", e, tc); } }
/** * At compile time, this function extracts the name of the variable: * {{#toJson}}variable_name{{/toJson}} */ protected static String extractVariableName(String fn, Mustache mustache, TemplateContext tc) { Code[] codes = mustache.getCodes(); if (codes == null || codes.length != 1) { throw new MustacheException("Mustache function [" + fn + "] must contain one and only one identifier"); } try (StringWriter capture = new StringWriter()) { // Variable name is in plain text and has type WriteCode if (codes[0] instanceof WriteCode) { codes[0].execute(capture, Collections.emptyList()); return capture.toString(); } else { codes[0].identity(capture); return capture.toString(); } } catch (IOException e) { throw new MustacheException("Exception while parsing mustache function [" + fn + "] at line " + tc.line(), e); } } }
public Writer run(Writer writer, List<Object> scopes) { if (codes != null) { for (Code code : codes) { writer = code.execute(writer, scopes); } } return writer; }
protected void runIdentity(Writer writer) { int length = getCodes().length; for (int i = 0; i < length; i++) { getCodes()[i].identity(writer); } }
@Override public void write(TemplateContext tc, final String text) { if (text.length() > 0) { int size = list.size(); if (size > 0) { Code code = list.get(size - 1); code.append(text); } else { list.add(new WriteCode(tc, df, text)); } } }
@Override public synchronized void init() { filterText(); Code[] codes = getCodes(); if (codes != null) { for (Code code : codes) { code.init(); } } }