Browse Source

init project

master
dslak 3 years ago
parent
commit
6956ad1aa1
  1. 31
      index.js
  2. 22
      package.json

31
index.js

@ -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)
}

22
package.json

@ -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…
Cancel
Save