HStringTemplate-0.8.7: StringTemplate implementation in Haskell.

Safe HaskellNone
LanguageHaskell98

Text.StringTemplate.Base

Synopsis

Documentation

data StringTemplate a #

A String with "holes" in it. StringTemplates may be composed of any Stringable type, which at the moment includes Strings, ByteStrings, PrettyPrinter Docs, and Endo Strings, which are actually of type ShowS. When a StringTemplate is composed of a type, its internals are as well, so it is, so to speak "turtles all the way down."

Constructors

STMP 

Fields

Instances
Stringable a => SEType a (StringTemplate a) # 
Instance details

Defined in Text.StringTemplate.Renderf

class Show a => StringTemplateShows a where #

The StringTemplateShows class should be instantiated for all types that are directly displayed in a StringTemplate, but take an optional format string. Each such type must have an appropriate ToSElem method defined as well.

Methods

stringTemplateShow :: a -> String #

Defaults to show.

stringTemplateFormattedShow :: String -> a -> String #

Defaults to _ a -> stringTemplateShow a

Instances
StringTemplateShows Double # 
Instance details

Defined in Text.StringTemplate.Instances

StringTemplateShows Float # 
Instance details

Defined in Text.StringTemplate.Instances

StringTemplateShows ZonedTime # 
Instance details

Defined in Text.StringTemplate.Instances

StringTemplateShows LocalTime # 
Instance details

Defined in Text.StringTemplate.Instances

StringTemplateShows TimeOfDay # 
Instance details

Defined in Text.StringTemplate.Instances

StringTemplateShows TimeZone # 
Instance details

Defined in Text.StringTemplate.Instances

StringTemplateShows UTCTime # 
Instance details

Defined in Text.StringTemplate.Instances

StringTemplateShows Day # 
Instance details

Defined in Text.StringTemplate.Instances

class ToSElem a where #

The ToSElem class should be instantiated for all types that can be inserted as attributes into a StringTemplate.

Minimal complete definition

toSElem

Methods

toSElem :: Stringable b => a -> SElem b #

toSElemList :: Stringable b => [a] -> SElem b #

Instances
ToSElem Bool # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => Bool -> SElem b #

toSElemList :: Stringable b => [Bool] -> SElem b #

ToSElem Char # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => Char -> SElem b #

toSElemList :: Stringable b => [Char] -> SElem b #

ToSElem Double # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => Double -> SElem b #

toSElemList :: Stringable b => [Double] -> SElem b #

ToSElem Float # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => Float -> SElem b #

toSElemList :: Stringable b => [Float] -> SElem b #

ToSElem Int # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => Int -> SElem b #

toSElemList :: Stringable b => [Int] -> SElem b #

ToSElem Integer # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => Integer -> SElem b #

toSElemList :: Stringable b => [Integer] -> SElem b #

ToSElem () # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => () -> SElem b #

toSElemList :: Stringable b => [()] -> SElem b #

Data a => ToSElem a # 
Instance details

Defined in Text.StringTemplate.GenericStandard

Methods

toSElem :: Stringable b => a -> SElem b #

toSElemList :: Stringable b => [a] -> SElem b #

ToSElem Void # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => Void -> SElem b #

toSElemList :: Stringable b => [Void] -> SElem b #

ToSElem ByteString # 
Instance details

Defined in Text.StringTemplate.Instances

ToSElem ByteString # 
Instance details

Defined in Text.StringTemplate.Instances

ToSElem Text # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => Text -> SElem b #

toSElemList :: Stringable b => [Text] -> SElem b #

ToSElem Text # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => Text -> SElem b #

toSElemList :: Stringable b => [Text] -> SElem b #

ToSElem ZonedTime # 
Instance details

Defined in Text.StringTemplate.Instances

ToSElem LocalTime # 
Instance details

Defined in Text.StringTemplate.Instances

ToSElem TimeOfDay # 
Instance details

Defined in Text.StringTemplate.Instances

ToSElem TimeZone # 
Instance details

Defined in Text.StringTemplate.Instances

ToSElem UTCTime # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => UTCTime -> SElem b #

toSElemList :: Stringable b => [UTCTime] -> SElem b #

ToSElem Day # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => Day -> SElem b #

toSElemList :: Stringable b => [Day] -> SElem b #

ToSElem a => ToSElem [a] # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => [a] -> SElem b #

toSElemList :: Stringable b => [[a]] -> SElem b #

ToSElem a => ToSElem (Maybe a) # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => Maybe a -> SElem b #

toSElemList :: Stringable b => [Maybe a] -> SElem b #

(Integral a, Show a) => ToSElem (Ratio a) # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => Ratio a -> SElem b #

toSElemList :: Stringable b => [Ratio a] -> SElem b #

