<commit_before>import path from 'path'
import pug from 'pug'
import helpers from './helpers'

const componentsPath = path.resolve(__dirname, 'components')
const templatesPath = path.resolve(__dirname, 'templates')

const pugOpts = {
  basedir: componentsPath,
  pretty: true,
  cache: true
}

export const staticPath = path.resolve(__dirname, '..', 'static')

export async function render (options, id, data = {}) {
  return new Promise((resolve, reject) => {
    const filePath = path.resolve(templatesPath, `${id}.pug`)
    const theme = { h: helpers(options, data) }
    const context = Object.assign({}, pugOpts, data, theme)

    try {
      const rendered = pug.renderFile(filePath, context)

      resolve(rendered)
    } catch (err) {
      reject([
        `Pug could not render "${filePath}"!`,
        err.stack,
        JSON.stringify(context, null, '  ')
      ].join('\n\n'))
    }
  })
}<commit_msg>💂 pass through options and add debug flag<commit_after>import path from 'path'
import pug from 'pug'
import helpers from './helpers'

const componentsPath = path.resolve(__dirname, 'components')
const templatesPath = path.resolve(__dirname, 'templates')

const pugOpts = {
  basedir: componentsPath,
  pretty: true,
  cache: true
}

export const staticPath = path.resolve(__dirname, '..', 'static')

export async function render (options, id, data = {}) {
  return new Promise((resolve, reject) => {
    const filePath = path.resolve(templatesPath, `${id}.pug`)
    const theme = { h: helpers(options, data) }
    const context = Object.assign({}, pugOpts, options, data, theme)

    try {
      const rendered = pug.renderFile(filePath, context)

      resolve(rendered)
    } catch (err) {
      const message = [`Pug could not render "${filePath}"!`, err]

      if (options.debug) message.push(JSON.stringify(context, null, '  '))

      reject(message.join('\n\n'))
    }
  })
}
{'fraction_non_alphanumeric': 0.14285714285714285, 'fraction_numerical': 0.0, 'mean_word_length': 3.6067961165048543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6950561', 'n_tokens_mistral': 582, 'n_tokens_neox': 582, 'n_words': 165}