everything you didn't know to ask
slides.forbesl.co.uk
<!DOCTYPE html>
<html lang="en">
<head>
<title>Jade</title>
</head>
<body>
<h1>Jade - node template engine</h1>
<article>
<p>Jade is a terse and simple
templating language with a
strong focus on performance
and powerful features.</p>
</article>
</body>
</html><!DOCTYPE html>
<html lang="en">
<head>
<title>Jade
<body>
<h1>Jade - node template engine
<article>
<p>Jade is a terse and simple
templating language with a
strong focus on performance
and powerful features.doctype html
html(lang="en")
head
title Jade
body
h1 Jade - node template engine
article
p.
Jade is a terse and simple
templating language with a
strong focus on performance
and powerful features.<!--[if IE 8]>
<html lang="en" class="lt-ie9">
<![endif]-->
<!--[if gt IE 8]><!-->
<html lang="en">
<!--<![endif]-->= jsVariable
!= jsVariablevar html = jade.render(template, {jsVariable: '<foo>'});<foo>
<foo>a(href="mailto:" + email)= emailvar html = jade.render(template, {email:'[email protected]'});<a href="mailto:[email protected]">[email protected]</a>p.
We would like to welcome #{name} to this talk
with the following snippet of html: !{html}var html = jade.render(template, {
name: 'Forbes',
html: '<strong>welcome</strong>'
});<p>We would like to welcome Forbes to this talk
with the following snippet of html: <strong>welcome</strong></p>p.
We would like to welcome #[strong= name] to this talk.var html = jade.render(template, { name: 'Forbes' });<p>We would like to welcome <strong>Forbes</strong> to this talk.</p>ul
each value in list
li= value
if awesome
p You are awesome
else
p You could use improvementvar html = jade.render(template, {list: [1, 2], awesome: true});<ul>
<li>1</li>
<li>2</li>
</ul>
<p>You are awesome</p>(a last resort)
ul
- list.forEach(function (value) {
li= value
- });var html = jade.render(template, {list: [1, 2]});<ul>
<li>1</li>
<li>2</li>
</ul>The simplest way to re-use code
//- root.jade
article
include ./child.jade//- child.jade
h2 An Article
p Blah Blah Blahvar html = jade.renderFile('root.jade');<article>
<h2>An Article</h2>
<p>Blah Blah Blah</p>
</article>Re-use blocks with an adjustment
mixin article(name, body)
article
h2= name
p= body
+article('A1', 'The first article')
+article('A2', 'The second article')<article>
<h2>A1</h2>
<p>The first article</p>
</article>
<article>
<h2>A2</h2>
<p>The second article</p>
</article>mixin article(name)
article
h2= name
block
+article('A1')
p The first article
+article('A2')
p The second article<article>
<h2>A1</h2>
<p>The first article</p>
</article>
<article>
<h2>A2</h2>
<p>The second article</p>
</article>//- base.jade
doctype html
html
head
block title
title Default Title
body
block content//- article.jade
extends ./base.jade
block title
title My Article Title
block content
p An epic article<!DOCTYPE html>
<html>
<head>
<title>My Article Title</title>
</head>
<body>
<p>An epic article</p>
</body>
</html>//- authenticated.jade
extends ./base.jade
block title
title Authenticated
//- anonymous.jade
extends ./base.jade
block title
title Anonymousgithub.com/ForbesLindesay/character-parser
var parseMax = require('character-parser').parseMax;
var expression = parseMax('foo="(", bar="}") bing bong').src;
assert(expression = 'foo="(", bar="}"');fs.readFileSyncblocks propertyfs.readFileSynclexerparsergithub.com/jadejs/jade-code-gen
buffer array.github.com/jadejs/jade-runtime
< with < etc.){color: 'red'} into "color: red"In jade@1 this must be loaded as a script tag on any page that uses Jade templates.
In jade@2, the required methods can just be inlined to simplify the build process.
github.com/ForbesLindesay/constantinople
github.com/ForbesLindesay/with
i.e.
with(obj) {
buf.push(foo + bar);
}becomes
var foo = obj.foo,
bar = obj.bar;
buf.push(foo + bar);:markdown
# Heading 1
Paragraph of text<h1>Heading 1</h1>
<p>Paragraph of text</p>github.com/ForbesLindesay/transformers
string + data -> string transformationsvar transformer = require('transformers')['transformer-name'];
var ouptut = transformer.render(input, options)string + data -> string transformationsvar transformer = require('jstransformer-transformer-name');
var ouptut = transformer.render(input, options)Get involved!!!
Custom implementation of jade-code-gen
a(href="http://example.com") exampleReact.createElement('a', {href: 'http://example.com'}, 'example')var jade = require('react-jade');
module.exports = jade.compileFile(__dirname + 'input.jade');becomes
module.exports = function (locals) {
return React.createElement('a', {
href: 'http://example.com'
}, 'example');
}var React = require('react');
var jade = require('react-jade');
module.exports = React.createClass({
onClick: function () { this.setState({clicked: true}) },
render: jade`
if !this.state.clicked
button(onClick=this.onClick) Click Me!
else
p You clicked me!
`
});var React = require('react');
module.exports = React.createClass({
onClick: function () { this.setState({clicked: true}) },
render: function () {
if (!this.state.clicked) {
return React.createElement('button', {
onClick: this.onClick
}, 'Click me!');
} else {
return React.createElement('p', {}, 'You clicked me!');
}
}
});Function constructorFunction in lexer/parser to check code is a valid expressionslides.forbesl.co.uk
Twitter: @ForbesLindesay
GitHub: @ForbesLindesay
Blog: www.forbeslindesay.co.uk
Jade
Browserify Middleware
readable-email.org
brcdn.org
tempjs.org