express-ejs-layouts
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -9,2 +9,4 @@ var path = require('path'); | ||
app.set('view engine', 'ejs'); | ||
app.set('layout extractScripts', true) | ||
app.set('layout extractStyles', true) | ||
@@ -15,9 +17,8 @@ app.use(expressLayouts); | ||
res.locals = { | ||
meta: { | ||
title: 'Page Title', | ||
description: 'Page Description' | ||
}, | ||
header: 'Page Header' | ||
title: 'Example', | ||
message: 'This is a message' | ||
}; | ||
res.render('the-view', {}); | ||
res.render('view', { | ||
// additional locals, a custom layout, or other options can be defined here | ||
}); | ||
}); | ||
@@ -24,0 +25,0 @@ |
@@ -27,3 +27,3 @@ /*jslint sloppy:true indent:2 plusplus:true regexp:true*/ | ||
function parseScripts(locals) { | ||
var str = locals.body, regex = /\<script(.|\n)*?\>(.|\n)*?\<\/script\>/g; | ||
var str = locals.body, regex = /\<script[\s\S]*?\>[\s\S]*?\<\/script\>/g; | ||
@@ -37,3 +37,3 @@ if (regex.test(str)) { | ||
function parseStyles(locals) { | ||
var str = locals.body, regex = /(?:\<style(.|\n)*?\>(.|\n)*?\<\/style\>)|(?:\<link(.|\n)*?\>(?:\<\/link\>)?)/g; | ||
var str = locals.body, regex = /(?:\<style[\s\S]*?\>[\s\S]*?\<\/style\>)|(?:\<link[\s\S]*?\>(?:\<\/link\>)?)/g; | ||
@@ -47,3 +47,3 @@ if (regex.test(str)) { | ||
function parseMetas(locals) { | ||
var str = locals.body, regex = /\<meta(.|\n)*?\>/g; | ||
var str = locals.body, regex = /\<meta[\s\S]*?\>/g; | ||
@@ -50,0 +50,0 @@ if (regex.test(str)) { |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"main": "lib/express-layouts.js", | ||
@@ -13,0 +13,0 @@ "dependencies": {}, |
@@ -13,5 +13,15 @@ # express-ejs-layouts | ||
## Example | ||
Check the example folder. | ||
1. `git clone git@github.com:Soarez/express-ejs-layouts.git` | ||
2. `cd express-ejs-layouts` | ||
3. `npm install` | ||
4. `node example` | ||
5. Open http://localhost:3000/ | ||
## Usage | ||
```js | ||
```javascript | ||
var express = require('express'); | ||
@@ -44,3 +54,3 @@ var expressLayouts = require('express-ejs-layouts'); | ||
```ejs | ||
somebody | ||
tyler | ||
<%- contentFor('foo') %> | ||
@@ -63,3 +73,3 @@ club | ||
fight club | ||
somebody | ||
tyler | ||
``` | ||
@@ -101,3 +111,3 @@ | ||
```js | ||
```javascript | ||
app.set("layout extractScripts", true) | ||
@@ -123,3 +133,3 @@ ``` | ||
```ejs | ||
```html | ||
<body> | ||
@@ -133,3 +143,3 @@ somethingsomething | ||
```js | ||
```javascript | ||
req.render('view', { extractScripts: true }) | ||
@@ -192,2 +202,22 @@ ``` | ||
### Set custom default layout | ||
By default 'layout.ejs' is used. If you want to specify your custom | ||
layout (e.g. 'layouts/layout.ejs'), just set `layout` property in | ||
express app settings. | ||
``` | ||
app.set('layout', 'layouts/layout'); | ||
``` | ||
### Set custom layout for single render | ||
Just pass `layout` as render locals object. | ||
``` | ||
app.get('/', function(req, res) { | ||
res.render('the-view', { layout: 'specific-layout' }); | ||
); | ||
``` | ||
## Optional sections | ||
@@ -225,6 +255,6 @@ | ||
Clone the rep and run: | ||
Clone the repo and run: | ||
```sh | ||
$ make test | ||
$ npm test | ||
``` | ||
@@ -231,0 +261,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11195
111
257