本文整理汇总了TypeScript中nunjucks.configure函数的典型用法代码示例。如果您正苦于以下问题:TypeScript configure函数的具体用法?TypeScript configure怎么用?TypeScript configure使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了configure函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: function
var renderer: HexoSyncRenderer = function (data, locals) {
var templateDir = path.dirname(data.path);
var env = nunjucks.configure(templateDir, hexo.config.nunjucks);
return env.renderString(data.text, locals);
}
开发者ID:kfitzgerald,项目名称:hexo-renderer-nunjucks,代码行数:7,代码来源:index.ts
示例2: initializeNunjucs
private initializeNunjucs(commonCollectiveName: string, viewsDirectory: string, version: string,
debug: boolean, powered: boolean, urlOrigin: string,
ownersPath: string, headersPath: string): nunjucks.Environment {
const nj: nunjucks.Environment = nunjucks.configure(viewsDirectory, {
autoescape: true,
noCache: debug,
watch: debug,
});
nj.addGlobal("version", version);
nj.addGlobal("commonCollectiveName", commonCollectiveName);
nj.addGlobal("development", debug);
nj.addGlobal("urlOrigin", urlOrigin);
nj.addGlobal("ownersPath", ownersPath);
nj.addGlobal("headersPath", headersPath);
if (powered) nj.addGlobal("powered", true);
// Add utility methods
nj.addGlobal("formatDate", this.formatDate);
let domain;
if (urlOrigin && urlOrigin.startsWith("https://")) {
domain = urlOrigin.substr(8);
} else if (urlOrigin && urlOrigin.startsWith("http://")) {
domain = urlOrigin.substr(7);
} else {
// Fail if urlOrigin is invalid
throw new Error("FATAL: urlOrigin invalid or not set, exiting");
}
nj.addGlobal("domain", domain);
return nj;
}
开发者ID:extendedmind,项目名称:extendedmind,代码行数:32,代码来源:rendering.ts
示例3: function
return async function(filename: string | any, data?: any) {
if (typeof filename !== 'string') {
data = filename;
filename = null;
}
// i.e., we've not been provided a specific file.
if (filename === null) {
filename = `${ ctx.controller.name }/${ ctx.controller.action }.html`;
}
// fetch our application
const application = overland.apps.get(ctx.controller.app);
// configure load paths
const paths = [
overland.settings.views,
`${ overland.settings.views }/${ ctx.controller.app }`,
application.views
];
// stat potential template files
const candidates = await Promise.all(paths.map((viewDir): Promise<boolean> => {
return new Promise((resolve, reject) => {
const test = `${ viewDir }/${ filename }`;
stat(test, (err, res) => {
if (err) resolve(false);
resolve(true);
});
});
}));
const base = paths[candidates.findIndex(p => p === true)];
if (base === undefined) {
const e = new Error(`No template found with name '${ filename }' in app or site directory!`);
e.name = 'No Such Template'
throw e;
}
const env = nunjucks.configure(paths, { watch: true });
const renderEnv = application.nunjucksEnv ? Object.assign(application.nunjucksEnv, { loaders: env.loaders, opts: env.opts }) : env;
renderEnv.addGlobal('css', ctx.state.css);
renderEnv.addGlobal('js', ctx.state.js);
renderEnv.addGlobal('asset', ctx.state.asset_path);
const renderCtx = overland.createRenderContext(ctx, data);
return renderEnv.render(base + '/' + filename, renderCtx);
};
开发者ID:overlandjs,项目名称:overland-nunjucks,代码行数:50,代码来源:index.ts
示例4: function
export default function(template: string, options?: any) {
options = Object.assign({}, options);
let nunjucksOptions = Object.assign({noCache: true}, options.nunjucks);
var env = nunjucks.configure(nunjucksOptions);
env.addFilter("nunjucks", (t,data) => nunjucks.renderString(t, data));
Object.keys(options.filters || {}).forEach(key => {
env.addFilter(key, options.filters[key])
});
Object.keys(options.globals || {}).forEach(key => {
env.addGlobal(key, options.globals[key])
});
return through.obj(function(file:gutil.File, encoding: string, callback: (err?: Error, data?: gutil.File) => void): void {
if (file.isNull()) {
return callback(null, file);
}
if (file.isStream() ||Â !(file.contents instanceof Buffer)) {
return this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
}
var data = JSON.parse(file.contents.toString());
let result: string;
try {
result = nunjucks.render(template, data);
} catch(err) {
return callback(new gutil.PluginError(PLUGIN_NAME, err, {fileName: template}));
}
var basename = path.basename(file.path),
stylename = basename.substr(0, basename.length-path.extname(basename).length);
var resultFile = file.clone({contents: false});
resultFile.path = gutil.replaceExtension(file.path, ".html");
resultFile.contents = new Buffer(result);
callback(null, resultFile);
});
};
开发者ID:kaa,项目名称:gulp-nunjucks-template,代码行数:37,代码来源:index.ts
示例5: getName
/// <reference path="../typings/tsd.d.ts" />
import * as Hapi from 'hapi';
import * as nunjucks from 'nunjucks';
// configure nunjucks to read from the dist directory
nunjucks.configure('./dist');
// create a server with a host and port
const server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 8000
});
function getName(request) {
// default values
let name = {
fname: 'Michael',
lname: 'Chavez'
};
// split path params
let nameParts = request.params.name ? request.params.name.split('/') : [];
// order of precedence
// 1. path param
// 2. query param
// 3. default value
name.fname = (nameParts[0] || request.query.fname) ||
name.fname;
name.lname = (nameParts[1] || request.query.lname) ||
name.lname;
开发者ID:bigbassroller,项目名称:isomorphic-ts,代码行数:31,代码来源:index.ts
示例6: debug
debug('isDev', isDev);
debug('srcPath', srcPath);
debug('Views path', views);
// Express
const app: express.Express = express();
// view engine setup
app.engine('njk', nunjucks.render);
app.set('views', views);
app.set('view engine', 'njk');
const env = nunjucks.configure(views, {
autoescape: true,
watch: isDev,
noCache: isDev,
express: app,
});
// Configure localization
localization.configure({
locales: ['en-US', 'es'],
defaultLocale: 'en-US',
cookie: 'lang',
queryParameter: 'lang',
directory: `${ROOT}/src/locales`,
autoReload: isDev,
api: {
'__': 't', // now req.__ becomes req.t
'__n': 'tn' // and req.__n can be called as req.tn
}
开发者ID:melxx001,项目名称:simple-nodejs-typescript-starter,代码行数:31,代码来源:server.ts
示例7:
import { swagger, segments, routes, hasIds } from './swagger';
import * as nunjucks from 'nunjucks';
import * as fs from 'fs';
import { actions } from './action';
import * as _ from 'lodash';
import { renderModel } from './render';
const pascalCase = (str: string): string => {
return _.upperFirst(_.camelCase(str));
}
const env = nunjucks.configure('views', {
autoescape: false,
trimBlocks: true,
lstripBlocks: true,
});
env.addFilter('pascalCase', pascalCase);
const format = (str: string): string => {
let indent = 0;
let result = '';
for(const line of str.replace(/\s+$/mg, '').replace(/\n{2,}/g, '\n').split('\n').map(item => item.trim())) {
if (line == '}') {
indent -= 4;
}
result += _.repeat(' ', indent) + line + '\n';
if (line == '{') {
indent += 4;
}
}
开发者ID:tylerlong,项目名称:rc-swagger-codegen,代码行数:31,代码来源:index.ts
示例8: require
import * as nunjucks from 'nunjucks';
import * as pathlib from 'path';
import { File } from '../core';
const gulp = require('gulp');
const packageInfo = require('../package.json');
const CWD = pathlib.normalize(`${process.cwd()}/..`);
const DOCS = `${CWD}/docs`;
nunjucks.configure(DOCS);
/**
* Build documentation
* @param {string} path
*/
async function buildDocs(path: string) {
let files = await File.readDirectory(path);
for (let file of files) {
file = `${path}/${file}`;
let stats = await File.getStats(file);
if (stats.isDirectory()) {
await buildDocs(file);
} else if (stats.isFile() && pathlib.extname(file) == '.tpl') {
await File.create(
`${pathlib.dirname(file)}/${pathlib.basename(file, '.tpl')}.html`,
nunjucks.renderString(await File.read(file), packageInfo)
);
}
}
}
开发者ID:chen-framework,项目名称:chen,代码行数:31,代码来源:gulp.ts
示例9: enableFor
enableFor (app: express.Express) {
app.set('view engine', 'njk')
const nunjucksEnv = nunjucks.configure([
path.join(__dirname, '..', '..', 'views'),
path.join(__dirname, '..', '..', 'common'),
path.join(__dirname, '..', '..', 'features'),
path.join(__dirname, '..', '..', 'views', 'macro'),
path.join(__dirname, '..', '..', '..', '..', 'node_modules', '@hmcts', 'cmc-common-frontend', 'macros')
], {
autoescape: true,
throwOnUndefined: true,
watch: this.developmentMode,
express: app
})
app.use((req, res, next) => {
res.locals.pagePath = req.path
next()
})
require('numeral/locales/en-gb')
numeral.locale('en-gb')
numeral.defaultFormat(NUMBER_FORMAT)
moment.locale('en-gb')
nunjucksEnv.addGlobal('asset_paths', appAssetPaths)
nunjucksEnv.addGlobal('serviceName', 'Money Claims')
nunjucksEnv.addGlobal('supportEmailAddress', config.get('secrets.cmc.staff-email'))
nunjucksEnv.addGlobal('development', this.developmentMode)
nunjucksEnv.addGlobal('govuk_template_version', packageDotJson.dependencies.govuk_template_jinja)
nunjucksEnv.addGlobal('gaTrackingId', config.get<string>('analytics.gaTrackingId'))
nunjucksEnv.addGlobal('t', (key: string, options?: TranslationOptions): string => this.i18next.t(key, options))
nunjucksEnv.addFilter('date', dateFilter)
nunjucksEnv.addFilter('inputDate', dateInputFilter)
nunjucksEnv.addFilter('addDays', addDaysFilter)
nunjucksEnv.addFilter('pennies2pounds', convertToPoundsFilter)
nunjucksEnv.addFilter('monthIncrement', monthIncrementFilter)
nunjucksEnv.addFilter('numeral', numeralFilter)
nunjucksEnv.addFilter('yesNo', yesNoFilter)
nunjucksEnv.addGlobal('isAfter4pm', isAfter4pm)
nunjucksEnv.addGlobal('betaFeedbackSurveyUrl', config.get('feedback.feedbackSurvey.url'))
nunjucksEnv.addGlobal('reportProblemSurveyUrl', config.get('feedback.reportProblemSurvey.url'))
nunjucksEnv.addGlobal('customerSurveyUrl', config.get('feedback.serviceSurvey.url'))
nunjucksEnv.addGlobal('featureToggles', this.convertPropertiesToBoolean(config.get('featureToggles')))
nunjucksEnv.addGlobal('RejectAllOfClaimOption', RejectAllOfClaimOption)
nunjucksEnv.addGlobal('AlreadyPaid', AlreadyPaid)
nunjucksEnv.addGlobal('DefendantPaymentType', DefendantPaymentType)
nunjucksEnv.addGlobal('DefendantPaymentOption', DefendantPaymentOption)
nunjucksEnv.addGlobal('PaymentType', PaymentType)
nunjucksEnv.addGlobal('InterestRateOption', InterestRateOption)
nunjucksEnv.addGlobal('SignatureType', SignatureType)
nunjucksEnv.addGlobal('ResponseType', ResponseType)
nunjucksEnv.addGlobal('MadeBy', MadeBy)
nunjucksEnv.addGlobal('CountyCourtJudgmentType', CountyCourtJudgmentType)
nunjucksEnv.addGlobal('YesNoOption', YesNoOption)
nunjucksEnv.addGlobal('EvidenceType', EvidenceType)
nunjucksEnv.addGlobal('StatementType', StatementType)
nunjucksEnv.addGlobal('NotEligibleReason', NotEligibleReason)
nunjucksEnv.addGlobal('InterestType', InterestType)
nunjucksEnv.addGlobal('InterestTypeOption', InterestTypeOption)
nunjucksEnv.addGlobal('InterestDateType', InterestDateType)
nunjucksEnv.addGlobal('InterestEndDateOption', InterestEndDateOption)
nunjucksEnv.addGlobal('FormaliseOption', FormaliseOption)
nunjucksEnv.addGlobal('ClaimantResponseType', ClaimantResponseType)
nunjucksEnv.addGlobal('ResidenceType', ResidenceType)
nunjucksEnv.addGlobal('PaymentSchedule', PaymentSchedule)
nunjucksEnv.addGlobal('UnemploymentType', UnemploymentType)
nunjucksEnv.addGlobal('BankAccountType', BankAccountType)
nunjucksEnv.addGlobal('ClaimStatus', ClaimStatus)
nunjucksEnv.addGlobal('AppPaths', AppPaths)
nunjucksEnv.addGlobal('ClaimantResponsePaths', ClaimantResponsePaths)
nunjucksEnv.addGlobal('DashboardPaths', DashboardPaths)
nunjucksEnv.addGlobal('CCJPaths', CCJPaths)
nunjucksEnv.addGlobal('StatePaidPaths', StatePaidPaths)
nunjucksEnv.addGlobal('ResponsePaths', ResponsePaths)
nunjucksEnv.addGlobal('MediationPaths', MediationPaths)
nunjucksEnv.addGlobal('PartAdmissionPaths', PartAdmissionPaths)
nunjucksEnv.addGlobal('FullRejectionPaths', FullRejectionPaths)
nunjucksEnv.addGlobal('DirectionsQuestionnairePaths', DirectionsQuestionnairePaths)
nunjucksEnv.addGlobal('TestingSupportPaths', TestingSupportPaths)
nunjucksEnv.addGlobal('SettlementAgreementPaths', SettlementAgreementPaths)
nunjucksEnv.addGlobal('HowMuchPaidClaimantOption', HowMuchPaidClaimantOption)
nunjucksEnv.addGlobal('MonthlyIncomeType', MonthlyIncomeType)
nunjucksEnv.addGlobal('MonthlyExpenseType', MonthlyExpenseType)
nunjucksEnv.addGlobal('PriorityDebtType', PriorityDebtType)
nunjucksEnv.addGlobal('Service', Service)
nunjucksEnv.addGlobal('DisabilityStatus', Disability)
nunjucksEnv.addGlobal('cookieText', `GOV.UK uses cookies make the site simpler. <a href="${AppPaths.cookiesPage.uri}">Find out more about cookies</a>`)
nunjucksEnv.addGlobal('serviceName', `Money Claims`)
nunjucksEnv.addGlobal('headingVisible', true)
nunjucksEnv.addGlobal('DecisionType', DecisionType)
nunjucksEnv.addGlobal('PartyType', PartyType)
nunjucksEnv.addGlobal('IncomeExpenseSchedule', IncomeExpenseSchedule)
nunjucksEnv.addGlobal('FreeMediationOption', FreeMediationOption)
}
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:99,代码来源:index.ts
注:本文中的nunjucks.configure函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论