Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

templatizer

Package Overview
Dependencies
Maintainers
3
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

templatizer - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

5

output_template.js

@@ -6,5 +6,4 @@ (function (root, factory) {

module.exports = factory();
} else if (typeof root{{namespace}} === 'undefined' || root{{namespace}} !== Object(root{{namespace}})) {
throw new Error('{{internalNamespace}}: window{{namespace}} does not exist or is not an object');
} else {
{{checkParent}}
root{{namespace}}.{{internalNamespace}} = factory();

@@ -18,2 +17,2 @@ }

return {{internalNamespace}};
}));
}));

2

package.json
{
"name": "templatizer",
"description": "Simple solution for compiling jade templates into vanilla JS functions for blazin' fast client-side use.",
"version": "1.4.0",
"version": "1.5.0",
"author": "Henrik Joreteg <henrik@andyet.net>",

@@ -6,0 +6,0 @@ "bin": "./bin/cli",

@@ -77,6 +77,23 @@ # templatizer.js

#### `namespace` (string, default `window`)
#### `namespace` (object, optional)
If you are using templatizer as a global in the browser (without node, requirejs, browserify, or something similar) by default it will attach itself to `window`. Using `namespace` you can attach it to a different global object. For example:
If you are using templatizer as a global in the browser (without requirejs, browserify, or something similar) by default your templates will be available at `window.templatizer`. Using `namespace` you can attach it to a different global object or rename the property it attaches to.
#### `namespace.parent` (string, default `window`)
This is the name of the object where you want to attach your templates.
#### `namespace.defineParent` (boolean, default `false`)
If this option is `true` and `namespace.parent` does not exist, it will be created. By default if `namespace.parent` does not exist, templatizer will throw an error like this: `templatizer: window.app does not exist or is not an object`.
#### `namespace.name` (string, default `templatizer`)
This is the name of the property on `namespace.parent` where your templates will be attached.
#### Shorthand
If all you want is to attach the `templatizer` object to an already created global variable, then you can just make `namespace` the name of the object where it will attach:
```js

@@ -83,0 +100,0 @@ templatizer(templatesDir, 'templates.js', {

@@ -12,6 +12,9 @@ var jade = require('jade');

var uglifyjs = require('uglify-js');
var glob = require('glob');
var minimatch = require('minimatch');
var namedTemplateFn = require('./lib/namedTemplateFn');
var bracketedName = require('./lib/bracketedName');
var glob = require('glob');
var minimatch = require("minimatch");
var indent = function (output, space) {
return output.split('\n').map(function (l) { return l ? new Array((space || 4) + 1).join(' ') + l : l; }).join('\n');
};

@@ -28,13 +31,26 @@ // Setting dynamicMixins to true will result in

options || (options = {});
options.namespace || (options.namespace = {});
var internalNamespace = 'templatizer';
var namespaceOptions = {
parent: '', // defaults to window
name: 'templatizer',
defineParent: false
};
// If namespace is a string then just apply it to namespace.parent
// for backwards compat
if (typeof options.namespace === 'string') {
namespaceOptions.parent = options.namespace;
options.namespace = namespaceOptions;
} else {
_.defaults(options.namespace, namespaceOptions);
}
_.defaults(options, {
dontTransformMixins: false,
dontRemoveMixins: false,
jade: {},
amdDependencies: [],
inlineJadeRuntime: true,
globOptions: {},
jade: {},
namespace: '' // No namespace means 'window'
globOptions: {}
});

@@ -51,7 +67,7 @@

if(_.isArray(options.amdDependencies) && !_.isEmpty(options.amdDependencies)) {
amdModuleDependencies = "'" + options.amdDependencies.join("','") + "'";
amdDependencies = options.amdDependencies.toString();
amdModuleDependencies = "'" + options.amdDependencies.join("','") + "'";
amdDependencies = options.amdDependencies.toString();
}
var namespace = _.isString(options.namespace) ? options.namespace : '';
var namespace = _.isString(options.namespace.parent) ? options.namespace.parent : '';
var folders = [];

@@ -139,3 +155,3 @@ var templates = [];

output += folders.map(function (folder) {
return internalNamespace + bracketedName(folder.split(pathSep)) + ' = {};';
return options.namespace.name + bracketedName(folder.split(pathSep)) + ' = {};';
}).join('\n') + '\n';

@@ -171,3 +187,3 @@

dir: dirString,
rootName: internalNamespace
rootName: options.namespace.name
});

@@ -180,3 +196,3 @@ mixins = astResult.mixins;

dir: dirString,
rootName: internalNamespace,
rootName: options.namespace.name,
fn: template

@@ -188,9 +204,19 @@ });

if(!options.inlineJadeRuntime)
wrappedJade = '';
var indentOutput = indent(output);
var checkParent = [
"if (typeof root{{namespace}} === 'undefined' || root{{namespace}} !== Object(root{{namespace}})) {",
options.namespace.defineParent ?
" root{{namespace}} = {};" :
" throw new Error('templatizer: window{{namespace}} does not exist or is not an object');",
"}"
].join('\n');
var indentOutput = output.split('\n').map(function (l) { return l ? ' ' + l : l; }).join('\n');
if(!options.inlineJadeRuntime) {
wrappedJade = '';
}
var finalOutput = outputTemplate
.replace('{{checkParent}}', indent(checkParent, 8))
.replace(/\{\{namespace\}\}/g, namespace)
.replace(/\{\{internalNamespace\}\}/g, internalNamespace)
.replace(/\{\{internalNamespace\}\}/g, options.namespace.name)
.replace('{{jade}}', wrappedJade)

@@ -197,0 +223,0 @@ .replace('{{code}}', indentOutput)

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