views

package
v0.0.0-...-d26cf96 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2014 License: BSD-2-Clause-Views Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CanEdit   = func(ctx dingo.Context) bool { return true }
	EmptyTmpl = "<!doctype html><head><title>Template Doesn't Exist</title></head>" +
		"<body>This template doesn't exist, or hasn't been created yet.</body></html>"
	UseCodeMirror = true
	CodeMirrorJS  = "/js/libs/codemirror.js"
	CodeMirrorCSS = "/css/codemirror.css"
)
View Source
var (
	Path = "./templates"
)

Functions

func Add

func Add(key string, v View)

Add adds a new view to the internal views collection.

func AddEditableView

func AddEditableView(name string)

AddEditableView adds a view to be edited.

func AddTmplFunc

func AddTmplFunc(name string, fn interface{})

AddTmplFunc adds a function to the templates functions.

func EditHandler

func EditHandler(ctx dingo.Context)

EditHandler is a dingo.Handler that edits/saves a given template.

func Execute

func Execute(ctx dingo.Context, key string, data interface{})

Execute invokes a view by key.

func NewTmpl

func NewTmpl(name string) *template.Template

NewTmpl returns a new template

Types

type CoreView

type CoreView struct {
	IsStale              bool
	ViewName             string
	Associated, Extended []string
}

CoreView is the most base view, implementing basic functionality.

func (*CoreView) Associate

func (v *CoreView) Associate(names ...string) error

Associate relates the given view names with this view.

func (*CoreView) Associations

func (v *CoreView) Associations() (views []View)

Associations returns this views associated views.

func (*CoreView) Extends

func (v *CoreView) Extends(name string) error

Extend creates a parent/child relationship with the given view name.

func (*CoreView) Extensions

func (v *CoreView) Extensions() (views []View)

Extensions returns the list of extended views.

func (*CoreView) Name

func (v *CoreView) Name() string

Name returns the views name.

type EditTemplateData

type EditTemplateData struct {
	URL, DoneURL, DingoVer       string
	HasViews, IsAction, WasSaved bool
	Error                        error
	Views                        map[string]View
	Content                      []byte
	Stylesheets, Scripts         string
}

EditTemplateData is data passed to the edit template.

type EditableView

type EditableView struct {
	View
	// contains filtered or unexported fields
}

Editable view wraps a view to be edited.

func (*EditableView) Execute

func (e *EditableView) Execute(ctx dingo.Context, data interface{}) error

Execute invokes the editor for the wrapped view.

type FileView

type FileView struct {
	TemplateView
}

FileView reads a template from the file system.

func (*FileView) Save

func (v *FileView) Save(ctx dingo.Context, data []byte) error

Save writes the new template data to the file system

type TemplateData

type TemplateData func(ctx dingo.Context, name string) (*template.Template, []byte, error)

TemplateData is a func that returns data for a given template used during rendering.

type TemplateView

type TemplateView struct {
	CoreView
	Tmpl     *template.Template
	TmplData TemplateData
	Bytes    []byte
}

Base template, extends core template.

func (*TemplateView) Data

func (v *TemplateView) Data(ctx dingo.Context) []byte

Data returns the templates raw data, used for both rendering and editing.

func (*TemplateView) Execute

func (v *TemplateView) Execute(ctx dingo.Context, data interface{}) error

Execute writes the template to the response using the given data.

func (*TemplateView) Init

func (v *TemplateView) Init(name string, dataFunc TemplateData)

Init initializes the template

func (*TemplateView) Reload

func (v *TemplateView) Reload(ctx dingo.Context) error

Reload reloads the template.

type View

type View interface {
	Name() string
	Associate(names ...string) error
	Associations() []View
	Extends(name string) error
	Extensions() []View
	Data(ctx dingo.Context) []byte
	Reload(ctx dingo.Context) error
	Save(ctx dingo.Context, data []byte) error
	Execute(ctx dingo.Context, data interface{}) error
}

View wraps a template and provides CRUD operations, and nesting of templates.

func Editable

func Editable(view View) View

Editable returns a wrapped view that can be edited.

func Get

func Get(key string) View

Get finds a view by it's key.

func New

func New(location string) View

New returns a new FileView

func NewEditable

func NewEditable(location string) View

NewEditable returns a new editable FileView

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL