How to use the nunjucks.renderString function in nunjucks

To help you get started, we’ve selected a few nunjucks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github epinna / tplmap / tests / env_node_tests / connect-app.js View on Github external
app.use('/blind/nunjucks', function(req, res){
  if(req.url) {
    var url_parts = url.parse(req.url, true);

    var inj = url_parts.query.inj;
    var tpl = '';
    if('tpl' in url_parts.query && url_parts.query.tpl != '') {
      // Keep the formatting a-la-python
      tpl = url_parts.query.tpl.replace('%s', inj);
    }
    else {
      tpl = inj;
    }
    nunjucks.renderString(tpl);
    res.end(randomstring.generate());
  }
});
github okiba-gang / okiba / docs / generate.js View on Github external
packageData.pkgName = name
    const packageJSON = JSON.parse(readFileSync(`./packages/${name}/package.json`))
    packageData.version = packageJSON.version
    const markdown = nunjucks.renderString(template, packageData)
    writeFileSync(`./packages/${name}/README.md`, markdown)

    try {
      baseData.packages.push(modelPackage(packageData, baseData))
    } catch (e) {
      throw new Error(`Missing required fields in package: ${name}\n`)
    }
    // writeFileSync(`./debug/data-${name}-dump.js`, JSON.stringify(data))
  })

  // await writeFileSync('./debug/data-root-dump.js', JSON.stringify(rootData))
  const markdown = nunjucks.renderString(templateRoot, baseData)
  writeFileSync('./README.md', markdown)
}
github whxaxes / mus / benchmark / renderNoCache.js View on Github external
.add('Nunjucks#renderNoCache', function() {
    nunjucks.renderString(str, obj);
  })
  // add listeners
github formio / formio / install.js View on Github external
// Set local variable to directory path.
      let directoryPath = directories[dir];

      // Change the document root if we need to.
      if (info.formio && info.formio.docRoot) {
        directoryPath = path.join(directories[dir], info.formio.docRoot);
      }

      if (!fs.existsSync(path.join(directoryPath, 'config.template.js'))) {
        return done('Missing config.template.js file');
      }

      // Change the project configuration.
      const config = fs.readFileSync(path.join(directoryPath, 'config.template.js'));
      const newConfig = nunjucks.renderString(config.toString(), {
        domain: formio.config.domain ? formio.config.domain : 'https://form.io'
      });
      fs.writeFileSync(path.join(directoryPath, 'config.js'), newConfig);
      done();
    });
  };
github apostrophecms / mechanic / app.js View on Github external
return 1;
      } else if (b.default) {
        return -1;
      }
    }
  });

  _.each(data.sites, function(site) {
    delete site._index;
  });

  var sites = _.filter(data.sites, validSiteFilter);

  var template = fs.readFileSync(settings.template || (__dirname + '/template.conf'), 'utf8');

  var output = nunjucks.renderString(template, {
    sites: sites,
    settings: settings
  });

  // Set up include-able files to allow
  // easy customizations
  _.each(sites, function(site) {
    var folder = settings.overrides;
    if (!fs.existsSync(folder)) {
      fs.mkdirSync(folder);
    }
    folder += '/' + site.shortname;
    if (!fs.existsSync(folder)) {
      fs.mkdirSync(folder);
    }
    var files = [ 'location', 'proxy', 'server', 'top' ];
github benjycui / bisheng / packages / bisheng-core / lib / loaders / bisheng-nunjucks-loader.js View on Github external
module.exports = function bishengEntryLoader(content) {
  if (this.cacheable) {
    this.cacheable();
  }

  const query = loaderUtils.parseQuery(this.query);
  const config = getConfig(query.config);
  const themePath = path.join(process.cwd(), config.theme);
  const root = query.isBuild === true ? config.root : '/';

  return nunjucks.renderString(content, { themePath, root });
};
github rundeck / docs / docs / .vuepress / nunjucks.js View on Github external
module.exports = function(source) {
    const isProd = process.env.NODE_ENV === 'production'
    const isServer = this.target === 'node'

    const rendered = nunjucks.renderString(source, config)
    return rendered
}
github benjycui / bisheng / packages / bisheng / src / index.js View on Github external
function getRoutesPath(themePath, configEntryName) {
  const routesTemplate = fs.readFileSync(path.join(__dirname, 'routes.nunjucks.js')).toString();
  const routesPath = path.join(tmpDirPath, `routes.${configEntryName}.js`);
  const { bishengConfig, themeConfig } = context;
  fs.writeFileSync(
    routesPath,
    nunjucks.renderString(routesTemplate, {
      themePath: escapeWinPath(themePath),
      themeConfig: JSON.stringify(bishengConfig.themeConfig),
      themeRoutes: JSON.stringify(themeConfig.routes),
    }),
  );
  return routesPath;
}
github benjycui / bisheng / packages / bisheng / src / index.js View on Github external
function getRoutesPath(themePath, configEntryName) {
  const routesTemplate = fs.readFileSync(path.join(__dirname, 'routes.nunjucks.js')).toString();
  const routesPath = path.join(tmpDirPath, `routes.${configEntryName}.js`);
  const { bishengConfig, themeConfig } = context;
  fs.writeFileSync(
    routesPath,
    nunjucks.renderString(routesTemplate, {
      themePath: escapeWinPath(themePath),
      themeConfig: JSON.stringify(bishengConfig.themeConfig),
      themeRoutes: JSON.stringify(themeConfig.routes),
    }),
  );
  return routesPath;
}