bundle

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2018 License: BSD-3-Clause Imports: 6 Imported by: 4

Documentation

Overview

Package bundle defines interfaces for bundling together the files produced by a run of a generator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectContentType

func DetectContentType(file BundledFile) (string, error)

DetectContentType returns the content type of the given bundled file. Always returns a content type if no error occurred.

func WriteToFileSystem

func WriteToFileSystem(bundle Bundle, dir string) error

WriteToFileSystem writes all the bundled files to the file system, placing them under the given directory.

Types

type Builder

type Builder func(files map[string]BundledFile) Bundle

Builder builds a new bundle for the given map of files.

type Bundle

type Bundle interface {
	// LookupFile returns the file with the given filename, if any.
	LookupFile(name string) (BundledFile, bool)

	// Files returns all the bundled files.
	Files() []BundledFile
}

Bundle represents a bundle of the files produced by a generator run.

func EmptyBundle

func EmptyBundle() Bundle

EmptyBundle returns an empty bundle of files.

func InMemoryBundle

func InMemoryBundle(files map[string]BundledFile) Bundle

InMemoryBundle returns an in-memory bundle of files.

func WithFile

func WithFile(bundle Bundle, file BundledFile) Bundle

WithFile returns a new file bundle that includes the given file.

type BundledFile

type BundledFile interface {
	// Filename is the name of the file.
	Filename() string

	// Reader returns a new reader for reading the contents of the file. Callers must close the
	// reader when done using it.
	Reader() io.ReadCloser

	// FileKind returns the kind of the file in the bundle.
	Kind() FileKind
}

BundledFile represents a single file added into a bundle.

func FileFromBytes

func FileFromBytes(filename string, kind FileKind, content []byte) BundledFile

FileFromBytes returns a BundledFile from byte data.

func FileFromString

func FileFromString(filename string, kind FileKind, content string) BundledFile

FileFromString returns a BundledFile from byte data.

type Bundler

type Bundler interface {
	// AddFile adds a file to the bundle.
	AddFile(file BundledFile)

	// Freeze freezes the collected files into a bundle.
	Freeze(builder Builder) Bundle
}

Bundler presents an interface for collecting files for a bundle.

func NewBundler

func NewBundler() Bundler

NewBundler returns a new file bundler.

type FileKind

type FileKind string

FileKind defines the various supported kinds of files.

const (
	// Script indicates a produced script file, which will be loaded via a <script> tag.
	Script FileKind = "script"

	// Stylesheet indicates a produced stylesheet, which will be loaded via a <link> tag.
	Stylesheet FileKind = "stylesheet"

	// Resource indicates a produced resource, which will not be loaded directly.
	Resource FileKind = "resource"
)

Jump to

Keyboard shortcuts

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