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

underscore-template-loader

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

underscore-template-loader - npm Package Compare versions

Comparing version 0.7.1 to 0.7.2

test/templates/dynamic-attribute-with-parseDynamicRoutes.html

10

index.js

@@ -24,3 +24,4 @@ var path = require('path');

withImports = false,
attributes = ['img:src'];
attributes = ['img:src'],
parseDynamicRoutes = false;

@@ -70,2 +71,7 @@ // Parse arguments

}
// Check if dynamic routes must be parsed
if (query.parseDynamicRoutes !== undefined) {
parseDynamicRoutes = !!query.parseDynamicRoutes;
}
}

@@ -89,3 +95,3 @@

return attributes.indexOf(tag + ':' + attr) != -1;
}, 'ATTRIBUTE', root);
}, 'ATTRIBUTE', root, parseDynamicRoutes);
content = attributesContext.replaceMatches(content);

@@ -92,0 +98,0 @@

@@ -40,3 +40,3 @@ var path = require('path');

// AttributeContext class
var AttributeContext = function (isRelevantTagAttr, usid, root) {
var AttributeContext = function (isRelevantTagAttr, usid, root, parseDynamicRoutes) {
this.currentDirective = null;

@@ -51,2 +51,3 @@ this.matches = [];

this.root = root;
this.parseDynamicRoutes = parseDynamicRoutes;
};

@@ -61,4 +62,6 @@

if (isTemplate(match.value)) {
// Replate template if a "root" option has been defined
if (pathIsAbsolute(match.value) && self.root != undefined) {
// Replace attribute value
// This is used if it contains a template expression and both the "root" and "parseDynamicRoutes"
// were defined
if (pathIsAbsolute(match.value) && self.root !== undefined) {
var x = content.pop();

@@ -132,3 +135,3 @@ content.push(x.substr(match.start + match.length));

if (isTemplate(value)) {
if (pathIsAbsolute(value) && self.root != undefined) {
if (pathIsAbsolute(value) && self.root !== undefined && self.parseDynamicRoutes) {
// Generate new value for replacement

@@ -171,5 +174,5 @@ expression = loaderUtils.urlToRequest(value, self.root);

module.exports = function parse(html, isRelevantTagAttr, usid, root) {
var context = new AttributeContext(isRelevantTagAttr, usid, root);
module.exports = function parse(html, isRelevantTagAttr, usid, root, parseDynamicRoutes) {
var context = new AttributeContext(isRelevantTagAttr, usid, root, parseDynamicRoutes);
return parser.parse('outside', html, context);
};

2

package.json
{
"name": "underscore-template-loader",
"version": "0.7.1",
"version": "0.7.2",
"description": "An Underscore and Lodash template loader for Webpack",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -9,3 +9,3 @@ underscore-template-loader

<br>
* 0.7.1: FIX: Check if attribute contains a template expression before replacing it.
* 0.7.2: Support for the `parseDynamicRoutes` argument (deactivated by default).

@@ -233,2 +233,35 @@ ### Installation

Dynamic attributes won't be afected by this behaviour by default.
```html
<!-- Ignore "root" argument if attribute contains a template expression -->
<img src="/img/cat-<%- currentCat.url %>.png" class="cat-img">
```
In order to append the root directory you'll need to specify the `parseDynamicRoutes` argument.
```javascript
module.exports = {
//...
module: {
loaders: [
{
test: /\.html$/,
loader: "underscore-template-loader",
query: {
root: "myapp",
parseDynamicRoutes: true
}
}
]
}
};
```
```html
<!-- Attribute now translates to "myapp/img/cat-<%- currentCat.url %>.png" -->
<img src="/img/cat-<%- currentCat.url %>.png" class="cat-img">
```
### Macros

@@ -235,0 +268,0 @@

@@ -158,2 +158,14 @@ var fs = require('fs');

});
it('should parse dynamic attributes with parseDynamicRoutes', function (done) {
testTemplate(loader, 'dynamic-attribute-with-parseDynamicRoutes.html', {
query: {
root: 'myapp',
parseDynamicRoutes: true
}
}, function (output) {
assert.equal(output, loadOutput('dynamic-attribute-with-parseDynamicRoutes.txt'));
done();
});
});

@@ -160,0 +172,0 @@ // FIXME: Changing the underscore tags changes it globally

@@ -6,3 +6,3 @@ module.exports = function(obj){

((__t=( currentCat.url ))==null?'':_.escape(__t))+
'.png" class="cat-img">\n<img src="/bar/img/dog-'+
'.png" class="cat-img">\n<img src="/img/dog-'+
((__t=( currentDog.url ))==null?'':_.escape(__t))+

@@ -9,0 +9,0 @@ '.png" class="dog-img">\n';

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