Safe Haskell | None |
---|
herringbone is a Haskell library for compiling and serving web assets.
It aims to make it dead simple to create a Middleware
or
Application
which deals with all of your static assets, including
preprocessing for languages like Fay, CoffeeScript, Sass, and LESS.
It takes most of its inspiration from the Ruby library, Sprockets, hence the name.
Example:
import Web.Herringbone fay, sass :: PP hb = Herringbone hb = herringbone ( addSourceDir "assets" . setDestDir "compiled_assets" . addPreprocessors [fay, sass] ) -- You can now access assets programmatically asset <- findAsset hb (fromJust . makeLogicalPath $ ["application.js"]) -- Or serve them with a Wai application app = toApplication hb
- data Herringbone = Herringbone {}
- herringbone :: ConfigBuilder -> Herringbone
- type ConfigBuilder = Herringbone -> Herringbone
- addSourceDir :: FilePath -> ConfigBuilder
- setDestDir :: FilePath -> ConfigBuilder
- addPreprocessors :: [PP] -> ConfigBuilder
- defaultHerringbone :: Herringbone
- data LogicalPath
- fromLogicalPath :: LogicalPath -> [Text]
- toFilePath :: LogicalPath -> FilePath
- data Asset = Asset {}
- findAsset :: Herringbone -> LogicalPath -> IO (Either AssetError Asset)
- data PP = PP {
- ppExtension :: Text
- ppAction :: ByteString -> IO (Either CompileError ByteString)
- data PPs
- data AssetError
- type CompileError = ByteString
- toApplication :: Herringbone -> Application
Creating a Herringbone
data Herringbone Source
The 'main' datatype in this library. Just a container for the
configuration. All of the important functions will take a Herringbone
as
their first argument.
herringbone :: ConfigBuilder -> HerringboneSource
Preferred way of creating Herringbone
instances.
type ConfigBuilder = Herringbone -> HerringboneSource
addSourceDir :: FilePath -> ConfigBuilderSource
Adds a directory to the list of source directories.
setDestDir :: FilePath -> ConfigBuilderSource
Sets the destination directory. Note that this will overwrite the destination directory if one is already set.
addPreprocessors :: [PP] -> ConfigBuilderSource
Add the preprocessors in the list to the preprocessor collection.
Assets
data LogicalPath Source
All assets in Herringbone are referenced by their logical path. This is the path to an asset, relative to any of the source directories.
fromLogicalPath :: LogicalPath -> [Text]Source
A preprocessed asset. Any function that returns this will already have done the preprocessing (if necessary).
Asset | |
|
findAsset :: Herringbone -> LogicalPath -> IO (Either AssetError Asset)Source
Preprocessors
A preprocessor something which is run on the asset before it is served. Preprocessors are run when a file extension matches the preprocessor extension. For example, if you have a preprocessor for "coffee" files, you request "application.js", and there is a file named "application.js.coffee", Herringbone will run the coffee preprocessor on that file and serve you the result.
You can add more preprocessors by adding more file extensions; "application.js.coffee.erb" will be preprocessed first by "erb", then by "coffee" (assuming you have registered preprocessors for those files).
PP | |
|
data AssetError Source
type CompileError = ByteStringSource
A string which should contain information about why an asset failed to compile.
WAI
toApplication :: Herringbone -> ApplicationSource
Convert a Herringbone
to a WAI Application
.