goejs

module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2021 License: MIT

README

goejs

Go Report Card codecov GoDoc


provider a powerful template by using ejs in go interpreter. But you should very careful to using it in a high traffic business.

Usage

basic
// default
e := otto.NewDefaultOttoEngine()
got, _ := e.Exec("hello, <%= name %>!", map[string]interface{}{"name": "goejs"}, &contract.Option{
	Debug: true,
})
fmt.Println(got) // hello, goejs!

// config 
e := otto.NewOttoEngine(ejs.NewJsScript(ejs.WithOpenDelimiter("{"), ejs.WithOpenDelimiter("}")))
got, _ := e.Exec("hello, {%= name %}!", map[string]interface{}{"name": "goejs"}, &contract.Option{
	Debug: true,
})
fmt.Println(got) // hello, goejs!
advanced

register js library

// lib.js
if (typeof sum == 'function') { 
	function sum(a, b) {
		return a + b;
	}
}
e := otto.NewOttoEngine(ejs.NewJsScript(ejs.WithOpenDelimiter("{"), ejs.WithOpenDelimiter("}")))
e.RegisterLibrary("./lib.js")
got, _ := e.Exec("{%= sum(1, 2) %}!", nil, nil)
fmt.Println(got) // 3

goja exists error, use otto first.

why use ejs

compare top js template engine on bestofjs, feature(call function in template) in ejs is most powerful.

feature

  • keep most of the features of ejs(js version)
  • support register js library

diff with ejs

  • not support include, partials
  • keep <%_, _%>
  • not use strict
  • remove opts.scope
  • remove opts.async
  • remove opts.client
  • remove opts.destructuredLocals

best Scene

  • admin page
  • config template
  • dev tool

more ejs syntax

https://ejs.co/#docs

Thanks

Directories

Path Synopsis
pkg
ejs
You can use the "packr clean" command to clean up this, and any other packr generated files.
You can use the "packr clean" command to clean up this, and any other packr generated files.
ejs/packrd
You can use the "packr2 clean" command to clean up this, and any other packr generated files.
You can use the "packr2 clean" command to clean up this, and any other packr generated files.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL