Browse Source

multiple helper params

feature/custom
dslak 3 years ago
parent
commit
2549f0d0e9
  1. 5
      helpers.js
  2. 6
      index.js

5
helpers.js

@ -4,7 +4,6 @@ exports.addHelper = (name, fun) => {
this.helpers[name] = fun
}
this.addHelper('ellipsis', (e) => {
let words = arg1.split(' ').slice(0, 10).join(' ')
return `${words} ...`
this.addHelper('ellipsis', (string, words = 10) => {
return `${string.split(' ').slice(0, words).join(' ')}...`
})

6
index.js

@ -78,8 +78,10 @@ exports.compile = (template, input) => {
template = template.replace(tag.tag, getValue(tag.tag.substring(2, tag.tag.length-2)))
} else {
const funct = split[0].substring(2)
const val = split[1].substring(0,split[1].length-2)
template = template.replace(tag.tag, this.helpers.helpers[funct](getValue(val)))
const val1 = split.length == 2 ? split[1].substring(0,split[1].length-2) : split[1]
const val2 = split.length == 3 ? split[2].substring(0,split[2].length-2) : null
template = val2 ? template.replace(tag.tag, this.helpers.helpers[funct](getValue(val1), val2)) :
template.replace(tag.tag, this.helpers.helpers[funct](getValue(val1)))
}
break
case 'HTML':

Loading…
Cancel
Save