pongo2rethink

package module
v0.0.0-...-3e6a030 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

README

pongo2rethink - a rethinkdb backend for pongo2 templates

GoDoc

Install
go get -u github.com/pandemicsyn/pongo2rethink
Depends on
  • github.com/flosch/pongo2
  • github.com/dancannon/gorethink

Documentation

Overview

pongo2rethink provides a pongo2.TemplateLoader that pulls template's from RethinkDB.

	opts := pongo2rethink.Opts{
  TableName: "templates",
  Prefix:    "randocustomer",
  Session:   s.rethink,
 }
 dbtmpl := pongo2.NewSet("assetfs", pongo2rethink.NewPongoLoader(&opts))
 res := dbtmpl.RenderTemplateFile("templates/tiny.pongo", pongo2.Context{"name": "florian"})

It also has some additional methods to let you manage your templates. You can also use it with vanilla go templates via something like github.com/unrolled/render by using the RethinkLoader ala:

opts := pongo2rethink.Opts{
 TableName: "templates",
 Prefix:    "randocustomer",
 Session:   s.rethink,
}
l := pongo2rethink.NewRethinkLoader(&opts))
render.New(render.Options{
 Asset: l.GetTemplateBytes,
 AssetNames: l.GetTemplateNames,
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindTemplates

func FindTemplates(path, pattern string) ([]string, error)

FindTemplates walks a given path and returns a slice of files that match the provided shell pattern.

func NewPongoLoader

func NewPongoLoader(opts *Opts) pongo2.TemplateLoader

Types

type Opts

type Opts struct {
	TableName string           //Table to use
	Prefix    string           //optional prefix to apply to all paths
	Session   *rethink.Session //The rethink session that should be used
	Owner     string           //What if anything to put in an "owner" field, empty string is omitted
}

type RethinkTemplateLoader

type RethinkTemplateLoader struct {
	// contains filtered or unexported fields
}

func NewRethinkLoader

func NewRethinkLoader(opts *Opts) *RethinkTemplateLoader

func (*RethinkTemplateLoader) Abs

func (t *RethinkTemplateLoader) Abs(base, name string) string

Abs returns the absolute path and is used by pongo2

func (*RethinkTemplateLoader) Get

func (t *RethinkTemplateLoader) Get(path string) (io.Reader, error)

Get returns io.Reader of a template contents from rethink and is used by pongo2

func (*RethinkTemplateLoader) GetTemplate

func (t *RethinkTemplateLoader) GetTemplate(path string) (*Template, error)

GetTemplate returns a Template object from rethink

func (*RethinkTemplateLoader) GetTemplateBytes

func (t *RethinkTemplateLoader) GetTemplateBytes(path string) ([]byte, error)

GetTemplateBytes retrieves a templates byte from rethink

func (*RethinkTemplateLoader) GetTemplateNames

func (t *RethinkTemplateLoader) GetTemplateNames() []string

GetTemplateNames retrieves a list of all current template names from rethink It goes against standards in that it ONLY PRINTS ERRORS if it encounters any, to satisfy github.com/unrolled/render AssetNames()

func (*RethinkTemplateLoader) GetTemplateString

func (t *RethinkTemplateLoader) GetTemplateString(path string) (string, error)

GetTemplateString retrieves a templates string from rethink

func (*RethinkTemplateLoader) LoadTemplate

func (t *RethinkTemplateLoader) LoadTemplate(template Template) error

LoadTemplate inserts a given Template into rethink

func (*RethinkTemplateLoader) LoadTemplateFromFile

func (t *RethinkTemplateLoader) LoadTemplateFromFile(path string) (err error)

LoadTemplateFromFile reads a given file and loads it into rethink

func (*RethinkTemplateLoader) LoadTemplatesFromDir

func (t *RethinkTemplateLoader) LoadTemplatesFromDir(dir, pattern string) error

LoadTemplatesFromDir walks a given path recursively searching for the provided shell pattern and loads any encountered templates into rethink

type Template

type Template struct {
	Name  string
	Data  string
	Owner string `gorethink:",omitempty"`
}

Jump to

Keyboard shortcuts

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