Skip to content

Commit

Permalink
Add examples for the Pug snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
alexyoung committed Dec 7, 2016
1 parent 9784e99 commit 38dc3a2
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions ch08-templates/pug-snippets/data-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const pug = require('pug');
const template = 'strong #{message}';
const context = { message: 'Hello template!' };
const fn = pug.compile(template);
console.log(fn(context));
11 changes: 11 additions & 0 deletions ch08-templates/pug-snippets/iteration-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const pug = require('pug');
const fs = require('fs');
const template = fs.readFileSync('./template.pug');
const context = {
messages: [
'You have logged in successfully.',
'Welcome back!'
]
};
const fn = pug.compile(template);
console.log(fn(context));
5 changes: 5 additions & 0 deletions ch08-templates/pug-snippets/link-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const pug = require('pug');
const template = 'a(href = url)';
const context = { url: 'http://google.com' };
const fn = pug.compile(template);
console.log(fn(context));
14 changes: 14 additions & 0 deletions ch08-templates/pug-snippets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "pug-snippets",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"pug": "^2.0.0-beta6"
}
}
3 changes: 3 additions & 0 deletions ch08-templates/pug-snippets/template.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- messages.forEach(message => {
p= message
- })

0 comments on commit 38dc3a2

Please sign in to comment.