Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/vendor/github.com/CloudyKit/jet/loader.go
akuma06 5991a21818 First batch of changes for the refactor (#1078)
* First batch of changes for the refactor

Added the support of gin in routes and other services/utils
Begining implementation of JetHTML

* Remove os folder

* Move scrapers to own repo

* Second batch of changes

All .jet.html are the working templates.
You can now test this PR, the index Page and upload works. If you want to complete the other html templates, you're welcome

* Move captcha to util

* Move uploadService to utils

* Use govalidator instead of regex

* Third batch of changes

All the front end should as previously.
I also fixed some minor things unrelated to the refactor (mostly style issues on static pages)
Now errors can be accessed by importing the "errors" helpers and using the `yield errors(name="xxx")` command in templates.
Same for infos.
Templates are now more hierarchized with a base template "base.jet.html" which is extended depending on the context in "index_site" or "index_admin" layouts. Those layouts are extended than in every pages.
Other helpers are captcha to render a captcha `yield captcha(captchaid="xxx")`
And also csrf, with the command `yield csrf_field()`
To translate, you don't have anymore to do `call $.T "xxx"`, you just have to do `T("xxx")`.

Pages for the website part are in folders in the folder "templates/site". Pages for the admin part are in "templates/admin". Layouts are separated in "templates/layouts". Helpers and menu are in "templates/layouts/helpers" and "templates/layouts/menu". Error pages should be put in "templates/errors"

* Added test on templates

When adding a new template, you have to tell to template_test.go, the context of the new template (if it doesn't use the common context)

* Panel admin works

Now the templating part should work. The PR can now be fully tested.

I think we should push the templating PR  and do the routes/controllers/removal of services in another branch. So we know that this one is functional

* Updated dependencies

* Fixed test for modelhelper

* Fix testing for commentlist

* Fix travis :')

* Just renamed router and removed network

* Applying same SEO fix

* Update form_validator.go

* Added back regexp package
2017-06-28 21:42:38 +10:00

95 lignes
3 Kio
Go

// Copyright 2016 José Santos <henrique_1609@me.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package jet
import (
"errors"
"io"
"os"
"path"
"path/filepath"
)
// Loader is a minimal interface required for loading templates.
type Loader interface {
// Open opens the underlying reader with template content.
Open(name string) (io.ReadCloser, error)
// Exists checks for template existence and returns full path.
Exists(name string) (string, bool)
}
// hasAddPath is an optional Loader interface. Most probably useful for OS file system only, thus unexported.
type hasAddPath interface {
AddPath(path string)
}
// hasAddGopathPath is an optional Loader interface. Most probably useful for OS file system only, thus unexported.
type hasAddGopathPath interface {
AddGopathPath(path string)
}
// OSFileSystemLoader implements Loader interface using OS file system (os.File).
type OSFileSystemLoader struct {
dirs []string
}
// NewOSFileSystemLoader returns an initialized OSFileSystemLoader.
func NewOSFileSystemLoader(paths ...string) *OSFileSystemLoader {
return &OSFileSystemLoader{dirs: paths}
}
// Open opens a file from OS file system.
func (l *OSFileSystemLoader) Open(name string) (io.ReadCloser, error) {
return os.Open(name)
}
// Exists checks if the template name exists by walking the list of template paths
// returns string with the full path of the template and bool true if the template file was found
func (l *OSFileSystemLoader) Exists(name string) (string, bool) {
for i := 0; i < len(l.dirs); i++ {
fileName := path.Join(l.dirs[i], name)
if _, err := os.Stat(fileName); err == nil {
return fileName, true
}
}
return "", false
}
// AddPath adds the path to the internal list of paths searched when loading templates.
func (l *OSFileSystemLoader) AddPath(path string) {
l.dirs = append(l.dirs, path)
}
// AddGopathPath adds a path located in the GOPATH.
// Example: l.AddGopathPath("github.com/CloudyKit/jet/example/views")
func (l *OSFileSystemLoader) AddGopathPath(path string) {
paths := filepath.SplitList(os.Getenv("GOPATH"))
for i := 0; i < len(paths); i++ {
var err error
path, err = filepath.Abs(filepath.Join(paths[i], "src", path))
if err != nil {
panic(errors.New("Can't add this path err: " + err.Error()))
}
if fstats, err := os.Stat(path); os.IsNotExist(err) == false && fstats.IsDir() {
l.AddPath(path)
return
}
}
if fstats, err := os.Stat(path); os.IsNotExist(err) == false && fstats.IsDir() {
l.AddPath(path)
}
}