-----------------------------------------------------------------------------
-- |
-- 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 -> unlines [importListForCss rs
                           ,importListForLess rs
                           ,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"

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