(ToSElem a, Foldable t) => ToSElem (t a) # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => t a -> SElem b #

toSElemList :: Stringable b => [t a] -> SElem b #

(ToSElem a, ToSElem b) => ToSElem (a, b) # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b0 => (a, b) -> SElem b0 #

toSElemList :: Stringable b0 => [(a, b)] -> SElem b0 #

(ToSElem a, Ix i) => ToSElem (Array i a) # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => Array i a -> SElem b #

toSElemList :: Stringable b => [Array i a] -> SElem b #

ToSElem a => ToSElem (Map String a) # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b => Map String a -> SElem b #

toSElemList :: Stringable b => [Map String a] -> SElem b #

(ToSElem a, ToSElem b, ToSElem c) => ToSElem (a, b, c) # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b0 => (a, b, c) -> SElem b0 #

toSElemList :: Stringable b0 => [(a, b, c)] -> SElem b0 #

(ToSElem a, ToSElem b, ToSElem c, ToSElem d) => ToSElem (a, b, c, d) # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b0 => (a, b, c, d) -> SElem b0 #

toSElemList :: Stringable b0 => [(a, b, c, d)] -> SElem b0 #

(ToSElem a, ToSElem b, ToSElem c, ToSElem d, ToSElem e) => ToSElem (a, b, c, d, e) # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b0 => (a, b, c, d, e) -> SElem b0 #

toSElemList :: Stringable b0 => [(a, b, c, d, e)] -> SElem b0 #

(ToSElem a, ToSElem b, ToSElem c, ToSElem d, ToSElem e, ToSElem f) => ToSElem (a, b, c, d, e, f) # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b0 => (a, b, c, d, e, f) -> SElem b0 #

toSElemList :: Stringable b0 => [(a, b, c, d, e, f)] -> SElem b0 #

(ToSElem a, ToSElem b, ToSElem c, ToSElem d, ToSElem e, ToSElem f, ToSElem g) => ToSElem (a, b, c, d, e, f, g) # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b0 => (a, b, c, d, e, f, g) -> SElem b0 #

toSElemList :: Stringable b0 => [(a, b, c, d, e, f, g)] -> SElem b0 #

(ToSElem a, ToSElem b, ToSElem c, ToSElem d, ToSElem e, ToSElem f, ToSElem g, ToSElem h) => ToSElem (a, b, c, d, e, f, g, h) # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b0 => (a, b, c, d, e, f, g, h) -> SElem b0 #

toSElemList :: Stringable b0 => [(a, b, c, d, e, f, g, h)] -> SElem b0 #

(ToSElem a, ToSElem b, ToSElem c, ToSElem d, ToSElem e, ToSElem f, ToSElem g, ToSElem h, ToSElem i) => ToSElem (a, b, c, d, e, f, g, h, i) # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b0 => (a, b, c, d, e, f, g, h, i) -> SElem b0 #

toSElemList :: Stringable b0 => [(a, b, c, d, e, f, g, h, i)] -> SElem b0 #

(ToSElem a, ToSElem b, ToSElem c, ToSElem d, ToSElem e, ToSElem f, ToSElem g, ToSElem h, ToSElem i, ToSElem j) => ToSElem (a, b, c, d, e, f, g, h, i, j) # 
Instance details

Defined in Text.StringTemplate.Instances

Methods

toSElem :: Stringable b0 => (a, b, c, d, e, f, g, h, i, j) -> SElem b0 #

toSElemList :: Stringable b0 => [(a, b, c, d, e, f, g, h, i, j)] -> SElem b0 #

type STGroup a = String -> StFirst (StringTemplate a) #

A function that generates StringTemplates. This is conceptually a query function into a "group" of StringTemplates.

class Monoid a => Stringable a where #

The Stringable class should be instantiated with care. Generally, the provided instances should be enough for anything.

Minimal complete definition

stFromString, stToString

Methods

stFromString :: String -> a #

stFromByteString :: ByteString -> a #

stFromText :: Text -> a #

stToString :: a -> String #

mconcatMap :: [b] -> (b -> a) -> a #

Defaults to mconcatMap m k = foldr (mappend . k) mempty m

mintercalate :: a -> [a] -> a #

Defaults to (mconcat .) . intersperse

mlabel :: a -> a -> a #

Defaults to mlabel x y = mconcat [x, stFromString "[", y, stFromString "]"]

Instances
Stringable String # 
Instance details

Defined in Text.StringTemplate.Classes

Stringable ByteString # 
Instance details

Defined in Text.StringTemplate.Classes

Stringable ByteString # 
Instance details

Defined in Text.StringTemplate.Classes

Stringable Builder # 
Instance details

Defined in Text.StringTemplate.Classes

Stringable Text # 
Instance details

Defined in Text.StringTemplate.Classes

Stringable Text # 
Instance details

Defined in Text.StringTemplate.Classes

Stringable Doc # 
Instance details

Defined in Text.StringTemplate.Classes

Stringable Builder # 
Instance details

Defined in Text.StringTemplate.Classes

Stringable (Endo String) # 
Instance details

Defined in Text.StringTemplate.Classes

stShowsToSE :: (StringTemplateShows a, Stringable b) => a -> SElem b #

This method should be used to create ToSElem instances for types defining a custom formatted show function.

toString :: StringTemplate String -> String #

Renders a StringTemplate to a String.

toPPDoc :: StringTemplate Doc -> Doc #

Renders a StringTemplate to a Doc.

render :: Stringable a => StringTemplate a -> a #

Generic render function for a StringTemplate of any type.

newSTMP :: Stringable a => String -> StringTemplate a #

Parses a String to produce a StringTemplate, with '$'s as delimiters. It is constructed with a stub group that cannot look up other templates.

newAngleSTMP :: Stringable a => String -> StringTemplate a #

Parses a String to produce a StringTemplate, delimited by angle brackets. It is constructed with a stub group that cannot look up other templates.

getStringTemplate :: Stringable a => String -> STGroup a -> Maybe (StringTemplate a) #

Queries an String Template Group and returns Just the appropriate StringTemplate if it exists, otherwise, Nothing.

getStringTemplate' :: Stringable a => String -> STGroup a -> Maybe (StringTemplate a) #

As with getStringTemplate but never inlined, so appropriate for use with volatile template groups.

setAttribute :: (ToSElem a, Stringable b) => String -> a -> StringTemplate b -> StringTemplate b #

Yields a StringTemplate with the appropriate attribute set. If the attribute already exists, it is appended to a list.

setManyAttrib :: (ToSElem a, Stringable b) => [(String, a)] -> StringTemplate b -> StringTemplate b #

Yields a StringTemplate with the appropriate attributes set. If any attribute already exists, it is appended to a list.

setNativeAttribute :: Stringable b => String -> b -> StringTemplate b -> StringTemplate b #

Yields a StringTemplate with the appropriate attribute set. If the attribute already exists, it is appended to a list. This will not translate the attribute through any intermediate representation, so is more efficient when, e.g. setting attributes that are large bytestrings in a bytestring template.

setManyNativeAttrib :: Stringable b => [(String, b)] -> StringTemplate b -> StringTemplate b #

Yields a StringTemplate with the appropriate attributes set. If any attribute already exists, it is appended to a list. Attributes are added natively, which may provide efficiency gains.

withContext :: (ToSElem a, Stringable b) => StringTemplate b -> a -> StringTemplate b #

Replaces the attributes of a StringTemplate with those described in the second argument. If the argument does not yield a set of named attributes but only a single one, that attribute is named, as a default, "it".

optInsertTmpl :: [(String, String)] -> StringTemplate a -> StringTemplate a #

Adds a set of global options to a single template

setEncoder :: Stringable a => (a -> a) -> StringTemplate a -> StringTemplate a #

Sets an encoding function of a template that all values are rendered with. For example one useful encoder would be stringToHtmlString. All attributes will be encoded once and only once.

paddedTrans :: a -> [[a]] -> [[a]] #

data SEnv a #

Constructors

SEnv 

Fields

parseSTMP :: Stringable a => (Char, Char) -> String -> Either String (SEnv a -> a) #

dumpAttribs :: Stringable a => StringTemplate a #

A special template that simply dumps the values of all the attributes set in it. This may be made available to any template as a function by adding it to its group. I.e. myNewGroup = addSuperGroup myGroup $ groupStringTemplates [("dumpAttribs", dumpAttribs)]

checkTemplate :: Stringable a => StringTemplate a -> (Maybe String, Maybe [String], Maybe [String]) #

Returns a tuple of three Maybes. The first is set if there is a parse error in the template. The next is set to a list of attributes that have not been set, or Nothing if all attributes are set. The last is set to a list of invoked templates that cannot be looked up, or Nothing if all invoked templates can be found. Note that this check is shallow -- i.e. missing attributes and templates are only caught in the top level template, not any invoked subtemplate.

checkTemplateDeep :: (Stringable a, NFData a) => StringTemplate a -> ([(String, String)], [String], [String]) #

Returns a tuple of three lists. The first is of templates with parse errors, and their errors. The next is of missing attributes, and the last is of missing templates. If there are no errors, then all lists will be empty. This check is performed recursively.

parseSTMPNames :: (Char, Char) -> String -> Either ParseError ([String], [String], [String]) #

Gets all quasiquoted names, normal names & templates used in a given template. Must be passed a pair of chars denoting the delimeters to be used.