livepkg

package module
v0.0.0-...-ec98257 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2015 License: Unlicense Imports: 21 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownImport = errors.New("unknown import format")

Functions

This section is empty.

Types

type Bundle

type Bundle struct {
	// Root is the filesystem used to load/reload sources
	Root http.FileSystem
	// Main is the root files that are used to find rest of the files
	Main []string
	// contains filtered or unexported fields
}

Bundle is a collection of source files that can be bundled and/or reloaded

func NewBundle

func NewBundle(root http.FileSystem, main ...string) *Bundle

NewBundle returns a empty bundle

func (*Bundle) All

func (b *Bundle) All() []*Source

All returns the list of sorted sources Do not modify this list!

func (*Bundle) ByExt

func (b *Bundle) ByExt(ext string) []*Source

All returns sorted sources with specified ext Do not modify this list!

func (*Bundle) Load

func (b *Bundle) Load(path string) (*Source, error)

Load loads a source from path

func (*Bundle) MergedByExt

func (b *Bundle) MergedByExt(ext string) []byte

MergedByExt bundles files together into bytes by ext

func (*Bundle) Reload

func (b *Bundle) Reload() ([]*Change, error)

Reload reloads the content from Root and returns the list of changes and all errors that occurred

func (*Bundle) ReloadSource

func (b *Bundle) ReloadSource(prev *Source) (changed bool, next *Source, err error)

ReloadSource reloads the base file and returns a new Source file in next. If file doesn't exist any more it will return nil as next

func (*Bundle) ServeFile

func (b *Bundle) ServeFile(w http.ResponseWriter, r *http.Request)

ServeFile serves file from cache or Root

type Change

type Change struct {
	Prev *Source `json:"prev"` // Prev is nil if file was added
	Next *Source `json:"next"` // Next is nil if file was deleted
	Deps bool    `json:"deps"` // Deps is true if dependencies changed
}

Change shows info about a source file change

type Errors

type Errors []error

Errors is a wrapper for multiple errors

func (Errors) Error

func (errs Errors) Error() string

Error is for implementing error interface

func (Errors) Nilify

func (errs Errors) Nilify() error

Nilify returns nil, if there are no errors

type Server

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

Server implements a live reloading server for JS

func NewServer

func NewServer(root http.FileSystem, dev bool, main ...string) *Server

NewServer returns a new server

func (*Server) ServeHTTP

func (server *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Server

type Source

type Source struct {
	Path string   `json:"path"` // absolute path for file
	Deps []string `json:"deps"` // list of absolute paths
	Ext  string   `json:"ext"`  // file extension

	ModTime     time.Time `json:"modified"`    // last modified time
	ContentType string    `json:"contentType"` // file content-type

	Content   []byte `json:"-"` // original content on disk
	Processed []byte `json:"-"` // pre-processed content in some cases
}

Source represents a single source file

func SortSources

func SortSources(sources []*Source) ([]*Source, error)

SortSources optimistically sorts items by dependencies in case of cycles those items will be unordered

func (*Source) ReadFrom

func (source *Source) ReadFrom(r io.Reader) error

ReadFrom reads content and deps from io.Reader

func (*Source) Tag

func (src *Source) Tag() template.HTML

Tag returns html tag that can be included in html

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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