packages feed

yesod-static-angular-0.1.0: example/StaticSettings.hs

{-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings, CPP #-}

-- | This module contains all the code to manage the angular application (javascript and
-- directives).  During development, the individual javascript and hamlet files will be reloaded
-- from disk on every request and served individually (you can test this out by changing the
-- javascript or hamlet files and reloading your web browser).  When compiling for production, the
-- resources are embedded into the executable.
module StaticSettings where

import Yesod
import Yesod.EmbeddedStatic
import Yesod.EmbeddedStatic.AngularJavascript

#ifdef DEV
#define DEV_BOOL True
#else
#define DEV_BOOL False
#endif

-- | Create the embedded static subsite.  This will create variables:
--
-- > embStatic :: EmbeddedStatic
-- > ng_modules_example_js :: Route EmbeddedStatic
-- > angular_js :: Route EmbeddedStatic
-- > bootstrap_min_css :: Route EmbeddedStatic
--
mkEmbeddedStatic DEV_BOOL "embStatic"
    [ embedNgModule "yesod-example" "ng-modules/example.js" "example/angular-app" return
        -- * The Angular module will be named yesod-example and this must match the ng-app inside the view.
        -- * The javascript code will be located inside the static subsite at ng-modules/example.js
        -- * This file is designed to be compiled from the .cabal file so the path includes
        --   @example@ to be relative to the directory containing the .cabal file.
        -- * The javascript minifier is just `return` so that you can see what the generated
        --   javascript looks like.  Usually you would use `uglifyJs` or `jasmine` from
        --   Yesod.EmbeddedStatic.Generators.  Also, during production the javascript will have
        --   inline dependency injection annotations, both at the top level and the controller
        --   function within my-tabs.js.  This is so that minimizers like uglifyJs which rename
        --   variables do not mess up the dependency injection.

    , concatFilesWith "angular.js" jasmine ["example/static/angular.js"]
        -- This embeds Angular itself.  Note this file is the unminified angular.js so that during
        -- development the unminified code is available.  During production, the code will be minified
        -- with jasmine.  You might consider instead using a CDN; I did not so that this example
        -- works offline.

    , embedFileAt "bootstrap.min.css" "example/static/bootstrap.min.css"
        -- Embeds bootstrap.
    ]