We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
{{#?}} and {{#~}}
{{#?}}
{{#~}}
The text was updated successfully, but these errors were encountered:
The following is just a try (can copy and paste it to node REPL) for demonstration that how to implement compile-time conditionals:
let src3 = ` Hello! {{& def.DEBUG }} the debug version... {{&& def.DEBUG2 }} the debug2 version... {{&&}} the release version... aaa {::{& def.HAS_BBB }::} bbb {::{&}::} ccc {{&}} `; let def = { HAS_BBB: true, }; function resolve_static_if(s) { return s.replace(/\{(:*)\{&\s*([\s\S]*?)\s*\}\1\}([\s\S]*?)\{\1\{&\s*\}\1\}/g, function (m, mark, if_cond, block) { console.log("GOT", if_cond); for (;;) { assert(mark !== undefined); assert(if_cond !== undefined); assert(block !== undefined); if_cond = if_cond === "" ? true : new Function("def", "return " + if_cond)(def); let p = new RegExp("^([\\s\\S]*?)(?:\\{"+mark+"\\{&&\\s*([\\s\\S]*?)\\s*\\}"+mark+"\\}([\\s\\S]*?))?$"); console.log("PATTERN", p); console.log("BLOCK", block.length); m = p.exec(block); //console.log("m:", m); let if_part = m[1]; if (if_cond) return resolve_static_if(if_part); if_cond = m[2]; if (if_cond === undefined) return ""; block = m[3]; } }); } let dst3 = resolve_static_if(src3); console.log("----\n"+dst3+"\n----");
Features:
I think the core functionality can be used in resolveDefs() of doT, after resolving c.define, before resolving c.use.
Sorry, something went wrong.
No branches or pull requests
{{#?}}
and{{#~}}
The text was updated successfully, but these errors were encountered: