1.0.2 • Published 6 years ago

salak-view v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

salak-view

NPM version build status Test coverage David deps NPM download

View for SalakJS 2.0, support for multiple view engine, using consolidate under the hood.

Install

$ npm install --save salak-view

Supported Template Engines

If you want to use ejs engine, You need install ejs.

$ npm install --save ejs

Usage

Config

In plugin:

module.exports = {
  plugin: [
    {
      name: 'view',
      package: 'salak-view'
    }
  ],
  view: {
    dirname: 'view',
    extension: 'html',
    engine: '',
    cache: true,
    map: null,
    config: {}
  }
}

Use in Context or Controller

user/controller/login.js

const { Controller } = require('salak')

class Login extends Controller {
  async actionIndex () {
    await this.render('login')
  }
}

module.exports = Login

API

Options

  • dirname {String} directory for storing views, default view
  • extension {String} template file extension, default html
  • engine {String} Engine for parse file, default
  • cache {Boolean} Cache things for reading the file content, default app.env === 'production'
  • map {Object} map a file extension to an engine, like { html: 'ejs' }, default null
  • config {Object} pass to view engine, default {}

Controller.prototype.render(viewName, locals, module)

The function which register on or

  • name {String} view filename
  • locals {Object} variables for view
  • module {String} the view located in, default: the current module

@return will set view html to response.body

context.render(), but module default app.root

Controller.prototype.renderView(viewName, locals, module)

params is the same as Controller.prototype.renderView

@return complied html string,if file ext is html and !options.engine && !map, will return fs.createReadStrem(file)

context.renderView(), but module default app.root

License

MIT

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago