Koahub.js: Developing the node. JS framework using the ES6/7 feature (2)

Source: Internet
Author: User

} islogin () {console.log (' base islogin '); }}//index controller, Admin/controller/index.controller.jsimport base from "./base.controller"; Export default class        Extends base{Constructor () {super ();    Console.log (' index constructor ');        } index () {super.islogin ();        Super.json ({msg: ' This is a msg '});    Console.log (' index index '); }}

All of the features in ES6/7 can be used in the project, and Babel can be compiled to run stably in the >=0.12.0 node. JS environment.

component 3:Koahub-yilianyun

Yi Yin-yun Printer Interface

Koahub-yilianyun Easy-Connection cloud Printer node interface

Installation
$ NPM Install Koahub-yilianyun
Use with Co-request
var printer = require (' Koahub-yilianyun '); var result = Yield Printer ({"Partner": 914,//User ID (acquired in Central Administration system integration) "Apikey": "3785b31b2c84f3c47e51a6c4481f8a5fc2eea72a",//apikey (acquired in Central Administration system integration) "Machine_code": "3400453726",//Printer terminal number "Msign": " Gn5p5zk585b6 ",//Printer terminal key" Time ": parseint (New Date (). GetTime ()/1000),//current timestamp (server for authentication timeout)" Content ": ' 2222 '//need to transfer print Content data});

Koahub.js--node. JS Web Rapid development framework based on Koa.js platform

Official website: http://js.koahub.com

Component 4:koahub-handlebars

Koahub-handlebars

Koahub Handlebars Templates

Installation
$ NPM Install Koahub-handlebars
Use with KOA
var koa = require (' KOA ');  var HBS = require (' Koahub-handlebars ');  var app = Koa (); Koahub-handlebars is middleware.  ' Use ' it before your want to render a view App.use (Hbs.middleware ({viewPath: __dirname + '/views '}); Render is attached to the KOA context.  Call ' This.render ' on your middleware//to attach rendered HTML to the KOA response body.  App.use (function * () {yield this.render (' index ', {title: ' Koahub-handlebars '}) App.listen (3000);
Registering Helpers

Helpers is registered using the #registerHelper method. Example using the default instance (helper stolen from official handlebars docs:

HBS = require (' Koahub-handlebars '); Hbs.registerhelper (' link ', function (text, url) {text = HBs.  Utils.escapeexpression (text); url = hbs.   Utils.escapeexpression (URL);   var result = ' <a href= ' + URL + ' "> ' + text + ' </a> '; Return to new HBS. Safestring (result);});

Your Helper is and then accessible in any views by using,{{link "Google" "http://google.com"}}

The registerHelper , Utils , and SafeString methods all proxies to an internal handlebars instance. If Passing an alternative instance of handlebars to the middleware Configurator, make sure to doing so before registering Hel Pers via the Koahub-handlebars proxy of the above functions, or just register your helpers directly via your handlebars in Stance.

You can also access the current Koa context in your helper. If you want to has a helper that outputs the current URL, you could write a helper like the following and call it in any Template as {{requestURL}} .

Hbs.registerhelper (' Requesturl ', function () {var url = hbs.templateOptions.data.koa.request.url; return URL;});
Registering partials

The simple-to-register partials is-stick them all-in-a directory, and pass the partialsPath option when generating the mid Dleware. Say your views ./views is in, and your partials is in ./views/partials . Configuring the middleware via

App.use (Hbs.middleware ({viewPath: __dirname + '/views ', Partialspath: __dirname + '/views/partials '}));

Would cause them to be automatically registered. Alternatively, partials one at a time by calling which proxies to the cached handlebars Metho hbs.registerPartial #registerPartial D.

Layouts

Passing with the a layout name would cause all templates to be inserted into the expression of the defaultLayout {{{body}}} layout. This might look like the following.

<! DOCTYPE html>

In the addition to, or alternatively, the Specify a layout to render a template into. Simply specify {{!< layoutName }} somewhere in your template. koahub-handlebars would load your layout from layoutsPath if defined, or from otherwise.

At this time, only a single content block ( {{{body}}} ) is supported.

Options

The plan for Koahub-handlebars are to offer identical functionality as KOA-HBS (eventaully). These options is supported now.

    • viewPath: [Required] full path from which to load templates ( Array|String )

    • handlebars: Pass your own instance of handlebars

    • templateOptions: Hash of handlebars options to pass totemplate()

    • extname: Alter The default template extension (default: ‘.html‘ )

    • partialsPath: Full path to partials directory ( Array|String )

    • defaultLayout: Name of the default layout

    • layoutsPath: Full path to layouts directory ( String )

    • disableCache: Disable template Caching (default: ‘.true‘ )

Locals

Application local Variables ( [this.state](https://github.com/koajs/koa/blob/master/docs/api/context.md#ctxstate) ) is provided to all templates rendered within the application.

App.use (function * (next) {this.state.title = ' My App ';  This.state.email = ' [email protected] '; Yield next;});

The state object is a JavaScript object. The properties added to it would be exposed as local variables within your views.

<title>{{title}}</title> <p>contact: {{email}}</p>
Thanks

Koa-hbs

Differents
    1. Configuration File Incremental Changes

    2. Modify some of the features and the default configuration

    3. ...

Official website: http://js.koahub.com

Koahub.js: Developing the node. JS framework using the ES6/7 feature (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.