public Writer run(Writer writer, List<Object> scopes) { if (codes != null) { for (Code code : codes) { writer = code.execute(writer, scopes); } } return writer; }
public Writer run(Writer writer, List<Object> scopes) { if (codes != null) { for (Code code : codes) { writer = code.execute(writer, scopes); } } return writer; }
public Writer run(Writer writer, List<Object> scopes) { if (codes != null) { for (Code code : codes) { writer = code.execute(writer, scopes); } } return writer; }
/** * 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 Writer run(Writer writer, List<Object> scopes) { if (getCodes() != null) { for (Code code : getCodes()) { try (StringWriter capture = new StringWriter()) { code.execute(capture, scopes); String s = capture.toString(); if (s != null) { encoder.encode(s, writer); } } catch (IOException e) { throw new MustacheException("Exception while parsing mustache function at line " + tc.line(), e); } } } return writer; }
/** * 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); } } }
/** * 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 Writer run(Writer writer, List<Object> scopes) { if (getCodes() != null) { for (Code code : getCodes()) { try (StringWriter capture = new StringWriter()) { code.execute(capture, scopes); String s = capture.toString(); if (s != null) { encoder.encode(s, writer); } } catch (IOException e) { throw new MustacheException("Exception while parsing mustache function at line " + tc.line(), e); } } } return writer; }