https://github.com/davidkk/killt
Template engine for Javascript.
https://github.com/davidkk/killt
Last synced: 3 months ago
JSON representation
Template engine for Javascript.
- Host: GitHub
- URL: https://github.com/davidkk/killt
- Owner: DavidKk
- Created: 2015-09-01T13:57:14.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-04-04T02:57:40.000Z (about 6 years ago)
- Last Synced: 2025-02-08T07:45:34.284Z (3 months ago)
- Language: JavaScript
- Homepage: https://github.com/DavidKk/killt
- Size: 2.19 MB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOGS.md
Awesome Lists containing this project
README
# killt
[](https://travis-ci.org/DavidKk/killt)
[](https://ci.appveyor.com/project/DavidKk/killt/branch/master)
[](https://david-dm.org/DavidKk/killt)
[](https://david-dm.org/DavidKk/killt#info=devDependencies)
[](https://coveralls.io/github/DavidKk/killt?branch=master)
[](http://inch-ci.org/github/DavidKk/killt)[](https://nodei.co/npm/killt/)
[](https://github.com/DavidKk/killt/blob/master/LICENSE)
[](https://github.com/996icu/996.ICU/blob/master/LICENSE)killt is a light template engine for Javascript.
### Examples & Docs
[http://davidkk.github.io/killt](http://davidkk.github.io/killt)
### Install
```
npm install killt
```### Features
- Support request template by ajax.
- Support comstom block helper.
- Support comstom syntax.
- Support compiled caches.
- Support UMD.### How can i use?
#### Lit Version
```
<h1><%= title %></h1>
<ul>
<%each(list, function(value, index) {%>
<li><%= index %>: <%= value %></li>
<%})%>
</ul>```
#### Default Syntax Version
```
# Template In HTML<h1>{{= title}}</h1>
<ul>
{{each list as value index}}
<li>{{= index}}: {{= value}}</li>
{{\/each}}
</ul>```
### Compile and Render
```
// Source
killt.compile([String source], [Object options])
killt.render([String source], [Object Data], [Object options])// Nested
script(id="/template/inline.html", type="template/text")
killt.compileSync([String TemplateId], [Object options])
killt.renderSync([String TemplateId], [Object data], [Object options])// Ajax
killt.compileAsync([String url], [Function callback], [Object options])
killt.renderAsync([String url], [Object data], [Function callback], [Object options])
```#### Compiled by template
```
var killt = window.killt
var killt = require('killt')killt.renderSync('templates/list/default.html', {
title: 'Customer Title',
list: {
Author: 'David Jones',
Gender: 'Male'
}
})
```##### Compiled by Ajax
```
killt.renderAsync('templates/list/default.html', function(html) {
// do something...
})
```#### Customize Helpers
```
killt.helper('hate', function(who) {
return 'Hate ' + who + '!!!'
})// HTML
{{"U" | hate}}// Output
'Hate U !!!'
```#### Customize Block (full version, not in lite version)
```
killt.block('like', function(who, blockShell) {
return who ? 'Like ' + who + '!!!' : blockShell()
})// HTML
{{like 'U'}}Me?{{/like}}// Output
'Like U!!!'
```#### Customize Syntax (full version, not in lite version)
```
killt.$registerSyntax('fuck', 'fuck\\s*([\\w\\W]+?)\\s*', 'fuck($1)')// HTML
{{fuck 'Q'}}// Be comipled to native template is
<% fuck('Q'); %>
```Note: `fuck` is a helper, so u must use `killt.helper('fuck', function() {})` to add a helper.
### Details
[See the code and the detailed annotate...](https://github.com/DavidKk/killt/blob/master/dist/es6/client/killt.js)
### Updates