Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OFFSITE-3616] - Pontential Handlebar Issue Offsite Templates #432

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
version: 2

jobs:
build:
docker:
- image: circleci/node:8
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}-{{ checksum "yarn.lock" }}
- run:
name: Npm login
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- run:
name: Install packages
command: yarn
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}-{{ checksum "yarn.lock" }}
paths:
- node_modules
- ~/.cache/yarn
- run:
name: Run tests
command: yarn test
- persist_to_workspace:
root: .
paths:
- .
publish:
docker:
- image: circleci/node:8
steps:
- attach_workspace:
at: .
- run:
name: Npm login
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- run:
name: Publish
command: |
npm publish


workflows:
version: 2
build_publish:
jobs:
- build:
context: org-global
filters:
tags:
only: /.*/
- publish:
context: org-global
requires:
- build
filters:
tags:
only: /^release-.*/
branches:
ignore: /.*/
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ node_modules
npm-debug.log

# yarn
yarn.lock
yarn-error.log

# misc
Expand All @@ -26,4 +25,4 @@ vendor
temp
tmp
TODO.md
package-lock.json
package-lock.json
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ node_js:
- '5'
- '4'
- '0.12'
before_script:
- npm install -g gulp-cli
script: gulp
allowed_failures:
node_js: '0.12'
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# handlebars-helpers [![NPM version](https://img.shields.io/npm/v/handlebars-helpers.svg?style=flat)](https://www.npmjs.com/package/handlebars-helpers) [![NPM monthly downloads](https://img.shields.io/npm/dm/handlebars-helpers.svg?style=flat)](https://npmjs.org/package/handlebars-helpers) [![NPM total downloads](https://img.shields.io/npm/dt/handlebars-helpers.svg?style=flat)](https://npmjs.org/package/handlebars-helpers) [![Linux Build Status](https://img.shields.io/travis/helpers/handlebars-helpers.svg?style=flat&label=Travis)](https://travis-ci.org/helpers/handlebars-helpers) [![Windows Build Status](https://img.shields.io/appveyor/ci/helpers/handlebars-helpers.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/helpers/handlebars-helpers)
# handlebars-helpers

