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,EAAM,EAAU,EAC9C,EAqCA,EAAI,QAAQ,OAAS,eAAgB,EAAM,GACzC,MAAM,EAAM,KAEN,EAAU,OAAO,OAAO,CAAC,EAAG,EAAI,MAAO,GAE7C,IAAI,QAAa,EAAO,EAAM,GAE9B,MAAM,GAA4B,IAAnB,EAAQ,SAA4B,EAAQ,QAAU,EAAS,QAC1E,IAEF,EAAQ,KAAO,EACf,QAAa,EAAO,EAAQ,IAI9B,MADwC,IAAtB,EAAQ,YAA+B,EAAQ,WAAa,EAAS,YAOrF,OAAO,EAJP,EAAI,KAAO,OACX,EAAI,KAAO,CAKf,CACF,EAMA,QAAQ,IAAM","file":"/npm/koa-ejs@4.3.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/koa-ejs@4.3.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/*!\n * koa-ejs - index.js\n * Copyright(c) 2017 dead_horse <dead_horse@qq.com>\n * MIT Licensed\n */\n\n'use strict';\n\n/**\n * Module dependencies.\n */\n\nconst debug = require('debug')('koa-ejs');\nconst fs = require('mz').fs;\nconst path = require('path');\nconst ejs = require('ejs');\n\n/**\n * Temp assigned for override later\n */\nconst parentResolveInclude = ejs.resolveInclude;\n\n/**\n * default render options\n * @type {Object}\n */\nconst defaultSettings = {\n  cache: true,\n  layout: 'layout',\n  viewExt: 'html',\n  locals: {},\n  compileDebug: false,\n  debug: false,\n  writeResp: true,\n  async: false\n};\n\n/**\n * set app.context.render\n *\n * usage:\n * ```\n * await ctx.render('user', {name: 'dead_horse'});\n * ```\n * @param {Application} app koa application instance\n * @param {Object} settings user settings\n */\nexports = module.exports = function (app, settings) {\n  if (app.context.render) {\n    return;\n  }\n\n  if (!settings || !settings.root) {\n    throw new Error('settings.root required');\n  }\n\n  settings.root = path.resolve(process.cwd(), settings.root);\n\n  /**\n   * cache the generate package\n   * @type {Object}\n   */\n  const cache = Object.create(null);\n\n  settings = Object.assign({}, defaultSettings, settings);\n\n  settings.viewExt = settings.viewExt\n    ? '.' + settings.viewExt.replace(/^\\./, '')\n    : '';\n\n  // override `ejs` node_module `resolveInclude` function\n  ejs.resolveInclude = function(name, filename, isDir) {\n    if (!path.extname(name)) {\n      name += settings.viewExt;\n    }\n    return parentResolveInclude(name, filename, isDir);\n  }\n\n  /**\n   * generate html with view name and options\n   * @param {String} view\n   * @param {Object} options\n   * @return {String} html\n   */\n  async function render(view, options) {\n    view += settings.viewExt;\n    const viewPath = path.join(settings.root, view);\n    debug(`render: ${viewPath}`);\n    // get from cache\n    if (settings.cache && cache[viewPath]) {\n      return cache[viewPath].call(options.scope, options);\n    }\n\n    const tpl = await fs.readFile(viewPath, 'utf8');\n\n    const fn = ejs.compile(tpl, {\n      filename: viewPath,\n      _with: settings._with,\n      compileDebug: settings.debug && settings.compileDebug,\n      debug: settings.debug,\n      delimiter: settings.delimiter,\n      cache: settings.cache,\n      async: settings.async,\n      outputFunctionName: settings.outputFunctionName\n    });\n    if (settings.cache) {\n      cache[viewPath] = fn;\n    }\n\n    return fn.call(options.scope, options);\n  }\n\n\n  app.context.render = async function (view, _context) {\n    const ctx = this;\n\n    const context = Object.assign({}, ctx.state, _context);\n\n    let html = await render(view, context);\n\n    const layout = context.layout === false ? false : (context.layout || settings.layout);\n    if (layout) {\n      // if using layout\n      context.body = html;\n      html = await render(layout, context);\n    }\n\n    const writeResp = context.writeResp === false ? false : (context.writeResp || settings.writeResp);\n    if (writeResp) {\n      // normal operation\n      ctx.type = 'html';\n      ctx.body = html;\n    } else {\n      // only return the html\n      return html;\n    }\n  };\n};\n\n/**\n * Expose ejs\n */\n\nexports.ejs = ejs;\n"]}