const utils = require('./utils'); const path = require('path'); /** * @exports html */ const helpers = module.exports; /** * Parse HTML tag attributes from the `options.hash`. * * @param {Object} `hash` Helper options hash, e.g. `{foo: 'bar'}` * @return {String} Stringified attributes, e.g. `foo="bar"` * @api public */ const parseAttr = function parseAttributes(hash) { return Object.keys(hash).map(function(key) { const val = String(hash[key]).replace(/^['"]|["']$/g, ''); return key + '="' + val + '"'; }).join(' '); }; /** * 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 = []; } let styles = utils.arrayify(list); let assets = ''; if (this && this.options) { assets = this.options.assets || ''; } if (options.hash.href) { styles = utils.arrayify(options.hash.href); } return styles.map(function(item) { const ext = path.extname(item); let fp = item; if (!/(^\/\/)|(:\/\/)/.test(item)) { fp = path.posix.join(assets, item); } if (ext === '.less') { return ''; } return ''; }).join('\n'); }; /** * Block helper for creating unordered lists (``) * * @param {Object} `context` * @param {Object} `options` * @return {String} * @block * @api public */ helpers.ul = function(context, options) { return (''; }; /** * Block helper for creating ordered lists (`
    `) * * @param {Object} `context` * @param {Object} `options` * @return {String} * @block * @api public */ helpers.ol = function(context, options) { return ('
      ') + context.map(function(item) { if (typeof item !== 'string') { item = options.fn(item); } return '
    1. ' + item + '
    2. '; }).join('\n') + '
    '; }; /** * Returns a `
    ` with a thumbnail linked to a full picture * * @param {Object} `context` Object with values/attributes to add to the generated elements: * @param {String} `context.alt` * @param {String} `context.src` * @param {Number} `context.width` * @param {Number} `context.height` * @return {String} HTML `
    ` element with image and optional caption/link. * @contributor: Marie Hogebrandt * @api public */ helpers.thumbnailImage = function(context) { let figure = ''; let image = ''; const link = context.full || false; const imageAttributes = { alt: context.alt, src: context.thumbnail, width: context.size.width, height: context.size.height }; const figureAttributes = { id: 'image-' + context.id }; const linkAttributes = { href: link, rel: 'thumbnail' }; if (context.classes) { if (context.classes.image) { imageAttributes.class = context.classes.image.join(' '); } if (context.classes.figure) { figureAttributes.class = context.classes.figure.join(' '); } if (context.classes.link) { linkAttributes.class = context.classes.link.join(' '); } } figure += '
    \n'; image += '\n'; if (link) { figure += '\n' + image + '\n'; } else { figure += image; } if (context.caption) { figure += '
    ' + context.caption + '
    \n'; } figure += '
    '; return figure; };