bundler

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

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

Go to latest
Published: Feb 9, 2016 License: MIT Imports: 11 Imported by: 2

README

bundler

Build Status Go Report Card GoDoc

bundler is a generic file combiner of any type of files using a custom left and right delimiter, i.e. css or js files using a lexer. bundler can be used via command line or as a library.

Why

I was writing an asset pipeline and needed a way to combine the files using some sort of include format and so why not a flexible library to handle that and can be used elsewhere.

Best Part

uses a Lexer to process the files, with necessary components exposed to use as you wish.

Installation

Use go get

go get github.com/go-playground/bundler/cmd/bundler

or to update

go get -u github.com/go-playground/bundler/cmd/bundler

Then import lars package into your code.

import "github.com/go-playground/bundler"
Command Line Use

bundler -h
Usage of ./bundler:
  -i string
    	File or DIR to bundle files for; DIR will bundle all files within the DIR recursivly.
  -ignore string
    	Regexp for files/dirs we should ignore i.e. \.gitignore; only used when -i option is a DIR
  -ld string
    	the Left Delimiter for file includes, if not specified default to //include(. (default "//include(")
  -o string
    	Output filename, or if using a DIR in -i option the suffix, otherwise will be be the filename with appended hash of file contents.
  -rd string
    	the Right Delimiter for file includes, if not specified default to ). (default ")")

Documentation

Index

Constants

View Source
const (
	DefaultLeftDelim  = "//include("
	DefaultRightDelim = ")"
)

Contant bundler variables

View Source
const (
	ItemError itemType = iota // error occurred; value is text of error
	ItemEOF
	ItemLeftDelim  // left action delimiter
	ItemRightDelim // right action delimiter
	ItemText       // plain text
	ItemFile       // file keyword
)

Lexed Item Types

Variables

This section is empty.

Functions

func Bundle

func Bundle(r io.Reader, w io.Writer, dir string, relativeToDir bool, relativeDir string, leftDelim string, rightDelim string) error

Bundle combines the given input and writes it out to the provided writer removing delims from the combined files

func BundleKeepDelims

func BundleKeepDelims(r io.Reader, w io.Writer, dir string, relativeToDir bool, relativeDir string, leftDelim string, rightDelim string) error

BundleKeepDelims combines the given input and writes it out to the provided writer but unlike Bundle() keeps the delims in the combined data

Types

type Item

type Item struct {
	Type itemType // The type of this item.
	Pos  Pos      // The starting position, in bytes, of this item in the input string.
	Val  string   // The value of this item.
}

Item represents a token or text string returned from the scanner.

type Lexer

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

Lexer holds the state of the scanner.

func NewLexer

func NewLexer(id string, r io.Reader, leftDelim string, rightDelim string) (*Lexer, error)

NewLexer creates a new scanner for the input string and returns it for use

func (*Lexer) NextItem

func (l *Lexer) NextItem() Item

NextItem returns the next item from the input.

type Pos

type Pos int

Pos represents a byte position in the original input text from which this template was parsed.

type ProcessedFile

type ProcessedFile struct {
	OriginalFilename string
	NewFilename      string
}

ProcessedFile contains the information of the processed files.

func BundleDir

func BundleDir(dirname string, suffix string, relativeToDir bool, relativeDir string, leftDelim string, rightDelim string, ignoreRegexp *regexp.Regexp) ([]*ProcessedFile, error)

BundleDir bundles an entire directory recursively and returns an array of filenames and if an error occurred processing suffix will be appended to filenames, if blank a hash of file contents will be added

func BundleFile

func BundleFile(path string, output string, relativeToDir bool, relativeDir string, leftDelim string, rightDelim string) (*ProcessedFile, error)

BundleFile bundles a single file on disk and returns the filename and if an error occurred processing

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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