> More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.
Forked from [https://github.com/helpers/handlebars-helpers](https://github.com/helpers/handlebars-helpers)

You might also be interested in [template-helpers](https://github.com/jonschlinkert/template-helpers).

Expand Down
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
environment:
matrix:
# node.js
- nodejs_version: "9.0"
- nodejs_version: "8.0"
- nodejs_version: "7.0"
- nodejs_version: "6.0"
- nodejs_version: "5.0"
- nodejs_version: "4.0"
- nodejs_version: "0.12"

# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
- npm install
- npm install -g gulp-cli

# Post-install test scripts.
test_script:
# Output useful info for debugging.
- node --version
- npm --version
# run tests
- gulp

# Don't actually build.
build: off
32 changes: 27 additions & 5 deletions lib/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,49 @@ helpers.filter = function(array, value, options) {
var content = '';
var results = [];

if (!Array.isArray(array)) {
if (options.fn) {
return content;
}
return [];
}

// filter on a specific property
var prop = options.hash && (options.hash.property || options.hash.prop);
if (prop) {
results = array.filter(function(val) {
if (value instanceof RegExp) {
return value.test(utils.get(val, prop));
}
return value === utils.get(val, prop);
});
} else {

// filter on a string value
results = array.filter(function(v) {
if (value instanceof RegExp) {
return value.test(v);
}
return value === v;
});
}

if (results && results.length > 0) {
for (var i = 0; i < results.length; i++) {
content += options.fn(results[i]);
if (options.fn) {
for (var i = 0; i < results.length; i++) {
content += options.fn(results[i]);
}
return content;
} else {
return results;
}
return content;
}
return options.inverse(this);

if (options && options.inverse) {
return options.inverse(this);
}

return '';
};

/**
Expand Down Expand Up @@ -222,7 +244,7 @@ helpers.forEach = function(array, options) {
*/

helpers.inArray = function(array, value, options) {
return util.value(util.indexOf(array, value) > -1, this, options);
return util.value(array && util.indexOf(array, value) > -1, this, options);
};

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/comparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ helpers.isTruthy = function(val, options) {
*/

helpers.ifEven = function(num, options) {
return util.value(utils.isEven(num), this, options);
return util.value(!!num && utils.isEven(num), this, options);
};

/**
Expand Down Expand Up @@ -348,7 +348,7 @@ helpers.ifNth = function(a, b, options) {
*/

helpers.ifOdd = function(val, options) {
return util.value(!utils.isEven(val), this, options);
return util.value(!!val && !utils.isEven(val), this, options);
};

/**
Expand Down
88 changes: 65 additions & 23 deletions lib/math.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
'use strict';

var isNumber = require('is-number');
var utils = require('./utils');
var helpers = module.exports;

function isNumber(num) {
if (typeof num === 'number') {
return num - num === 0;
}
if (typeof num === 'string' && num.trim() !== '') {
if (num.split('.').length > 2) {
return num;
}
return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
}
return false;
}

function coerceToNumber(num) {
if (typeof num === 'number') {
return num;
}

if (typeof num === 'string' && num.trim() !== '') {
if (num.split('.').length > 2) {
return num;
}
return Number(num);
}
}

/**
* Return the magnitude of `a`.
*
Expand All @@ -29,11 +54,11 @@ helpers.abs = function(num) {
*/

helpers.add = function(a, b) {
if (isNumber(a) && isNumber(b)) {
return Number(a) + Number(b);
}
if (typeof a === 'string' && typeof b === 'string') {
return a + b;
const numA = coerceToNumber(a);
const numB = coerceToNumber(b);

if (isNumber(numA) && isNumber(numB)) {
return numA + numB;
}
return '';
};
Expand Down Expand Up @@ -82,13 +107,16 @@ helpers.ceil = function(num) {
*/

helpers.divide = function(a, b) {
if (!isNumber(a)) {
const numA = coerceToNumber(a);
const numB = coerceToNumber(b);

if (!isNumber(numA)) {
throw new TypeError('expected the first argument to be a number');
}
if (!isNumber(b)) {
if (!isNumber(numB)) {
throw new TypeError('expected the second argument to be a number');
}
return Number(a) / Number(b);
return numA / numB;
};

/**
Expand All @@ -100,10 +128,12 @@ helpers.divide = function(a, b) {
*/

helpers.floor = function(num) {
if (!isNumber(num)) {
const numA = coerceToNumber(num);

if (!isNumber(numA)) {
throw new TypeError('expected a number');
}
return Math.floor(num);
return Math.floor(numA);
};

/**
Expand All @@ -116,13 +146,16 @@ helpers.floor = function(num) {
*/

helpers.minus = function(a, b) {
if (!isNumber(a)) {
const numA = coerceToNumber(a);
const numB = coerceToNumber(b);

if (!isNumber(numA)) {
throw new TypeError('expected the first argument to be a number');
}
if (!isNumber(b)) {
if (!isNumber(numB)) {
throw new TypeError('expected the second argument to be a number');
}
return Number(a) - Number(b);
return numA - numB;
};

/**
Expand Down Expand Up @@ -155,13 +188,16 @@ helpers.modulo = function(a, b) {
*/

helpers.multiply = function(a, b) {
if (!isNumber(a)) {
const numA = coerceToNumber(a);
const numB = coerceToNumber(b);

if (!isNumber(numA)) {
throw new TypeError('expected the first argument to be a number');
}
if (!isNumber(b)) {
if (!isNumber(numB)) {
throw new TypeError('expected the second argument to be a number');
}
return Number(a) * Number(b);
return numA * numB;
};

/**
Expand All @@ -173,13 +209,16 @@ helpers.multiply = function(a, b) {
*/

helpers.plus = function(a, b) {
if (!isNumber(a)) {
const numA = coerceToNumber(a);
const numB = coerceToNumber(b);

if (!isNumber(numA)) {
throw new TypeError('expected the first argument to be a number');
}
if (!isNumber(b)) {
if (!isNumber(numB)) {
throw new TypeError('expected the second argument to be a number');
}
return Number(a) + Number(b);
return numA + numB;
};

/**
Expand Down Expand Up @@ -239,13 +278,16 @@ helpers.round = function(num) {
*/

helpers.subtract = function(a, b) {
if (!isNumber(a)) {
const numA = coerceToNumber(a);
const numB = coerceToNumber(b);

if (!isNumber(numA)) {
throw new TypeError('expected the first argument to be a number');
}
if (!isNumber(b)) {
if (!isNumber(numB)) {
throw new TypeError('expected the second argument to be a number');
}
return Number(a) - Number(b);
return numA - numB;
};

/**
Expand Down
Loading