motto and otto for nodejs module syntax in custom filters
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -5,9 +5,9 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/ddliu/motto"
|
||||
"github.com/flosch/pongo2"
|
||||
_ "github.com/flosch/pongo2-addons"
|
||||
"github.com/robertkrimen/otto"
|
||||
_ "github.com/robertkrimen/otto/underscore"
|
||||
)
|
||||
|
||||
@@ -29,6 +29,7 @@ func MarkdownFilter(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pong
|
||||
nil
|
||||
}
|
||||
|
||||
// RegisterFilters reads a directory and register filters from files within it
|
||||
func RegisterFilters(dir string) {
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
@@ -38,14 +39,17 @@ func RegisterFilters(dir string) {
|
||||
if !f.IsDir() {
|
||||
switch path.Ext(f.Name()) {
|
||||
case ".js":
|
||||
fileBase := strings.TrimSuffix(f.Name(), ".js")
|
||||
jsFile := dir + "/" + f.Name()
|
||||
Log.Debugf("trying to register filter from: %s", jsFile)
|
||||
jsStr, err := ioutil.ReadFile(jsFile)
|
||||
if err != nil {
|
||||
Log.Panicf("could not read '%s': %s", jsFile, err)
|
||||
}
|
||||
vm := otto.New()
|
||||
fn, err := vm.Run(jsStr)
|
||||
/*
|
||||
jsStr, err := ioutil.ReadFile(jsFile)
|
||||
if err != nil {
|
||||
Log.Panicf("could not read '%s': %s", jsFile, err)
|
||||
}
|
||||
*/
|
||||
vm := motto.New()
|
||||
fn, err := vm.Run(jsFile)
|
||||
if err != nil {
|
||||
Log.Panicf("error in javascript vm for '%s': %s", jsFile, err)
|
||||
}
|
||||
@@ -54,7 +58,7 @@ func RegisterFilters(dir string) {
|
||||
}
|
||||
|
||||
err = pongo2.RegisterFilter(
|
||||
strings.TrimSuffix(f.Name(), ".js"),
|
||||
fileBase,
|
||||
func(in, param *pongo2.Value) (out *pongo2.Value, erro *pongo2.Error) {
|
||||
thisObj, _ := vm.Object("({})")
|
||||
if currentContext != nil {
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
// RequestFn will make a web request and returns map[string]interface form pongo2
|
||||
func RequestFn(url *pongo2.Value, args ...*pongo2.Value) *pongo2.Value {
|
||||
u := url.String()
|
||||
Log.Notice("requesting url via GET %s", u)
|
||||
Log.Noticef("requesting url via GET %s", u)
|
||||
|
||||
resp, err := http.Get(u)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user