express-ejs-layouts
Advanced tools
Comparing version 1.1.0 to 2.0.0
@@ -28,3 +28,2 @@ /*jslint sloppy:true indent:2 plusplus:true regexp:true*/ | ||
var str = locals.body, regex = /\<script(.|\n)*?\>(.|\n)*?\<\/script\>/g; | ||
locals.script = ''; | ||
@@ -37,2 +36,11 @@ if (regex.test(str)) { | ||
function parseStyles(locals) { | ||
var str = locals.body, regex = /(?:\<style(.|\n)*?\>(.|\n)*?\<\/style\>)|(?:\<link(.|\n)*?\>(?:\<\/link\>)?)/g; | ||
if (regex.test(str)) { | ||
locals.body = str.replace(regex, ''); | ||
locals.style = str.match(regex).join('\n'); | ||
} | ||
} | ||
module.exports = function (req, res, next) { | ||
@@ -77,2 +85,3 @@ var render = res.render; | ||
locals.script = ''; | ||
if (options.extractScripts === true || (options.extractScripts === undefined && app.get('layout extractScripts') === true)) { | ||
@@ -82,2 +91,7 @@ parseScripts(locals); | ||
locals.style = ''; | ||
if (options.extractStyles === true || (options.extractStyles === undefined && app.get('layout extractStyles') === true)) { | ||
parseStyles(locals); | ||
} | ||
parseContents(locals); | ||
@@ -84,0 +98,0 @@ render.call(self, layout, locals, fn); |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"main": "lib/express-layouts.js", | ||
@@ -13,0 +13,0 @@ "dependencies": {}, |
@@ -77,4 +77,12 @@ | ||
req.render('view', { parseScript: true }) | ||
req.render('view', { extractScripts: true }) | ||
### Style blocks extraction | ||
Works exactly like script blocks extraction except: | ||
* Supported tags are ``<link rel="stylesheet" …>`` and ``<style …>`` | ||
* The option is named ``extractStyles`` | ||
* The template variable in layout is ``style`` | ||
## Optional sections | ||
@@ -81,0 +89,0 @@ |
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
6303
78
119