Comparing version 0.7.0 to 0.7.1
@@ -63,2 +63,5 @@ "use strict"; | ||
registerIfLeHelper(); | ||
registerIfAndHelper(); | ||
registerIfOrHelper(); | ||
registerIfXorHelper(); | ||
injectGlobalsToHelpers(globals); | ||
@@ -274,3 +277,3 @@ clearDistributionDirectoryIfNeeded(); | ||
} | ||
/** If equals Block helper | ||
/** IF EQUALS block helper | ||
* @example | ||
@@ -293,3 +296,3 @@ * {{#if_eq var 'value' }} | ||
} | ||
/** If not equals Block helper | ||
/** IF NOT EQUALS block helper | ||
* @example | ||
@@ -312,3 +315,3 @@ * {{#if_ne var 'value' }} | ||
} | ||
/** If greater than Block helper | ||
/** IF GREATER THAN block helper | ||
* @example | ||
@@ -331,3 +334,3 @@ * {{#if_gt var N }} | ||
} | ||
/** If greater or equal than Block helper | ||
/** IF GREATER OR EQUAL TO block helper | ||
* @example | ||
@@ -350,3 +353,3 @@ * {{#if_ge var N }} | ||
} | ||
/** If less than Block helper | ||
/** IF LESS THAN block helper | ||
* @example | ||
@@ -369,3 +372,3 @@ * {{#if_lt var N }} | ||
} | ||
/** If less or equal than Block helper | ||
/** IF LESS OR EQUAL TO block helper | ||
* @example | ||
@@ -388,2 +391,69 @@ * {{#if_le var N }} | ||
} | ||
/** IF AND block helper | ||
* @example | ||
* {{#if_and a b c ... }} | ||
* a && b && c ... === true | ||
* {{else}} | ||
* a && b && c ... === false | ||
* {{/if_and}} | ||
*/ | ||
function registerIfAndHelper() { | ||
handlebars_1.default.registerHelper('if_and', function (...args) { | ||
if (args.length <= 2) { | ||
throw new Error('Block helper #if_and requires 2 or more arguments: {{#if_and a b ... }} {{/if_and}}'); | ||
} | ||
const options = args[args.length - 1]; | ||
const resultBooleanValue = args.slice(0, args.length - 1).every((arg) => arg); | ||
if (resultBooleanValue) { | ||
return options.fn(this); | ||
} | ||
else { | ||
return options.inverse(this); | ||
} | ||
}); | ||
} | ||
/** IF OR block helper | ||
* @example | ||
* {{#if_or a b c ... }} | ||
* a || b || c ... === true | ||
* {{else}} | ||
* a || b || c ... === false | ||
* {{/if_or}} | ||
*/ | ||
function registerIfOrHelper() { | ||
handlebars_1.default.registerHelper('if_or', function (...args) { | ||
if (args.length <= 2) { | ||
throw new Error('Block helper #if_or requires 2 or more arguments: {{#if_or a b ... }} {{/if_or}}'); | ||
} | ||
const options = args[args.length - 1]; | ||
const resultBooleanValue = args.slice(0, args.length - 1).some((arg) => arg); | ||
if (resultBooleanValue) { | ||
return options.fn(this); | ||
} | ||
else { | ||
return options.inverse(this); | ||
} | ||
}); | ||
} | ||
/** IF XOR block helper | ||
* @example | ||
* {{#if_xor a b c ... }} | ||
* There is at least 1 TRUE value and 1 FALSE value | ||
* {{else}} | ||
* All values are TRUE or all values are FALSE | ||
* {{/if_xor}} | ||
*/ | ||
function registerIfXorHelper() { | ||
handlebars_1.default.registerHelper('if_xor', function (...args) { | ||
if (args.length <= 2) { | ||
throw new Error('Block helper #if_xor requires 2 or more arguments: {{#if_xor a b ... }} {{/if_xor}}'); | ||
} | ||
const options = args[args.length - 1]; | ||
const values = args.slice(0, args.length - 1); | ||
if (values.every((value) => value) || values.every((value) => !value)) { | ||
return options.inverse(this); | ||
} | ||
return options.fn(this); | ||
}); | ||
} | ||
function scanSourceFiles() { | ||
@@ -390,0 +460,0 @@ const allSourceFiles = filesystem.scanFiles(configuration_1.default.getSourceDirectoryPath(), false, true, true); |
{ | ||
"name": "symply", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"description": "A simple static site generator.", | ||
@@ -5,0 +5,0 @@ "author": "Oleg Legun <oleg.legun@gmail.com>", |
199817
1784