HStringTemplateHelpers-0.0.3: Convenience functions and instances for HStringTemplate



Functions I found useful for doing webapps with HStringTemplate.

More usage examples can be found by grep -r "Text.StringTemplate.Helpers" in happs-tutorial, on hackage.



directoryGroupSafer :: Stringable a => FilePath -> IO (STGroup a)Source

calculate the STGroup for a given directory, filtering out files that are probably errors (eg emacs backups)

directoryGroupsSafer :: Stringable a => FilePath -> IO (STDirGroups a)Source

calculate a map of directory groups from a top-level directory

Each directory gives rise to its own groups.

Groups are independent; groups from higher in the directory structure do not have access to groups lower.

The top group has key "." (mnemonic, current directory), other groups have key names of subdirectories, including the starting ., eg "./templates/path/to/subdir"

dirgroupKeys :: Stringable a => STDirGroups a -> [FilePath]Source

The STGroup can't be shown in a useful way because it's a function type, but you can at least show the directories via Data.Map.keys.

renderTemplateGroup :: ToSElem a => STGroup String -> [(String, a)] -> [Char] -> StringSource

Chooses a template from an STGroup, or errors if not found.

Render that template using attrs.

If a template k/v pair is repeated, it appears twice. (Perhaps a clue to buggy behavior?)

Repeated keys could be eliminated by running clean:

 clean = nubBy (\(a1,b1) (a2,b2) -> a1 == a2) . sortBy (\(a1,b1) (a2,b2) -> a1 `compare` a2)

The ToSElem type is probably either String or [String]

render1 :: [(String, String)] -> String -> StringSource

 render1 [("name","Bill")] "Hi, my name is $name$"
 render1 attribs tmpl = render . setManyAttrib attribs . newSTMP $ tmpl

readTmplTuples :: STGroup String -> String -> [(String, String)]Source

 readTmplTuples = readTmplDef [("readTutTuples error","")]

use ST machinery to store key/val configuration information, eg as a configuration hack or in web apps