Expands text containing CTemplate delimiters "{{" using the data object
558132
function expand(template, data) {
    if (template.indexOf("{{") >= 0) {
        let ast = myna.parsers.mustache(template);
        let lines = expandAst(ast, data);
        return lines.join("");
    } 
    else {
        return template;
    }
}
1057712
function parseText(source, delimiters) {
    delimiters = delimiters || ['{{', '}}'];

    var regCacheKey = delimiters[0] + '>..<' + delimiters[1];
    var exprStartReg = delimRegCache[regCacheKey];
    if (!exprStartReg) {
        exprStartReg = new RegExp(
            regexpLiteral(delimiters[0])
                + '\\s*([\\s\\S]+?)\\s*'
                + regexpLiteral(delimiters[1]),
            'g'
        );
        delimRegCache[regCacheKey] = exprStartReg;
    }

    var exprMatch;

    var walker = new Walker(source);
    var beforeIndex = 0;

    var expr = {
        type: ExprType.TEXT,
        segs: []
    };

    function pushStringToSeg(text) {
        text && expr.segs.push({
            type: ExprType.STRING,
            literal: text,
            value: decodeHTMLEntity(text)
        });
    }

    var delimEndLen = delimiters[1].length;
    while ((exprMatch = walker.match(exprStartReg)) != null) {
        var interpSource = exprMatch[1];
        var interpLen = exprMatch[0].length;
        if (walker.cut(walker.index + 1 - delimEndLen, walker.index + 1) === delimiters[1]) {
            interpSource += walker.cut(walker.index, walker.index + 1);
            walker.go(1);
            interpLen++;
        }

        pushStringToSeg(walker.cut(
            beforeIndex,
            walker.index - interpLen
        ));

        var interp = parseInterp(interpSource);
        expr.original = expr.original || interp.original;
        expr.segs.push(interp);

        beforeIndex = walker.index;
    }

    pushStringToSeg(walker.cut(beforeIndex));



    if (expr.segs.length === 1 && expr.segs[0].type === ExprType.STRING) {
        expr.value = expr.segs[0].value;
    }

    return expr;
}
675404
private String expandTemplates(String message, JsonNode entityJson) throws IOException, TemplateException {
    // Read entityJSON data
    Map<String, Object> data = new HashMap<>();
    data.put("data", MAPPER.convertValue(entityJson, Map.class));
    data.put("entity", MAPPER.convertValue(entityJson, Map.class));

    // Read MessageMLV2 template
    StringWriter sw = new StringWriter();
    Template template = new Template("messageML", message, FREEMARKER);

    // Expand the template
    template.process(data, sw);

    return sw.toString();
  }
859522
public TemplateBuilder pe(Object o, Escape escape) {
        if (null != o) {
            if (o instanceof RawData) {
                return (TemplateBuilder) p(o);
            }
            if (null == escape) {
                escape = __defaultEscape();
            }
            switch (escape) {
                case RAW:
                    return (TemplateBuilder) p(S.raw(o));
                case HTML:
                    return (TemplateBuilder) p(S.escapeHtml(o));
                case JSON:
                    return (TemplateBuilder) p(S.escapeJson(o));
                case JS:
                    return (TemplateBuilder) p(S.escapeJavaScript(o));
                case CSV:
                    return (TemplateBuilder) p(S.escapeCsv(o));
                case XML:
                    return (TemplateBuilder) p(S.escapeXml(o));
            }
        }
        return this;
    }
454620
def expand_mapping_target(namespaces, val):
    """"""

    vals = [v.strip() for v in val.split(',')]
    ret = []
    for v in vals:
        inverse = False
        if v.startswith('^'):
            inverse = True
            v = v[1:]
        ret.append((expand_curielike(namespaces, v), inverse))
    return ret
1115314
function (template, data) {
            var p;
            for (p in data) {
                if (data.hasOwnProperty(p)) {
                    template = template.replace(new RegExp('\\{\\{' + p + '\\}\\}', 'g'), data[p]);
                }
            }
            return template;
        }
113492
def expand_abbreviations(template, abbreviations):
    
    if template in abbreviations:
        return abbreviations[template]

    # Split on colon. If there is no colon, rest will be empty
    # and prefix will be the whole template
    prefix, sep, rest = template.partition(':')
    if prefix in abbreviations:
        return abbreviations[prefix].format(rest)

    return template
1071550
def _expand(self, str, local_vars={}):
        """"""
        return ninja_syntax.expand(str, self.vars, local_vars)
77827
function parseStringAttrs(templates, context) {
  var stringAttrs = '';
  var toString = new ToString(true, true);
  for (var i = 0; i < templates.length; i++) {
    toString.clear();
    render(toString, templates[i], context);
    stringAttrs += ' ' + toString.getOutput() + ' ';
  }
  if (whitespaceOnlyRegex.test(stringAttrs)) {
    return null;
  }
  var node = htmlParser('<div ' + stringAttrs + '></div>');
  return node.properties.attributes;
}
824834
function compileTemplate(str) {
    return new Function(
      tmpl.arg,
      "var _e=tmpl.encode" + tmpl.helper + ",_s='" +
        str.replace(tmpl.regexp, tmpl.func)
           .replace(/(<\/?)(script>)/, "$1' + '$2" ) +
        "';return _s;"
    );
  }
