当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript hbs.registerPartials函数代码示例

本文整理汇总了TypeScript中hbs.registerPartials函数的典型用法代码示例。如果您正苦于以下问题:TypeScript registerPartials函数的具体用法?TypeScript registerPartials怎么用?TypeScript registerPartials使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了registerPartials函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: bootstrap

async function bootstrap(): Promise<void> {
    const app = await NestFactory.create(M1cr0blogModule, { cors: true })

    // Set up static content rendering
    app.useStaticAssets(__dirname + '/static')
    app.setBaseViewsDir(__dirname + '/views')
    app.setViewEngine('hbs')
    hbs.registerPartials(__dirname + '/views/partials')
    hbs.registerHelper('unlessEquals', function(arg1, arg2, options) {
        //@ts-ignore
        return (arg1 != arg2) ? options.fn(this) : options.inverse(this);
    })
    hbs.registerHelper('replace', function(needle: string, newstr: string, options) {
        //@ts-ignore
        return options.fn(this).replace(needle, newstr)
    })

    // Set up Swagger
    const options = new DocumentBuilder()
        .setTitle('M1cr0blog API')
        .setDescription('Backend REST API for m1cr0man\'s blog')
        .setVersion('1.0')
        .addTag('Users', 'User management system')
        .addBearerAuth()
        .build()
    const document = SwaggerModule.createDocument(app, options)
    SwaggerModule.setup('api/swagger', app, document)

    await app.listen(3000)
}
开发者ID:m1cr0man,项目名称:m1cr0blog,代码行数:30,代码来源:index.ts

示例2: require

let expressHandlebars: any = require('hbs');

log('loading controllers');
import { Controllers } from './controllers/index';

// setup express
log('setup express');
let app: express.Express = express();
app.use(logger());

// setup express to have static resource folders
app.use('', express.static(__dirname + '/../client'));
app.use('/vendor', express.static(__dirname + '/../../node_modules'));

// configure handlebars as the view engine
expressHandlebars.registerPartials(__dirname + '/views');
// configure express to use handlebars as the view engine
app.set('view engine', 'hbs');
// change express default where to look for views on the server
app.set('views', __dirname + '/views');

// load UX and API controllers
log('initialize controllers');
let controllers: Controllers = new Controllers(app);
controllers.init();

// setup ssl self hosting (use the same certs from browsersync)
let httpsOptions: https.ServerOptions = {
  cert: fs.readFileSync(__dirname + '/../../node_modules/browser-sync/lib/server/certs/server.crt'),
  key: fs.readFileSync(__dirname + '/../../node_modules/browser-sync/lib/server/certs/server.key')
};
开发者ID:andrewconnell,项目名称:pres-ng2-officeaddin,代码行数:31,代码来源:server.ts

示例3: require

// express handlebars
const hbs = require('hbs');
// Portfolio data
const  data = require(join(__dirname, '/..', '/database.json'));
// express instance
const server =  express();
// Handlebars views path
const views = `${__dirname}/front-end/views/`;
// Handlebars partials path
const partials = `${__dirname}/front-end/partials/`;

const staticFiles = join(__dirname, '/..', '/public/')

// Register Handlebars Partials
hbs.registerPartials(partials);

// Set Handlebars as view engine
server.set('view engine', 'hbs');
// Register Handlebars views
server.set('views', views);
// Static files
server.use(express.static(staticFiles));


// Main Route
server.get('/', (req, res) => res.render('index', data));
// Redurect all other request to Main route
server.all('*', (req, res)=>res.redirect('/'));
// Init server
server.listen( 
开发者ID:santi6291,项目名称:Portfolio,代码行数:30,代码来源:index.ts


注:本文中的hbs.registerPartials函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。