Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import (
"os"
"path/filepath"

_ "github.com/cznic/ql/driver"
"github.com/gernest/qlstore"
"github.com/gernest/utron/config"
"github.com/gernest/utron/controller"
"github.com/gernest/utron/logger"
"github.com/gernest/utron/models"
"github.com/gernest/utron/router"
"github.com/gernest/utron/view"
"github.com/gorilla/sessions"
// load ql drier
_ "github.com/cznic/ql/driver"
"github.com/joesteel2010/utron/config"
"github.com/joesteel2010/utron/controller"
"github.com/joesteel2010/utron/logger"
"github.com/joesteel2010/utron/models"
"github.com/joesteel2010/utron/router"
"github.com/joesteel2010/utron/view"
)

//StaticServerFunc is a function that returns the static assetsfiles server.
Expand Down Expand Up @@ -104,8 +103,7 @@ func (a *App) init() error {
return err
}
a.Config = appConfig

views, err := view.NewSimpleView(appConfig.ViewsDir)
views, err := view.GetView(appConfig.ViewsDir)
if err != nil {
return err
}
Expand All @@ -129,7 +127,7 @@ func (a *App) init() error {
}

a.Router.Options = a.options()
a.Router.LoadRoutes(a.ConfigPath) // Load a routes file if available.
a.Router.LoadRoutes(a.ConfigPath) // Load a routes file if available.
a.isInit = true

// In case the StaticDir is specified in the Config file, register
Expand Down
4 changes: 2 additions & 2 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strings"
"testing"

"github.com/gernest/utron/config"
"github.com/gernest/utron/controller"
"github.com/joesteel2010/utron/config"
"github.com/joesteel2010/utron/controller"
)

const notFoundMsg = "nothing"
Expand Down
8 changes: 4 additions & 4 deletions base/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"io"
"net/http"

"github.com/gernest/utron/config"
"github.com/gernest/utron/logger"
"github.com/gernest/utron/models"
"github.com/gernest/utron/view"
"github.com/joesteel2010/utron/config"
"github.com/joesteel2010/utron/logger"
"github.com/joesteel2010/utron/models"
"github.com/joesteel2010/utron/view"
"github.com/gorilla/context"
"github.com/gorilla/mux"
"github.com/gorilla/sessions"
Expand Down
2 changes: 1 addition & 1 deletion base/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http/httptest"
"testing"

"github.com/gernest/utron/config"
"github.com/joesteel2010/utron/config"
"github.com/gorilla/mux"
)

Expand Down
2 changes: 1 addition & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"reflect"

"github.com/gernest/utron/base"
"github.com/joesteel2010/utron/base"
)

// Controller is an interface for utron controllers
Expand Down
2 changes: 1 addition & 1 deletion controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"

"github.com/gernest/utron/base"
"github.com/joesteel2010/utron/base"
)

func TestBaseController(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion flash/flash.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/gob"
"errors"

"github.com/gernest/utron/base"
"github.com/joesteel2010/utron/base"
)

const (
Expand Down
6 changes: 3 additions & 3 deletions flash/flash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"os"
"testing"

"github.com/gernest/utron/controller"
"github.com/gernest/utron/logger"
"github.com/gernest/utron/router"
"github.com/joesteel2010/utron/controller"
"github.com/joesteel2010/utron/logger"
"github.com/joesteel2010/utron/router"
"github.com/gorilla/sessions"
)

Expand Down
2 changes: 1 addition & 1 deletion models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"reflect"
"strings"

"github.com/gernest/utron/config"
"github.com/joesteel2010/utron/config"
"github.com/jinzhu/gorm"

// support mysql, sqlite3 and postgresql
Expand Down
2 changes: 1 addition & 1 deletion router/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package router
import (
"net/http"

"github.com/gernest/utron/base"
"github.com/joesteel2010/utron/base"
)

//MiddlewareType is the kind of middleware. Utron support middleware with
Expand Down
4 changes: 2 additions & 2 deletions router/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"net/http/httptest"
"testing"

"github.com/gernest/utron/base"
"github.com/gernest/utron/controller"
"github.com/joesteel2010/utron/base"
"github.com/joesteel2010/utron/controller"
"github.com/gorilla/context"
)

Expand Down
12 changes: 6 additions & 6 deletions router/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import (

"github.com/BurntSushi/toml"
"github.com/gernest/ita"
"github.com/gernest/utron/base"
"github.com/gernest/utron/config"
"github.com/gernest/utron/controller"
"github.com/gernest/utron/logger"
"github.com/gernest/utron/models"
"github.com/gernest/utron/view"
"github.com/gorilla/mux"
"github.com/gorilla/sessions"
"github.com/hashicorp/hcl"
"github.com/joesteel2010/utron/base"
"github.com/joesteel2010/utron/config"
"github.com/joesteel2010/utron/controller"
"github.com/joesteel2010/utron/logger"
"github.com/joesteel2010/utron/models"
"github.com/joesteel2010/utron/view"
"github.com/justinas/alice"
"gopkg.in/yaml.v2"
)
Expand Down
2 changes: 1 addition & 1 deletion router/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"

"github.com/gernest/utron/controller"
"github.com/joesteel2010/utron/controller"
)

var msg = "gernest"
Expand Down
2 changes: 1 addition & 1 deletion utron.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package utron

import "github.com/gernest/utron/app"
import "utron/app"

// NewApp creates a new bare-bone utron application. To use the MVC components, you should call
// the Init method before serving requests.
Expand Down
18 changes: 16 additions & 2 deletions view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,32 @@ import (
"strings"
)

var viewFactory ViewFactoryFunc = func(viewDir string) (View, error) {
return NewSimpleView(viewDir)
}

// View is an interface for rendering templates.
type View interface {
Render(out io.Writer, name string, data interface{}) error
}

// Type to allow is to override the default view implementation
type ViewFactoryFunc func(viewDir string) (View, error)

// SimpleView implements View interface, but based on golang templates.
type SimpleView struct {
viewDir string
tmpl *template.Template
}

func SetViewFactory(viewFactoryImpl ViewFactoryFunc) {
viewFactory = viewFactoryImpl
}

func GetView(viewDir string) (View, error) {
return viewFactory(viewDir)
}

//NewSimpleView returns a SimpleView with templates loaded from viewDir
func NewSimpleView(viewDir string) (View, error) {
info, err := os.Stat(viewDir)
Expand All @@ -43,7 +58,6 @@ func NewSimpleView(viewDir string) (View, error) {
// should be relative to the dir. That is, if dir is foo, you don't have to refer to
// foo/bar.tpl, instead just use bar.tpl
func (s *SimpleView) load(dir string) (View, error) {

// supported is the list of file extensions that will be parsed as templates
supported := map[string]bool{".tpl": true, ".html": true, ".tmpl": true}

Expand Down Expand Up @@ -80,7 +94,7 @@ func (s *SimpleView) load(dir string) (View, error) {
name = strings.TrimSuffix(name, extension) // remove extension

t := s.tmpl.New(name)

if _, err = t.Parse(string(data)); err != nil {
return err
}
Expand Down