Giter Club home page Giter Club logo

killt's Introduction

killt

Build Status Build status Dependency Status devDependency Status Coverage Status Inline docs

NPM

GitHub LICENSE

killt is a light template engine for Javascript.

Examples & Docs

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

<script id="templates/list/default.html" type="template/text">
  <h1><%= title %></h1>
  <ul>
    <%each(list, function(value, index) {%>
      <li><%= index %>: <%= value %></li>
    <%})%>
  </ul>
</script>

Default Syntax Version

# Template In HTML
<script id="templates/list/default.html" type="template/text">
  <h1>{{= title}}</h1>
  <ul>
      {{each list as value index}}
          <li>{{= index}}: {{= value}}</li>
      {{\/each}}
  </ul>
</script>

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...

Updates

killt's People

Contributors

davidkk avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

killt's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.