-----------------------------------------------------------------------------
-- |
-- Module      :  Static.Resources.Import
-- Copyright   :  (c) Scrive 2012
-- License     :  BSD-style (see the LICENSE file in the distribution)
--
-- Maintainer  :  mariusz@scrive.com
-- Stability   :  development
-- Portability :  portable
--
-- Generating list of imports to be embedded in html
--


module Static.Resources.Import (
                               -- * Importing
                                 htmlImportList
                                 ) where

import Static.Resources.Types
import Data.List

-- | Generating import list for HTML resources
htmlImportList :: String -> ResourceSetsForImport -> String
htmlImportList s (ResourceSetsForImport rss) =
    case find (\r -> (name $ set r) == s) rss of
        Just rs -> importListForCss rs ++ "\n" ++ importListForJS rs
        Nothing -> "<!-- Resource set " ++ s ++ " is missing -->\n"

importListForCss :: ResourceSetForImport -> String
importListForCss rs = concatMap cssGen (cssFiles rs)
    where cssGen fn = "<link rel='stylesheet' type='text/css' href='/"++fn++"' media='screen'/>\n"


importListForJS :: ResourceSetForImport -> String
importListForJS rs = concatMap jsGen (jsFiles rs)
    where jsGen fn = "<script src='/"++fn++"' type='text/javascript'></script>\n"