Socket
Socket
Sign inDemoInstall

derby-jade

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

derby-jade - npm Package Compare versions

Comparing version 0.6.17 to 0.6.18

test/extra/module/index.jade

79

index.js

@@ -19,3 +19,3 @@ var jade = require('jade');

module.exports = function (app, opts) {
module.exports = exports = function (app, opts) {
options = opts || {};

@@ -26,2 +26,4 @@ app.viewExtensions.push('.jade');

exports.compiler = compiler;
function addindent(source, count) {

@@ -69,4 +71,17 @@ if (count === undefined) count = defaultIndent;

function postprocess(html) {
function postprocess(html, scripts) {
return html
.replace(/\n/g, newLine)
.replace(r('\\s*(<([\\w-:]+))((?:\\b[^>]+)?>)(?:' + regNewLine + ')?([\\s\\S]*?)(?:' + regNewLine + ')?<\\/\\2>', 'g'), function (template, left, name, right, content, offset, string) {
return left + ':' + right + (content ? newLine + content : '')
+ ((offset + template.length === string.length) ? '' : newLine);
})
// Remove underscores
.replace(/<_derby_/g, '<')
.replace(/<\/_derby_/g, '<\/')
// Add scripts
.replace(/<script(\d*)><\/script\1>/g, function(statement, index) {
return scripts[index];
})
.replace(/\r$/g, '')
// Clean redundant Derby statements

@@ -84,3 +99,3 @@ //.replace(/[ \t]*<\/__derby-statement>\n?(?=\s+<__derby-statement type="else([ \t]+if)?")/g, '')

function compiler(file, fileName, preprocessOnly) {
function compiler(file, fileName, preprocessOnly, jadeOptions) {
var out = [];

@@ -95,2 +110,3 @@ var lines = file.replace(/\r\n/g, newLine).split(newLine);

var debugString;
jadeOptions = jadeOptions || options.globals || {};

@@ -102,35 +118,7 @@ function renderBlock() {

block = [];
var jadeOptions = {
filename: fileName,
pretty: true
}
jadeOptions.filename = fileName;
jadeOptions.pretty = true;
jade.render(source, jadeOptions, function (error, html) {
if (error) throw error;
html = html
.replace(/\n/g, newLine)
// Add colons
//.replace(/^\s*(<([\w-:]+))((?:\b[^>]+)?>)\n?([\s\S]*?)\n?<\/\2>$/, function (template, left, name, right, content) {
// return left + ':' + right + (content ? newLine + content : '');
//})
.replace(r('\\s*(<([\\w-:]+))((?:\\b[^>]+)?>)(?:' + regNewLine + ')?([\\s\\S]*?)(?:' + regNewLine + ')?<\\/\\2>', 'g'), function (template, left, name, right, content, offset, string) {
// console.log('-----------> HAS');
// console.log(template);
// console.log('-------> LEFT');
// console.log(left);
// console.log('-------> RIGHT');
// console.log(right);
// console.log('-------> CONTENT');
// console.log(content);
return left + ':' + right + (content ? newLine + content : '')
+ ((offset + template.length === string.length) ? '' : newLine);
})
// Remove underscores
.replace(/<_derby_/g, '<')
.replace(/<\/_derby_/g, '<\/')
// Add scripts
.replace(/<script(\d*)><\/script\1>/g, function(statement, index) {
return scripts[index];
})
.replace(/\r$/g, '');
out.push(postprocess(html));
out.push(postprocess(html, scripts));
});

@@ -282,7 +270,28 @@ }

do {
oldLine = line;
line = line.replace(/(^\s*[\w\.#-]*\.)(&)/, '$1' + lastElement);
oldLine = line
} while (line !== oldLine);
}
// Module mode for Jade (for usage with Webpack and custom css-loader)
// Ref: https://github.com/dmapper/style-guide/blob/master/stylus.md
if (( jadeOptions.moduleMode || options.moduleMode) && fileName) {
var _componentName = path.basename(fileName, path.extname(fileName));
if (_componentName === 'index') {
_componentName = path.basename( path.dirname(fileName) );
}
line = line.replace(/(\.)([a-z][\w_-]+)/g, function(match, dot, localName, offset, string){
// Check that it's a class (the dot is before any parenthesis)
if (/^\s*[^\s\(]+[\s\(]/.test( string.substr(0, offset) )) {
return match;
} else {
if (localName === 'root') {
return dot + _componentName;
} else {
return dot + _componentName + '-' + localName;
}
}
});
}
block.push(line);

@@ -289,0 +298,0 @@ }

{
"name": "derby-jade",
"description": "Jade for Derby.js",
"version": "0.6.17",
"version": "0.6.18",
"author": {

@@ -6,0 +6,0 @@ "name": "Vladimir Makhaev",

@@ -78,2 +78,11 @@ var assert = require("assert");

it("should support module mode", function() {
dJade(app, {globals: {moduleMode: true}});
var compiler = app.compilers[".jade"];
var jade = fs.readFileSync(__dirname + "/extra/module/index.jade", "utf8");
var html = fs.readFileSync(__dirname + "/extra/module/result.html", "utf8");
assert.equal(compiler(jade, __dirname + "/extra/module/index.jade"), html);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc