Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- hbSourceDir :: Herringbone -> FilePath
- hbDestDir :: Herringbone -> FilePath
- hbPPs :: Herringbone -> PPs
- hbVerbose :: Herringbone -> Bool
- data HerringboneSettings = HerringboneSettings {}
- module Web.Herringbone.Internal.Configuration
- data LogicalPath
- makeLogicalPath :: [Text] -> Maybe LogicalPath
- unsafeMakeLogicalPath :: [Text] -> LogicalPath
- fromLogicalPath :: LogicalPath -> [Text]
- toFilePath :: LogicalPath -> FilePath
- data Asset = Asset {}
- assetContent :: Asset -> IO ByteString
- findAsset :: Herringbone -> LogicalPath -> IO (Either AssetError Asset)
- precompile :: Herringbone -> IO [(LogicalPath, AssetError)]
- data PP = PP {
- ppName :: Text
- ppConsumes :: Text
- ppProduces :: Text
- ppAction :: PPAction
- data PPs
- data AssetError
- type CompileError = ByteString
- data PPReader = PPReader {}
- data PPM a
Creating a Herringbone
data Herringbone Source
The 'main' datatype in this library. All of the important functions
will take a Herringbone
as their first argument.
hbSourceDir :: Herringbone -> FilePath Source
The directory where Herringbone will look when searching for assets.
hbDestDir :: Herringbone -> FilePath Source
The directory to place assets in after compilation.
hbPPs :: Herringbone -> PPs Source
The collection of preprocessors that will be used when preprocessing assets.
hbVerbose :: Herringbone -> Bool Source
True iff the Herringbone
has the verbose setting enabled.
data HerringboneSettings Source
Contains configuration.
HerringboneSettings | |
|
Assets
data LogicalPath Source
All assets in Herringbone are referenced by their logical path. This is the path to an asset, relative to the source directory.
makeLogicalPath :: [Text] -> Maybe LogicalPath Source
Create a LogicalPath from a list of path segments. For example,
["data", "dogs.txt"]
would map to data/dogs.txt (relative to the
source directory). This returns Nothing if the path would be unsafe (that
is, if it contains ".."), to prevent directory traversal attacks.
unsafeMakeLogicalPath :: [Text] -> LogicalPath Source
Create a LogicalPath without checking any of the values.
fromLogicalPath :: LogicalPath -> [Text] Source
toFilePath :: LogicalPath -> FilePath Source
A preprocessed asset. Any function that returns this will already have done the preprocessing (if necessary).
Asset | |
|
assetContent :: Asset -> IO ByteString Source
findAsset :: Herringbone -> LogicalPath -> IO (Either AssetError Asset) Source
The most important function in this library. Attempts to find the asset
referenced by the given LogicalPath
, compiles it if necessary (based on
file modification time), and returns it to you as an Asset
(or an
AssetError
, if something went wrong).
precompile :: Herringbone -> IO [(LogicalPath, AssetError)] Source
Precompiles all assets, returning a list of the logical paths of assets
that failed to compile (if any) together with AssetError
values describing
what went wrong.
Preprocessors
A preprocessor something which is run on the asset before it is served. Preprocessors are run when a file matches its rule. For example, if you have a preprocessor which takes "coffee" files and emits "js" files, there is a file named "application.coffee", and you request "application.js", Herringbone will run the coffee preprocessor on "application.coffee" and serve you the result.
PP | |
|
A collection of preprocessors. This can store many preprocessors which produce files with the same extension, but may not store more than one preprocessor which consumes files of a particular extension.
data AssetError Source
A value describing an error that occurred while trying to produce an
Asset
.
type CompileError = ByteString Source
A string which should contain information about why an asset failed to compile.
Data which is given to preprocessors on the off-chance that they need it (eg, Fay)
PPReader | |
|