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

[WIP] Remove handlebars-utils package #15

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
10 changes: 9 additions & 1 deletion lib/array.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
'use strict';

var util = require('handlebars-utils');
var util = {
isUndefined: require('./utils/isUndefined'),
result: require('./utils/result'),
value: require('./utils/value'),
indexOf: require('./utils/indexOf'),
isString: require('./utils/isString'),
isOptions: require('./utils/isOptions'),
isObject: require('./utils/isObject')
};
var helpers = module.exports;
const getValue = require('get-value');
const createFrame = require('./utils/createFrame');
Expand Down
2 changes: 1 addition & 1 deletion lib/collection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var util = require('handlebars-utils');
var util = require('./utils/handlebarsUtils');
var object = require('./object');
var array = require('./array');
var forEach = array.forEach;
Expand Down
13 changes: 10 additions & 3 deletions lib/comparison.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
'use strict';

var has = require('has-value');
var util = require('handlebars-utils');
var util = {
value: require('./utils/value'),
isOptions: require('./utils/isOptions'),
isString: require('./utils/isString'),
fn: require('./utils/fn'),
isObject: require('./utils/isObject'),
inverse: require('./utils/inverse')
};
var utils = require('./utils');
const falsey = require('./utils/falsey');
const isOdd = require('./utils/odd');
Expand Down Expand Up @@ -447,8 +454,8 @@ helpers.lt = function(a, b, options) {
* You may optionally use the `compare=''` hash argument for the
* second value.
*
* @param {Sring} `a`
* @param {Sring} `b`
* @param {String} `a`
* @param {String} `b`
* @param {Object} `options` Handlebars provided options object
* @return {String} Block, or inverse block if specified and falsey.
* @block
Expand Down
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var fs = require('fs');
var path = require('path');
var util = require('handlebars-utils');
var util = require('./utils/handlebarsUtils');
var number = require('./number');
var helpers = module.exports;
const kindOf = require('kind-of');
Expand Down
6 changes: 3 additions & 3 deletions lib/html.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var path = require('path');
var util = require('handlebars-utils');
var util = require('./utils/handlebarsUtils');
var html = require('./utils/html');
var parseAttr = html.parseAttributes;
var helpers = module.exports;
Expand Down Expand Up @@ -99,8 +99,8 @@ helpers.js = function(context) {
context = util.arrayify(context);
return context.map(function(fp) {
return (path.extname(fp) === '.coffee')
? htmlTag('script', {type: 'text/coffeescript', src: fp})
: htmlTag('script', {src: fp});
? htmlTag('script', { type: 'text/coffeescript', src: fp })
: htmlTag('script', { src: fp });
}).join('\n');
};

Expand Down
2 changes: 1 addition & 1 deletion lib/i18n.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var util = require('handlebars-utils');
var util = require('./utils/handlebarsUtils');
var helpers = module.exports;
const getValue = require('get-value');

Expand Down
2 changes: 1 addition & 1 deletion lib/inflection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var util = require('handlebars-utils');
var util = require('./utils/handlebarsUtils');
var helpers = module.exports;

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/match.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var util = require('handlebars-utils');
var util = require('./utils/handlebarsUtils');
var helpers = module.exports;
const micromatch = require('micromatch');

Expand Down
4 changes: 2 additions & 2 deletions lib/misc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var util = require('handlebars-utils');
var util = require('./utils/handlebarsUtils');
var helpers = module.exports;
const getValue = require('get-value');
const createFrame = require('./utils/createFrame');
Expand All @@ -22,7 +22,7 @@ helpers.frame = function(context, options) {

// extend the frame with hash arguments
frame.extend(options.hash);
return options.fn(this, {data: frame});
return options.fn(this, { data: frame });
};

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/number.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var util = require('handlebars-utils');
var util = {
isUndefined: require('./utils/isUndefined')
};
var helpers = module.exports;

/**
Expand Down
9 changes: 6 additions & 3 deletions lib/object.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
'use strict';

var hasOwn = Object.hasOwnProperty;
var util = require('handlebars-utils');
var util = {
isOptions: require('./utils/isOptions'),
isObject: require('./utils/isObject')
};
var array = require('./array');
var helpers = module.exports;
const getValue = require('get-value');
Expand Down Expand Up @@ -64,7 +67,7 @@ helpers.forIn = function(obj, options) {

for (var key in obj) {
data.key = key;
result += options.fn(obj[key], {data: data});
result += options.fn(obj[key], { data: data });
}
return result;
};
Expand All @@ -91,7 +94,7 @@ helpers.forOwn = function(obj, options) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
data.key = key;
result += options.fn(obj[key], {data: data});
result += options.fn(obj[key], { data: data });
}
}
return result;
Expand Down
4 changes: 2 additions & 2 deletions lib/path.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var util = require('handlebars-utils');
var util = require('./utils/handlebarsUtils');
var path = require('path');
const relative = require('relative');
var helpers = module.exports;
Expand All @@ -18,7 +18,7 @@ var helpers = module.exports;
*/

helpers.absolute = function(filepath, options) {
options = options || {data: {}};
options = options || { data: {} };
var context = util.options(this, options);
var ctx = Object.assign({}, options.data.root, context);
var cwd = ctx.cwd || process.cwd();
Expand Down
2 changes: 1 addition & 1 deletion lib/regex.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var util = require('handlebars-utils');
var util = { options: require('./utils/options') };
var helpers = module.exports;
const kindOf = require('kind-of');

Expand Down
6 changes: 5 additions & 1 deletion lib/string.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
'use strict';

var util = require('handlebars-utils');
var util = {
isString: require('./utils/isString'),
isObject: require('./utils/isObject'),
options: require('./utils/options')
};
var utils = require('./utils');
var helpers = module.exports;

Expand Down
4 changes: 3 additions & 1 deletion lib/url.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';

var url = require('url');
var util = require('handlebars-utils');
var util = {
isString: require('./utils/isString')
};
var querystring = require('querystring');
var helpers = module.exports;

Expand Down
40 changes: 40 additions & 0 deletions lib/utils/fn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

const isBlock = require('./isBlock');
const isOptions = require('./isOptions');
const fn = require('./fn');

/**
* This code was taken directly from handlebars-helpers,
* https://github.com/helpers/handlebars-utils/blob/master/index.js#L398
*
* that was taken directly from handlebars.
* https://github.com/wycats/handlebars.js/blob/b55a120e8222785db3dc00096f6afbf91b656e8a/LICENSE
* Released under the MIT License
* Copyright (C) 2011-2016 by Yehuda Katz
*/

/**
* Returns the given value or renders the block if it's a block helper.
*
* ```js
* Handlebars.registerHelper('example', function(val, locals, options) {
* return utils.fn(val, locals, options);
* });
* ```
* @param {any} `val`
* @param {Object} `options`
* @param {Object} `context`
* @return {String} Either returns the value, or renders the block.
* @api public
*/

module.exports = function(val, context, options) {
if (isOptions(val)) {
return fn('', val, options);
}
if (isOptions(context)) {
return fn(val, {}, context);
}
return isBlock(options) ? options.fn(context) : val;
};
Loading
Loading