'use strict';
var path = require('path');
var util = require('handlebars-utils');
var html = require('./utils/html');
var utils = require('./utils');
var parseAttr = html.parseAttributes;
var helpers = module.exports;
/**
* Stringify attributes on the options `hash`.
*
* ```handlebars
*
*
*
* {{css stylesheets}}
*
*
*
*
* ```
* @param {String|Array} `list` One or more stylesheet urls.
* @return {String}
* @api public
*/
helpers.css = function(list, options) {
if (arguments.length < 2) {
options = list;
list = [];
}
var styles = util.arrayify(list);
var assets = '';
if (this && this.options) {
assets = this.options.assets || '';
}
if (options.hash.href) {
styles = util.arrayify(options.hash.href);
}
return styles.map(function(item) {
var ext = path.extname(item);
var fp = item;
if (!/(^\/\/)|(:\/\/)/.test(item)) {
fp = path.posix.join(assets, item);
}
if (ext === '.less') {
return '';
}
return '';
}).join('\n');
};
/**
* Generate one or more `` tags with paths/urls to
* javascript or coffeescript files.
*
* ```handlebars
* {{js scripts}}
* ```
* @param {Object} `context`
* @return {String}
* @api public
*/
helpers.js = function(context) {
if (utils.typeOf(context) === 'object') {
var attr = parseAttr(context.hash);
return '';
}
if (utils.typeOf(context) === 'string') {
return '';
}
context = util.arrayify(context);
return context.map(function(fp) {
return (path.extname(fp) === '.coffee')
? utils.tag('script', {type: 'text/coffeescript', src: fp})
: utils.tag('script', {src: fp});
}).join('\n');
};
/**
* Strip HTML tags from a string, so that only the text nodes
* are preserved.
*
* ```handlebars
* {{sanitize "foo"}}
*
* ```
*
* @param {String} `str` The string of HTML to sanitize.
* @return {String}
* @api public
*/
helpers.sanitize = function(str) {
return html.sanitize(str);
};
/**
* Block helper for creating unordered lists (`