Jquery.jade.js
Jade for jQuery is a lightweight jQuery plugin providing a friendly API for using the jade template engine.
Install / Use
/learn @jmar777/Jquery.jade.jsREADME
Jade for jQuery
Jade for jQuery is a lightweight jQuery plugin providing a friendly API for using the jade template engine.
Features
- Simple API
- Adheres to jQuery plugin conventions
- Caches compiled templates for more better performance
Dependencies
Getting Started
Some simple examples of using Jade for jQuery are provided below. Please note that some example pages are
also provided in /examples.
Basic Usage
Templates can be defined inline using script tags. Because of the non-standard type value, this code
will not be executed as javascript, and is instead available to use as template markup:
<script id='my-template' type='text/x-jade'>
h1 Hello #{name}!
</script>
Rendering a template is as simple as $('#my-template').jade({ /* data */ });. This will return a jQuery
collection representing the rendered template, which can then be chained in regular jQuery fashion. In this
example, we simply append the result to the body element:
$('#my-template').jade({ name: 'World' }).appendTo('body');
Using the API Directly
Jade for jQuery exposes the $.jade() method for times when inline template tags aren't desired. As shown below, this
method will compile the provided template and render it using the provided data.
var template = 'h1 Hello #{name}!',
data = { name: 'World' },
html = $.jade(template, data);
console.log(html); // '<h1>Hello World!</h1>'
Please note that the code above will not actually cache the compiled template, though. If it is known ahead of time that a given template will be used repeatedly, a template name can be provided as well, which will be used as a cache key for the compiled template:
var template = 'h1 Hello #{name}!',
templateName = 'header-template',
data = { name: 'World' },
html = $.jade(templateName, template, data);
console.log(html); // '<h1>Hello World!</h1>'
Todo
- A test suite
Licensing
Copyright 2013, Jeremy Martin (http://github.com/jmar777)
Dual licensed under the MIT or GPL Version 2 licenses.
Related Skills
node-connect
349.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
