Giter Club home page Giter Club logo

salak-view's Introduction

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

salak-view's People

Contributors

wengeek avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.