<commit_before>/* @flow */
/**
 * renderString.js
 * Written by: <NAME>
 */
import mustache from '../../mustache';

import loadCytoConfig from '../../../configs/loadCytoConfig';
import generateTemplate from '../../../template/generateTemplate';
import types from '../../types';
import errors from '../../errors';

/**
 * Description of renderString
 *
 */
export default function renderString(str, args) {
  mustache.escape = (text) => text; // Don't escape html

  const renderPartial = async (partialString, context) => {
    const tokens = partialString.split(' ').filter((s) => s.trim());
    if (!tokens.length || tokens.length > 2) {
      errors.invalidPartial(partialString, '');
    } else if (tokens.length === 1) {
      if (context.id) {
        tokens.push(context.id);
      } else {
        errors.invalidPartial(partialString);
      }
    }

    const [templateId, id] = tokens;
    const cytoConfig = loadCytoConfig(templateId);

    if (!types.isPartial(cytoConfig)) {
      errors.invalidPartial(partialString, `${templateId} is not a partial!`);
    }

    const generatedPartial = await generateTemplate({
      templateId,
      args: { ...context, id },
      outputRoot: '',
    });

    return Object.keys(generatedPartial).reduce((s, k) => {
      return `${s}${generatedPartial[k]}`;
    }, '');
  };

  return mustache.render(str, args, renderPartial);
}
<commit_msg>pass author arg to partial templates<commit_after>/* @flow */
/**
 * renderString.js
 * Written by: <NAME>
 */
import mustache from '../../mustache';

import loadCytoConfig from '../../../configs/loadCytoConfig';
import generateTemplate from '../../../template/generateTemplate';
import types from '../../types';
import errors from '../../errors';

/**
 * Description of renderString
 *
 */
export default function renderString(str, args) {
  mustache.escape = (text) => text; // Don't escape html

  const renderPartial = async (partialString, context) => {
    const tokens = partialString.split(' ').filter((s) => s.trim());
    if (!tokens.length || tokens.length > 2) {
      errors.invalidPartial(partialString, '');
    } else if (tokens.length === 1) {
      if (context.id) {
        tokens.push(context.id);
      } else {
        errors.invalidPartial(partialString);
      }
    }

    const [templateId, id] = tokens;
    const cytoConfig = loadCytoConfig(templateId);

    if (!types.isPartial(cytoConfig)) {
      errors.invalidPartial(partialString, `${templateId} is not a partial!`);
    }

    const generatedPartial = await generateTemplate({
      templateId,
      args: { ...context, id, author: args.author },
      outputRoot: '',
    });

    return Object.keys(generatedPartial).reduce((s, k) => {
      return `${s}${generatedPartial[k]}`;
    }, '');
  };

  return mustache.render(str, args, renderPartial);
}

{'fraction_non_alphanumeric': 0.1717207334273625, 'fraction_numerical': 0.0014104372355430183, 'mean_word_length': 3.0127298444130126, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '925332', 'n_tokens_mistral': 834, 'n_tokens_neox': 823, 'n_words': 201}