451544
function template(string, data) {
  var proxyRegEx = /\{\{([^\}]+)?\}\}/g;
  return string.replace(proxyRegEx, function(_, key) {
    var keyParts = key.split('.');
    var value = data;
    for (var i = 0; i < keyParts.length; i++) {
      value = value[keyParts[i]];
    }
    return value || '';
  });
}
65463
function(apiKey, templateId, pieceTitle,
        category, fromAddress, toAddress, ccAddress, bccAddresses, subject,
        textBody, htmlBody, contentType, mergeContext) {}
1091104
function(template_data, template_name) {
        var precompiled_template,
            regex = /{([^{}]*)}/g;

        // replace double quotes with single quotes
        precompiled_template = template_data.replace(/\"/g, "'");

        // split each line, enclose in double quotes & join them using + sign
        precompiled_template = precompiled_template.split("\n").map(
          function(line) {
            return '"' + line.trim() + '"';
          }).join(" \t+\n ");

        // replace the curly braces with the variables
        precompiled_template = precompiled_template.replace(
          regex, function(a, b) {
            return '" + data.' + b + ' + "';
          });

        return "(function() {\n\t" +
                  "window." + template_namespace + ' = window.' + template_namespace + ' || {};\n\t' +
                  template_namespace + '["' + template_name + '"] = ' + 'function(data) {\n\t\t' +
                    'return ' + precompiled_template + ';\n\t' +
                  '};\n' +
                '})();';
      }
85100
function  updateTemplate(tbName, schema, columns, inData)  {
	var  insertObj = {},
		 jsonObj = {},
		 schemaCol = schema.columns,
		 isNewSQL = schemaCol.indexOf('_c_json') >= 0;

	// if columns are specified in the SQL expression, remove input data which are
	// not  specified in columns
	if (columns)  {
		var  ndata = {},
			 keys = Object.getOwnPropertyNames(inData);
		for (var i in keys)  {
			var  key = keys[i];
			if (columns.indexOf(key) >= 0)
				ndata[key] = inData[key];
		}
		inData = ndata;
	}
	
	// needs to decide what goes to sql columns and what goes to the json column
	var  keys = Object.getOwnPropertyNames(inData);
	for (var i in keys)  {
		var  key = keys[i];
		if (schemaCol.indexOf(key) >= 0)
			insertObj[key] = inData[key];
		else  if (isNewSQL)
			jsonObj[key] = inData[key];
	}

	var  insertCol = Object.keys( insertObj );
	if (Object.keys(jsonObj).length)  {
		// prepare the json column
		insertCol.push('_c_json');
		//insertObj._c_json = JSON.stringify(jsonObj);
	}

	var  updateSBI = soar.sqlTemplate(tbName);
	updateSBI.column( insertCol );

	return  {sbi: updateSBI, data: insertObj, _c_json: jsonObj};
}
54017
function (template) {
    var pattern = _.template(template)(fileReplace);
    pattern = pattern.replace(/\//g, '\\/');
    pattern = pattern.replace(/\s+/g, '\\s*');
    pattern = '\\s*' + pattern + '\\s*';
    return new RegExp(pattern);
}
891431
function expandAst(ast, data, lines) {
    if (lines == undefined)
        lines = [];
    
    // If there is a child "key" get the value associated with it. 
    let keyNode = ast.child("key");
    let key = keyNode ? keyNode.allText : "";
    let val = data ? (key in data ? data[key] : "") : "";

    // Functions are not supported
    if (typeof(val) == 'function')
        throw new Exception('Functions are not supported');

    switch (ast.rule.name) 
    {
        case "document":    
        case "sectionContent":
            ast.children.forEach(function(c) { 
                expandAst(c, data, lines); });
            return lines;

        case "comment":
            return lines;

        case "plainText":
            lines.push(ast.allText);
            return lines;

        case "section":        
            let content = ast.child("sectionContent");
            if (typeof val === "boolean" || typeof val === "number" || typeof val === "string") {
                if (val) 
                    expandAst(content, data, lines);
            }
            else if (val instanceof Array) {
                for (let x of val)
                    expandAst(content, mergeObjects(data, x), lines);
            }                
            else {
                expandAst(content, mergeObjects(data, val), lines);
            }
            return lines;

        case "invertedSection":
            if (!val || ((val instanceof Array) && val.length == 0))
                expandAst(ast.child("sectionContent"), data, lines);
            return lines;

        case "escapedVar":
            if (val) 
                lines.push(
                    expand(escapeHtmlChars(String(val)), data));
            return lines;
        
        case "unescapedVar":
            if (val) 
                lines.push(
                    expand(String(val), data));
            return lines;
    }
            
    throw "Unrecognized AST node " + ast.rule.name;
}
831794
public static String expand(final String templateString, Map<String, Object> values)
    throws MalformedUriTemplateException, VariableExpansionException
    {
        UriTemplate t = new UriTemplate(templateString);
        t.set(values);
        return t.expand();
    }