<commit_before>'use strict';

const Handlebars = require('handlebars');
const _          = require('lodash');
const utils      = require('@frctl/fractal').utils;

module.exports = function(fractal){

    return function staticPath(path, root){
        root = this._config ? this : root;

        if (! root || ! root._env || root._env.server) {
            return path;
        }

        return utils.relUrlPath(path, _.get(root._request, 'path', '/'), fractal.web.get('builder.urls'));
    };

};<commit_msg>Support variable interpolation in path strings<commit_after>'use strict';

const Handlebars = require('handlebars');
const _          = require('lodash');
const utils      = require('@frctl/fractal').utils;

module.exports = function(fractal){

    return function staticPath(path){

        const options = Array.from(arguments).pop();
        const root = options.data.root;

        if (path.includes('{{')) {
            let context = _.defaults({}, this, _.pickBy(root, (item, key) => key.startsWith('_')));
            const tpl = Handlebars.compile(path, {
                data: false
            });
            path = tpl(context);
        }

        if (! root || ! root._env || root._env.server) {
            return path;
        }

        return utils.relUrlPath(path, _.get(root._request, 'path', '/'), fractal.web.get('builder.urls'));
    };

};
{'fraction_non_alphanumeric': 0.15962099125364432, 'fraction_numerical': 0.0, 'mean_word_length': 2.4759493670886075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4138598', 'n_tokens_mistral': 404, 'n_tokens_neox': 398, 'n_words': 85}