Skip to content

Allow hyphen seperated template variables #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/template.js
Original file line number Diff line number Diff line change
@@ -47,12 +47,12 @@ JsonTemplate.prototype.compile = function() {

function parse(item) {
let matched = false;
const templates = /\{(([\!\^]?[a-zA-Z\$_][\w\$]*)\s*(=([^:]+))?(:(\w+))?)\}/g;
const templates = /\{(([\!\^]?[a-zA-Z\$_][\w\$-]*)\s*(=([^:]+))?(:(\w+))?)\}/g;
/* eslint-disable no-cond-assign */
while (match = templates.exec(item)) {
/* eslint-enable no-cond-assign */
matched = true;
const param = /([[\!\^]?[a-zA-Z\$_][\w\$]*)\s*(=([^:]+))?(:(\w+))?/.exec(match[1]);
const param = /([[\!\^]?[a-zA-Z\$_][\w\$-]*)\s*(=([^:]+))?(:(\w+))?/.exec(match[1]);
if (!param || !param[1]) {
throw new Error(g.f('Invalid parameter: %s', match[1]));
}
@@ -120,7 +120,7 @@ JsonTemplate.prototype.build = function(parameters) {
function transform(obj) {
return traverse(obj).map(function(item) {
const ctx = this;
const templates = /\{(([\!\^]?[a-zA-Z\$_][\w\$]*)\s*(=([^:\{\}]+))?(:(\w+))?)\}/g;
const templates = /\{(([\!\^]?[a-zA-Z\$_][\w\$-]*)\s*(=([^:\{\}]+))?(:(\w+))?)\}/g;
function build(item) {
let match = null;
const parsed = [];
@@ -134,7 +134,7 @@ JsonTemplate.prototype.build = function(parameters) {
parsed.push(item.substring(index, match.index));
}
// The variable pattern is {name=defaultValue:type}
const param = /([\!\^]?[a-zA-Z\$_][\w\$]*)\s*(=([^:\{\}]+))?(:(\w+))?/.exec(match[1]);
const param = /([\!\^]?[a-zA-Z\$_][\w\$-]*)\s*(=([^:\{\}]+))?(:(\w+))?/.exec(match[1]);
if (!param || !param[1]) {
throw new Error(g.f('Invalid parameter: %s', match[1]));
}