2 changed files with 53 additions and 0 deletions
@ -0,0 +1,31 @@ |
|||
exports.printVersion = () => { |
|||
console.log('Staples v0.0.1') |
|||
} |
|||
|
|||
exports.compile = (template, input) => { |
|||
let index = 0 |
|||
|
|||
while(index < template.length) { |
|||
const nextOpen = template.indexOf('{{', index + 1) |
|||
if(nextOpen == index || nextOpen == -1) { |
|||
index = template.length |
|||
} else { |
|||
index = nextOpen |
|||
const nextClose = template.indexOf('}}', index + 1) |
|||
if(nextClose == index || nextClose == -1) { |
|||
index = template.length |
|||
} else { |
|||
index = nextOpen+2 |
|||
const tagContent = template.substring(nextOpen+2, nextClose) |
|||
const tagContentSplit = tagContent.split('.') |
|||
let varLevel = input |
|||
tagContentSplit.forEach( (level) => { |
|||
const isIndex = Number.isInteger(parseInt(level)) |
|||
varLevel = isIndex ? varLevel[parseInt(level)] : varLevel[level] |
|||
}) |
|||
template = template.replace(tagContent, varLevel) |
|||
} |
|||
} |
|||
} |
|||
console.log(template) |
|||
} |
@ -0,0 +1,22 @@ |
|||
{ |
|||
"name": "@dslak/staples", |
|||
"version": "0.0.35", |
|||
"description": "Lightweight handlebars replacement for Angular", |
|||
"main": "index.js", |
|||
"scripts": { |
|||
"login": "npm login", |
|||
"publish": "npm publish --access public", |
|||
"test": "echo \"Error: no test specified\" && exit 1" |
|||
}, |
|||
"repository": { |
|||
"type": "git", |
|||
"url": "https://git.dslak.it/dslak/staples.git" |
|||
}, |
|||
"keywords": [ |
|||
"brackets", |
|||
"handlebars", |
|||
"mustaches" |
|||
], |
|||
"author": "Dslak", |
|||
"license": "ISC" |
|||
} |
Loading…
Reference in new issue