mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Merge pull request #682 from corebreaker/django-include-problem
Resolve Django `include` and `extends` tags problem Former-commit-id: 4d6a7f45292f8e49abe45f91891c852b0eebb5f8
This commit is contained in:
commit
197cb0e9b0
|
@ -1,10 +1,12 @@
|
||||||
package view
|
package view
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
stdPath "path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -22,6 +24,35 @@ type (
|
||||||
FilterFunction func(in *Value, param *Value) (out *Value, err *Error)
|
FilterFunction func(in *Value, param *Value) (out *Value, err *Error)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type tDjangoAssetLoader struct {
|
||||||
|
baseDir string
|
||||||
|
assetGet func(name string) ([]byte, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Abs calculates the path to a given template. Whenever a path must be resolved
|
||||||
|
// due to an import from another template, the base equals the parent template's path.
|
||||||
|
func (dal *tDjangoAssetLoader) Abs(base, name string) string {
|
||||||
|
if stdPath.IsAbs(name) {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
return stdPath.Join(dal.baseDir, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns an io.Reader where the template's content can be read from.
|
||||||
|
func (dal *tDjangoAssetLoader) Get(path string) (io.Reader, error) {
|
||||||
|
if stdPath.IsAbs(path) {
|
||||||
|
path = path[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := dal.assetGet(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return bytes.NewBuffer(res), nil
|
||||||
|
}
|
||||||
|
|
||||||
// DjangoEngine contains the amber view engine structure.
|
// DjangoEngine contains the amber view engine structure.
|
||||||
type DjangoEngine struct {
|
type DjangoEngine struct {
|
||||||
// files configuration
|
// files configuration
|
||||||
|
@ -199,12 +230,8 @@ func (s *DjangoEngine) loadAssets() error {
|
||||||
virtualDirectory, virtualExtension := s.directory, s.extension
|
virtualDirectory, virtualExtension := s.directory, s.extension
|
||||||
assetFn, namesFn := s.assetFn, s.namesFn
|
assetFn, namesFn := s.assetFn, s.namesFn
|
||||||
|
|
||||||
var templateErr error
|
// Make a file set with a template loader based on asset function
|
||||||
/*fsLoader, err := pongo2.NewLocalFileSystemLoader(virtualDirectory)
|
set := pongo2.NewSet("", &tDjangoAssetLoader{baseDir: s.directory, assetGet: s.assetFn})
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}*/
|
|
||||||
set := pongo2.NewSet("", pongo2.DefaultLoader)
|
|
||||||
set.Globals = getPongoContext(s.globals)
|
set.Globals = getPongoContext(s.globals)
|
||||||
|
|
||||||
// set the filters
|
// set the filters
|
||||||
|
@ -225,6 +252,8 @@ func (s *DjangoEngine) loadAssets() error {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
var templateErr error
|
||||||
|
|
||||||
names := namesFn()
|
names := namesFn()
|
||||||
for _, path := range names {
|
for _, path := range names {
|
||||||
if !strings.HasPrefix(path, virtualDirectory) {
|
if !strings.HasPrefix(path, virtualDirectory) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user