Преглед на файлове

Allow Lua plugins to inject all templates

master
Simon Ser преди 4 години
родител
ревизия
733304c88f
No known key found for this signature in database GPG ключ ID: FDE7BE0E88F5E48
променени са 2 файла, в които са добавени 9 реда и са изтрити 2 реда
  1. +1
    -1
      README.md
  2. +8
    -1
      plugin_lua.go

+ 1
- 1
README.md Целия файл

@@ -36,7 +36,7 @@ The entry point is at `plugins/<name>/main.lua`.
API:

* `koushin.on_render(name, f)`: prior to rendering the template `name`, call
`f` with the template data
`f` with the template data (the special name `*` matches all templates)
* `koushin.set_filter(name, f)`: set a template function
* `koushin.set_route(method, path, f)`: register a new HTTP route, `f` will be
called with the HTTP context


+ 8
- 1
plugin_lua.go Целия файл

@@ -68,7 +68,7 @@ func (p *luaPlugin) setRoute(l *lua.LState) int {
return 0
}

func (p *luaPlugin) Inject(name string, data interface{}) error {
func (p *luaPlugin) inject(name string, data interface{}) error {
f, ok := p.renderCallbacks[name]
if !ok {
return nil
@@ -86,6 +86,13 @@ func (p *luaPlugin) Inject(name string, data interface{}) error {
return nil
}

func (p *luaPlugin) Inject(name string, data interface{}) error {
if err := p.inject("*", data); err != nil {
return err
}
return p.inject(name, data)
}

func (p *luaPlugin) LoadTemplate(t *template.Template) error {
t.Funcs(p.filters)



Зареждане…
Отказ
Запис