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

razorleaf

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

razorleaf - npm Package Compare versions

Comparing version 1.5.4 to 1.6.0

2

package.json
{
"name": "razorleaf",
"version": "1.5.4",
"version": "1.6.0",
"main": "razorleaf.js",

@@ -5,0 +5,0 @@ "files": [

@@ -8,2 +8,10 @@ "use strict";

function addBlockAction(tree, blockName, action) {
if(tree.blockActions.hasOwnProperty(blockName)) {
tree.blockActions[blockName].push(action);
} else {
tree.blockActions[blockName] = [action];
}
}
var specialBlocks = {};

@@ -242,2 +250,3 @@

blocks: {},
blockActions: {},
indent: -1

@@ -497,2 +506,35 @@ };

if(c !== " ") {
var duplicatesExistingNameError = this.prepareError();
this.context.duplicatesExistingName = function() {
return duplicatesExistingNameError("A block named “" + this.name + "” already exists in this context");
};
return this.pass(specialBlocks.block.name);
}
return whitespace;
},
name: function name(c) {
if(c === "\n") {
if(this.root.blocks.hasOwnProperty(this.context.name)) {
throw this.context.duplicatesExistingName();
}
this.root.blocks[this.context.name] = this.context;
return this.pass(states.content);
}
this.context.name += c;
return name;
}
};
specialBlocks.replace = {
begin: function() {
this.context.parent.children.pop();
this.context.type = "replace-block";
this.context.name = "";
},
initialState: function whitespace(c) {
if(c !== " ") {
var replacesNonExistentError = this.prepareError();

@@ -503,3 +545,3 @@ this.context.replacesNonExistentBlock = function() {

return this.pass(specialBlocks.block.name);
return this.pass(specialBlocks.replace.name);
}

@@ -510,5 +552,9 @@

name: function name(c) {
var replaceBlock = this.context;
if(c === "\n") {
// TODO: Warn that duplicating block names within the same template serves no purpose.
this.root.blocks[this.context.name] = this.context;
addBlockAction(this.root, replaceBlock.name, function(block) {
block.children = replaceBlock.children;
});
return this.pass(states.content);

@@ -515,0 +561,0 @@ }

@@ -27,3 +27,3 @@ "use strict";

if(child.type !== "extends" && child.type !== "block") {
if(child.type !== "extends" && child.type !== "replace-block") {
throw child.unexpected;

@@ -42,8 +42,4 @@ }

if(tree.blocks.hasOwnProperty(name)) {
var parentBlock = newTree.blocks[name];
if(parentBlock) {
parentBlock.children = [tree.blocks[name]];
} else if(!isContained(tree.blocks[name])) {
throw tree.blocks[name].replacesNonExistentBlock();
if(newTree.blocks.hasOwnProperty(name)) {
throw tree.blocks[name].duplicatesExistingName();
}

@@ -55,2 +51,12 @@

for(var name in newTree.blocks) {
if(tree.blockActions.hasOwnProperty(name)) {
var block = newTree.blocks[name];
tree.blockActions[name].forEach(function(action) {
action(block);
});
}
}
return newTree;

@@ -85,2 +91,12 @@ }

for(var name in tree.blocks) {
if(tree.blockActions.hasOwnProperty(name)) {
var block = tree.blocks[name];
tree.blockActions[name].forEach(function(action) {
action(block);
});
}
}
return compiler.compile(tree);

@@ -87,0 +103,0 @@ }

@@ -1,2 +0,2 @@

[![Build Status](https://travis-ci.org/campersander/razorleaf.png)](https://travis-ci.org/campersander/razorleaf)
[![Build Status](https://travis-ci.org/charmander/razorleaf.png)](https://travis-ci.org/charmander/razorleaf)

@@ -155,7 +155,7 @@ Razor Leaf is a template engine for JavaScript with a convenient

- **`include (name)`**: Loads and includes another template.
- **`extends (name)`**: Loads another template and replaces any blocks
with names matching blocks in the current template with those blocks.
`extends` must appear at the beginning of the template. A template that
extends another template cannot have any content outside of blocks.
- **`block (name)`**: Defines a replaceable block, to be used with `extend`.
- **`extends (name)`**: Loads another template and replaces its blocks.
A template that extends another template cannot have any content
outside of block actions.
- **`block (name)`**: Defines a replaceable block.
- **`replace (name)`**: Replaces a block.

@@ -162,0 +162,0 @@ ## API

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