Safe Haskell | None |
---|
Happstack.Server.YUI
- implYUISite :: Happstack m => Text -> Text -> m Response
- data YUISitemap
- sitemap :: Router YUISitemap
- route :: Happstack m => YUISitemap -> RouteT YUISitemap m Response
- showCSSComboURL :: MonadRoute m => (YUISitemap -> URL m) -> [Text] -> m Text
- gridUnit :: Integer -> Integer -> Text
- fontSize :: Integer -> Text
- createNode :: JExpr -> XML -> JExpr
- isYUIFile :: FilePath -> IO Bool
- readYUIFile :: FilePath -> IO ByteString
Combo Handler
Arguments
:: Happstack m | |
=> Text | The URL of your application, e.g. |
-> Text | The path under which to mount the YUI handler, e.g. |
-> m Response |
Mounts a handler for serving YUI. You can use this if you're not
using web-routes
in your own application. See YUISitemap
for the
routes the mounted handler responds to.
data YUISitemap Source
The web-routes
sitemap for the handler that serves up the YUI
bundle. You can embed this in your own sitemap, something like:
data Sitemap = YUI YUISitemap | Home
The version number of the bundled YUI release is included in the routes for sake of cache-busting: the routes all respond with far-future expiration dates.
A PathInfo
instance is provided in case you're using web-routes
without boomerang
. This isn't recommended for production, however,
since the YUI version number is not included in this case.
Constructors
SeedURL |
|
ComboURL |
|
BundleURL [String] |
|
ConfigURL |
|
CSSComboURL |
|
Instances
sitemap :: Router YUISitemapSource
A boomerang
Router
for YUISitemap
. If you embed the
YUISitemap
in your own, you can also embed this router in your own:
import qualified Happstack.Server.YUI as Y sitemap = (rYUI . (lit "yui" </> Y.sitemap)) <> rHome
route :: Happstack m => YUISitemap -> RouteT YUISitemap m ResponseSource
Routes a YUISitemap
to its handler. If you embed YUISitemap
in
your own sitemap, you can use nestURL
in your own routing function
to dispatch to this one:
import qualified Happstack.Server.YUI as Y route (YUI url) = nestURL YUI (Y.route url)
Arguments
:: MonadRoute m | |
=> (YUISitemap -> URL m) | Constructor for |
-> [Text] | Names of CSS modules to include, in order. |
-> m Text |
Helper for building a URL to CSSComboURL
.
do cssURL <- showCSSComboURL YUI ["reset", "base", "fonts", "grids"] unXMLGenT <html> <head> <link href=cssURL rel="stylesheet"/> </head> </html>
CSS utilities
gridUnit :: Integer -> Integer -> TextSource
Gets the class name for the grid unit of the ratio of the two argument integers. YUI doesn't define redundant classes like "6/24" because that is the same as 1/4 and presumably for sake of a smaller CSS file. This helper function handles that for you, though:
>>>
gridUnit 6 24
"yui3-u-1-4">>>
gridUnit 24 24
"yui3-u-1"
The intention is for this function to be used in templates to create values for class attributes, for example with HSP:
<div class=(gridUnit 6 24)> <% someContent %> </div>
fontSize :: Integer -> TextSource
Converts a pixel size to a percentage suitable for use with the CSS fonts module:
>>>
fontSize 16
"123.1%"
Useful in generated stylesheets, for example with HSP:
<style> h1 { font-size: <% fontSize 26 %> } </style>
JS utilities
createNode :: JExpr -> XML -> JExprSource
Creates a YUI Node object from XML created using HSP, for use with
JMacro. This generates less code than using the hsx-jmacro
package to
achieve the same effect, since it goes straight to YUI without directly
using the DOM itself. The first argument is the YUI object that gets
passed to the function you give to YUI().use()
. Such variables are
available in antiquotation splices with JMacro:
do html <- unXMLGenT <p>Hello, World!</p>
ok [jmacro| YUI().use "node" \y ->
y.one("body").append(`(y `createNode
` html`)) |]
Bundle utilities
isYUIFile :: FilePath -> IO BoolSource
Tells if a file is included in the YUI bundle.
>>>
isYUIFile "yui/yui-min.js"
True
readYUIFile :: FilePath -> IO ByteStringSource
Reads the contents of a file included in the YUI bundle.