Exemplo n.º 1
0
 renderInlineHelper(token, context) {
     const helper = this.helpers[token.value]
     if (!helper) {
         throw new Error(`Miss helper#${token.value}, at ${token.loc.start}`)
     }
     let data = token.params.context
     if (data != null) {
         const isRaw = token.params.contextIsString || isRawValue(data)
         data = isRaw ? getValueFromString(data, isRaw.preferNumber) : context.lookup(data)
     }
     const value = helper.call(
         context,
         data,
         {
             fn() { return '' },
             inverse() { return '' },
             hash: token.params.hash,
             $$base: checkUrl(token),
             $$root: getRootToken(token).url,
             // page url
             $$page: token.addtionalInfo && token.addtionalInfo.page,
             // config.root
             $$configRoot: token.addtionalInfo && token.addtionalInfo.configRoot
         }
     )
     if (value != null) return escapeHtml(value)
 }
Exemplo n.º 2
0
 renderFilter(token, context) {
     const data = token.context && context.lookup(token.context)
     let value = data
     let filter
     token.filters.forEach((v) => {
         filter = this.filters[v.name]
         if (!filter) {
             throw new Error(`Miss filter#${v.name}, at ${token.loc.start}`)
         }
         value = filter(value, v.hash)
     })
     if (value != null) return escapeHtml(value)
 }
Exemplo n.º 3
0
        }
    }
    return res
}

const renderer = {
    Text (options, token) {
        return token.value
    },
    RawValue (options, token, context) {
        const value = context.lookup(token.value)
        return value == null ? '' : value
    },
    Value (options, token, context) {
        const value = context.lookup(token.value)
        return value == null ? '' : escapeHtml(value)
    },
    Comment () {
        return ''
    },
    IgnoreCompile (options, token) {
        return token.value
    },
    Filter (options, token, context, template) {
        const data = token.name && context.lookup(token.name)
        let value = data
        let filter
        token.filters.forEach(v => {
            filter = options.filters[v.name]
            if (!filter) {
                throw new Exception(`Miss filter#${v.name}`, token.loc.start, template || '')
Exemplo n.º 4
0
 escapedValue(token, context) {
     const value = context.lookup(token.value)
     if (value != null) return escapeHtml(value)
 }