-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | representations of a web page -- -- An applicative-based, shared-data representation of a web page. @package web-rep @version 0.12.3.0 -- | Key generators and miscellaneous html utilities. module Web.Rep.Html -- | Convert a link to a css library from text to html. -- --
--   >>> markdown_ Compact Html $ libCss "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
--   "<link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css\">"
--   
libCss :: ByteString -> Markup -- | Convert a link to a js library from text to html. -- --
--   >>> markdown_ Compact Html $ libJs "https://code.jquery.com/jquery-3.3.1.slim.min.js"
--   "<script src=\"https://code.jquery.com/jquery-3.3.1.slim.min.js\"></script>"
--   
libJs :: ByteString -> Markup -- | Common web page input elements, often with bootstrap scaffolding. module Web.Rep.Html.Input -- | something that might exist on a web page and be a front-end input to -- computations. data Input a Input :: a -> Maybe ByteString -> ByteString -> InputType -> Input a -- | underlying value [inputVal] :: Input a -> a -- | label suggestion [inputLabel] :: Input a -> Maybe ByteString -- | name/key/id of the Input [inputId] :: Input a -> ByteString -- | type of html input [inputType] :: Input a -> InputType -- | Various types of web page inputs, encapsulating practical bootstrap -- class functionality data InputType Slider :: [Attr] -> InputType SliderV :: [Attr] -> InputType TextBox :: InputType TextBox' :: InputType TextArea :: Int -> InputType ColorPicker :: InputType ChooseFile :: InputType Dropdown :: [ByteString] -> InputType DropdownMultiple :: [ByteString] -> Char -> InputType DropdownSum :: [ByteString] -> InputType Datalist :: [ByteString] -> ByteString -> InputType Checkbox :: Bool -> InputType Toggle :: Bool -> Maybe ByteString -> InputType Button :: InputType -- | Convert an Input to Markup via a specific printer. markupInput :: (a -> ByteString) -> Input a -> Markup -- | Conversion to a ByteString class ToByteString a -- | Convert a value to a strict ByteString toByteString :: ToByteString a => a -> ByteString -- | Convert a value to a strict ByteString toByteString :: (ToByteString a, Show a) => a -> ByteString instance GHC.Generics.Generic Web.Rep.Html.Input.InputType instance GHC.Show.Show Web.Rep.Html.Input.InputType instance GHC.Classes.Eq Web.Rep.Html.Input.InputType instance GHC.Generics.Generic (Web.Rep.Html.Input.Input a) instance GHC.Show.Show a => GHC.Show.Show (Web.Rep.Html.Input.Input a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Web.Rep.Html.Input.Input a) instance Web.Rep.Html.Input.ToByteString Data.ByteString.Internal.Type.ByteString instance Web.Rep.Html.Input.ToByteString Data.Text.Internal.Text instance Web.Rep.Html.Input.ToByteString GHC.Types.Int instance Web.Rep.Html.Input.ToByteString GHC.Num.Integer.Integer instance Web.Rep.Html.Input.ToByteString GHC.Types.Double instance Web.Rep.Html.Input.ToByteString GHC.Types.Float instance Web.Rep.Html.Input.ToByteString GHC.Types.Bool -- | Representations of a web page, covering Html, CSS & JS artifacts. module Web.Rep.Page -- | Components of a web page. -- -- A web page can take many forms but still have the same underlying -- representation. For example, CSS can be linked to in a separate file, -- or can be inline within html, but still be the same css and have the -- same expected external effect. A Page represents the practical -- components of what makes up a static snapshot of a web page. data Page Page :: Markup -> Markup -> Css -> Js -> Js -> Markup -> Markup -> Page -- | css library links [libsCss] :: Page -> Markup -- | javascript library links [libsJs] :: Page -> Markup -- | css [cssBody] :: Page -> Css -- | javascript with global scope [jsGlobal] :: Page -> Js -- | javascript included within the onLoad function [jsOnLoad] :: Page -> Js -- | html within the header [htmlHeader] :: Page -> Markup -- | body html [htmlBody] :: Page -> Markup -- | Configuration options when rendering a Page. data PageConfig PageConfig :: PageConcerns -> PageStructure -> RenderStyle -> Concerns FilePath -> [FilePath] -> PageConfig [concerns] :: PageConfig -> PageConcerns [structure] :: PageConfig -> PageStructure [renderStyle] :: PageConfig -> RenderStyle [filenames] :: PageConfig -> Concerns FilePath [localdirs] :: PageConfig -> [FilePath] -- | Default configuration is inline ecma and css, separate html header and -- body, minified code, with the suggested filename prefix. defaultPageConfig :: FilePath -> PageConfig -- | A web page typically is composed of some css, javascript and html. -- -- Concerns abstracts this structural feature of a web page. data Concerns a Concerns :: a -> a -> a -> Concerns a [cssConcern] :: Concerns a -> a [jsConcern] :: Concerns a -> a [htmlConcern] :: Concerns a -> a -- | The common file suffixes of the three concerns. suffixes :: Concerns FilePath -- | Create filenames for each Concern element. concernNames :: FilePath -> FilePath -> Concerns FilePath -- | Is the rendering to include all Concerns (typically in a html -- file) or be separated (tyypically into separate files and linked in -- the html file)? data PageConcerns Inline :: PageConcerns Separated :: PageConcerns -- | Various ways that a Html file can be structured. data PageStructure HeaderBody :: PageStructure Headless :: PageStructure Snippet :: PageStructure -- | css as a string. newtype Css Css :: ByteString -> Css [cssByteString] :: Css -> ByteString -- | Render Css as text. renderCss :: RenderStyle -> Css -> ByteString -- | Css snippet for reponsiveness to preferred color-scheme. cssColorScheme :: Css -- | Javascript as string newtype Js Js :: ByteString -> Js [jsByteString] :: Js -> ByteString -- | Add the windows.onload assignment onLoad :: Js -> Js instance GHC.Generics.Generic (Web.Rep.Page.Concerns a) instance Data.Traversable.Traversable Web.Rep.Page.Concerns instance Data.Foldable.Foldable Web.Rep.Page.Concerns instance GHC.Show.Show a => GHC.Show.Show (Web.Rep.Page.Concerns a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Web.Rep.Page.Concerns a) instance GHC.Generics.Generic Web.Rep.Page.PageConcerns instance GHC.Classes.Eq Web.Rep.Page.PageConcerns instance GHC.Show.Show Web.Rep.Page.PageConcerns instance GHC.Generics.Generic Web.Rep.Page.PageStructure instance GHC.Classes.Eq Web.Rep.Page.PageStructure instance GHC.Show.Show Web.Rep.Page.PageStructure instance GHC.Generics.Generic Web.Rep.Page.PageConfig instance GHC.Classes.Eq Web.Rep.Page.PageConfig instance GHC.Show.Show Web.Rep.Page.PageConfig instance GHC.Base.Monoid Web.Rep.Page.Css instance GHC.Base.Semigroup Web.Rep.Page.Css instance GHC.Generics.Generic Web.Rep.Page.Css instance GHC.Classes.Eq Web.Rep.Page.Css instance GHC.Show.Show Web.Rep.Page.Css instance GHC.Base.Monoid Web.Rep.Page.Js instance GHC.Base.Semigroup Web.Rep.Page.Js instance GHC.Generics.Generic Web.Rep.Page.Js instance GHC.Show.Show Web.Rep.Page.Js instance GHC.Classes.Eq Web.Rep.Page.Js instance GHC.Generics.Generic Web.Rep.Page.Page instance GHC.Show.Show Web.Rep.Page.Page instance GHC.Base.Semigroup Web.Rep.Page.Page instance GHC.Base.Monoid Web.Rep.Page.Page instance GHC.Base.Functor Web.Rep.Page.Concerns instance GHC.Base.Applicative Web.Rep.Page.Concerns -- | Page rendering module Web.Rep.Render -- | Render a Page with the default configuration into Html. renderPage :: Page -> Markup -- | Render a Page into css text, js text and html. renderPageWith :: PageConfig -> Page -> (ByteString, ByteString, Markup) -- | Render a Page into Html. renderPageHtmlWith :: PageConfig -> Page -> Markup -- | Render a Page as Text. renderPageAsByteString :: PageConfig -> Page -> Concerns ByteString -- | Render Page concerns to files. renderPageToFile :: FilePath -> PageConfig -> Page -> IO () -- | Render a page to just a Html file. renderPageHtmlToFile :: FilePath -> PageConfig -> Page -> IO () -- | Serve pages via ScottyM module Web.Rep.Server -- | serve a Page via a ScottyM servePageWith :: RoutePattern -> PageConfig -> Page -> ScottyM () -- | A shared-element representation of web page communication. module Web.Rep.Shared -- | Information contained in a web page can usually be considered to be -- isomorphic to a map of named values - a HashMap. This is -- especially true when considering a differential of information -- contained in a web page. Looking at a page from the outside, it often -- looks like a streaming differential of a hashmap. -- -- RepF consists of an underlying value being represented, and, given a -- hashmap state, a way to produce a representation of the underlying -- value (or error), in another domain, together with the potential to -- alter the hashmap state. data RepF r a Rep :: r -> (HashMap ByteString ByteString -> (HashMap ByteString ByteString, Either ByteString a)) -> RepF r a [rep] :: RepF r a -> r [make] :: RepF r a -> HashMap ByteString ByteString -> (HashMap ByteString ByteString, Either ByteString a) -- | the common usage, where the representation domain is Html type Rep a = RepF Markup a -- | stateful result of one step, given a RepF, and a monadic -- action. Useful for testing and for initialising a page. oneRep :: Monad m => Rep a -> (Rep a -> HashMap ByteString ByteString -> m ()) -> StateT (HashMap ByteString ByteString) m (HashMap ByteString ByteString, Either ByteString a) -- | Driven by the architecture of the DOM, web page components are -- compositional, and tree-like, where components are often composed of -- other components, and values are thus shared across components. -- -- This is sometimes referred to as "observable sharing". See -- data-reify as another library that reifies this (pun intended), -- and provided the initial inspiration for this implementation. -- -- unshare should only be run once, which is a terrible flaw that might -- be fixed by linear types. newtype SharedRepF m r a SharedRep :: StateT (Int, HashMap ByteString ByteString) m (RepF r a) -> SharedRepF m r a [unshare] :: SharedRepF m r a -> StateT (Int, HashMap ByteString ByteString) m (RepF r a) -- | default representation type of Html () type SharedRep m a = SharedRepF m Markup a -- | Compute the initial state of a SharedRep and then run an action once -- (see tests). runOnce :: Monad m => SharedRep m a -> (Markup -> HashMap ByteString ByteString -> m ()) -> m (HashMap ByteString ByteString, Either ByteString a) -- | compute the initial state of a SharedRep (testing) zeroState :: Monad m => SharedRep m a -> m (Markup, (HashMap ByteString ByteString, Either ByteString a)) -- | Create a sharedRep register :: Monad m => (ByteString -> Either ByteString a) -> (a -> ByteString) -> (ByteString -> a -> r) -> a -> SharedRepF m r a -- | Like register, but does not put a value into the HashMap on -- instantiation, consumes the value when found in the HashMap, and -- substitutes a default on lookup failure message :: Monad m => (ByteString -> Either ByteString a) -> (ByteString -> a -> r) -> a -> a -> SharedRepF m r a -- | name supply for elements of a SharedRepF genName :: MonadState Int m => m ByteString -- | sometimes a number doesn't work properly in html (or js???), and an -- alpha prefix seems to help genNamePre :: MonadState Int m => ByteString -> m ByteString instance GHC.Base.Functor (Web.Rep.Shared.RepF r) instance GHC.Base.Functor m => GHC.Base.Functor (Web.Rep.Shared.SharedRepF m r) instance GHC.Base.Functor m => Data.Bifunctor.Bifunctor (Web.Rep.Shared.SharedRepF m) instance GHC.Base.Monad m => Data.Biapplicative.Biapplicative (Web.Rep.Shared.SharedRepF m) instance (GHC.Base.Monad m, GHC.Base.Monoid r) => GHC.Base.Applicative (Web.Rep.Shared.SharedRepF m r) instance GHC.Base.Semigroup r => GHC.Base.Semigroup (Web.Rep.Shared.RepF r a) instance (GHC.Base.Monoid a, GHC.Base.Monoid r) => GHC.Base.Monoid (Web.Rep.Shared.RepF r a) instance Data.Bifunctor.Bifunctor Web.Rep.Shared.RepF instance Data.Biapplicative.Biapplicative Web.Rep.Shared.RepF instance GHC.Base.Monoid r => GHC.Base.Applicative (Web.Rep.Shared.RepF r) -- | Some bootstrap assets and functionality. module Web.Rep.Bootstrap -- | bootstrap css link bootstrapCss :: Markup -- | bootstrap JS link bootstrapJs :: Markup -- | bootstrap meta element. bootstrapMeta :: Markup -- | A page containing all the bootstrap needs for a web page. bootstrapPage :: Page -- | wrap some Html with the bootstrap card class cardify :: (Markup, [Attr]) -> Maybe ByteString -> (Markup, [Attr]) -> Markup -- | create a bootstrapped accordian class accordion :: MonadState Int m => ByteString -> Maybe ByteString -> [(ByteString, Markup)] -> m Markup -- | create a bootstrapped accordian class accordionChecked :: MonadState Int m => ByteString -> [(ByteString, Markup, Markup)] -> m Markup -- | A Html object based on the bootstrap accordion card concept. accordionCard :: Bool -> [Attr] -> ByteString -> ByteString -> ByteString -> ByteString -> Markup -> Markup -- | A bootstrap accordion card attached to a checkbox. accordionCardChecked :: Bool -> ByteString -> ByteString -> ByteString -> ByteString -> Markup -> Markup -> Markup -- | This version of accordion runs a local state for naming, and will -- cause name clashes if the prefix is not unique. accordion_ :: ByteString -> Maybe ByteString -> [(ByteString, Markup)] -> Markup -- | Various SharedRep instances for common html input elements. module Web.Rep.SharedReps -- | Create a sharedRep from an Input. repInput :: Monad m => (ByteString -> Either ByteString a) -> (a -> ByteString) -> Input a -> a -> SharedRep m a -- | Like repInput, but does not put a value into the HashMap on -- instantiation, consumes the value when found in the HashMap, and -- substitutes a default on lookup failure repMessage :: Monad m => (ByteString -> Either ByteString a) -> (a -> ByteString) -> Input a -> a -> a -> SharedRep m a -- | integral slider -- -- For Example, a slider between 0 and 1000 with a step of 10 and a -- default value of 300 is: -- --
--   :t sliderI (Just "label") 0 1000 10 300
--   
-- -- sliderI (Just "label") 0 1000 10 300 :: (Monad m, ToHtml a, P.Integral -- a, Show a) => SharedRep m a sliderI :: (Monad m, Integral a, ToByteString a) => Maybe ByteString -> a -> a -> a -> a -> SharedRep m a -- | double slider -- -- For Example, a slider between 0 and 1 with a step of 0.01 and a -- default value of 0.3 is: -- --
--   :t slider (Just "label") 0 1 0.01 0.3
--   
-- -- slider (Just "label") 0 1 0.01 0.3 :: Monad m => SharedRep m Double slider :: Monad m => Maybe ByteString -> Double -> Double -> Double -> Double -> SharedRep m Double -- | double slider with shown value -- -- For Example, a slider between 0 and 1 with a step of 0.01 and a -- default value of 0.3 is: -- --
--   :t slider (Just "label") 0 1 0.01 0.3
--   
-- -- slider (Just "label") 0 1 0.01 0.3 :: Monad m => SharedRep m Double sliderV :: Monad m => Maybe ByteString -> Double -> Double -> Double -> Double -> SharedRep m Double -- | integral slider with shown value sliderVI :: (Monad m, Integral a, ToByteString a) => Maybe ByteString -> a -> a -> a -> a -> SharedRep m a -- | dropdown box dropdown :: Monad m => (ByteString -> Either ByteString a) -> (a -> ByteString) -> Maybe ByteString -> [ByteString] -> a -> SharedRep m a -- | dropdown box with multiple selections dropdownMultiple :: Monad m => Parser ByteString a -> (a -> ByteString) -> Maybe ByteString -> [ByteString] -> [a] -> SharedRep m [a] -- | a datalist input datalist :: Monad m => Maybe ByteString -> [ByteString] -> ByteString -> ByteString -> SharedRep m ByteString -- | A dropdown box designed to help represent a haskell sum type. dropdownSum :: Monad m => (ByteString -> Either ByteString a) -> (a -> ByteString) -> Maybe ByteString -> [ByteString] -> a -> SharedRep m a -- | Non-typed hex color input colorPicker :: Monad m => Maybe ByteString -> ByteString -> SharedRep m ByteString -- | textbox classique -- --
--   :t textbox (Just "label") "some text"
--   
-- -- textbox (Just "label") "some text" :: Monad m => SharedRep m -- ByteString textbox :: Monad m => Maybe ByteString -> ByteString -> SharedRep m ByteString -- | textarea input element, specifying number of rows. textarea :: Monad m => Int -> Maybe ByteString -> ByteString -> SharedRep m ByteString -- | A checkbox input. checkbox :: Monad m => Maybe ByteString -> Bool -> SharedRep m Bool -- | a toggle button toggle :: Monad m => Maybe ByteString -> Bool -> SharedRep m Bool -- | a toggle button, with no label toggle_ :: Monad m => Maybe ByteString -> Bool -> SharedRep m Bool -- | a button button :: Monad m => Maybe ByteString -> SharedRep m Bool -- | filename input chooseFile :: Monad m => Maybe ByteString -> ByteString -> SharedRep m ByteString -- | Represent a Maybe using a checkbox. -- -- Hides the underlying content on Nothing maybeRep :: Monad m => Maybe ByteString -> Bool -> SharedRep m a -> SharedRep m (Maybe a) -- | A (fixed-size) list represented in html as an accordion card A major -- restriction of the library is that a SharedRepF does not have a -- Monad instance. In practice, this means that the external -- representation of lists cannot have a dynamic size. accordionList :: Monad m => Maybe ByteString -> ByteString -> Maybe ByteString -> (ByteString -> a -> SharedRep m a) -> [ByteString] -> [a] -> SharedRep m [a] -- | A fixed-sized list of Maybe a's listMaybeRep :: Monad m => Maybe ByteString -> ByteString -> (ByteString -> Maybe a -> SharedRep m (Maybe a)) -> Int -> [a] -> SharedRep m [Maybe a] -- | A SharedRep of [a]. Due to the applicative nature of the bridge, the -- size of lists has to be fixed on construction. listRep is a workaround -- for this, to enable some form of dynamic sizing. listRep :: Monad m => Maybe ByteString -> ByteString -> (Bool -> SharedRep m Bool) -> (a -> SharedRep m a) -> Int -> a -> [a] -> SharedRep m [a] -- | Parse from a textbox -- -- Uses focusout so as not to spam the reader. readTextbox :: (Monad m, Read a, ToByteString a) => Maybe ByteString -> a -> SharedRep m (Either ByteString a) -- | A sensible default for the accordion row labels for a list defaultListLabels :: Int -> [ByteString] -- | Dropdown representation of a multi-element list. repChoice :: Monad m => Int -> [(ByteString, SharedRep m a)] -> SharedRep m a -- | subtype Html class. subtype :: ByteString -> ByteString -> [Attr] -- | select test keys from a Map selectItems :: [ByteString] -> HashMap ByteString a -> [(ByteString, a)] -- | rep of multiple items list repItemsSelect :: Monad m => [ByteString] -> [ByteString] -> SharedRep m [ByteString] -- | A socket between a web page and haskell, based on the box library. module Web.Rep.Socket -- | Page with all the trimmings for a sharedRep Box socketPage :: Page -- | Bootstrapped base page for a web socket. defaultSocketPage :: Page -- | Socket configuration -- --
--   >>> defaultSocketConfig
--   SocketConfig {host = "127.0.0.1", port = 9160, path = "/"}
--   
data SocketConfig SocketConfig :: Text -> Int -> Text -> SocketConfig [host] :: SocketConfig -> Text [port] :: SocketConfig -> Int [path] :: SocketConfig -> Text -- | official default defaultSocketConfig :: SocketConfig -- | bidirectional websocket serving a Box serveSocketBox :: SocketConfig -> Page -> Box IO Text Text -> IO () -- | A common Box pattern. [Code] is typically committed to the websocket -- and key-value elements, representing changes to the shared objects -- that are in the Dom are emitted. type CodeBox = Box IO [Code] (ByteString, ByteString) -- | Codensity CodeBox type CoCodeBox = Codensity IO (Box IO [Code] (ByteString, ByteString)) -- | Configuration for a CodeBox serving. data CodeBoxConfig CodeBoxConfig :: SocketConfig -> Page -> Queue [Code] -> Queue (ByteString, ByteString) -> CodeBoxConfig [codeBoxSocket] :: CodeBoxConfig -> SocketConfig [codeBoxPage] :: CodeBoxConfig -> Page [codeBoxCommitterQueue] :: CodeBoxConfig -> Queue [Code] [codeBoxEmitterQueue] :: CodeBoxConfig -> Queue (ByteString, ByteString) -- | official default config. defaultCodeBoxConfig :: CodeBoxConfig -- | Turn the default configuration into a live (Codensity) CodeBox codeBox :: CoCodeBox -- | Turn a configuration into a live (Codensity) CodeBox codeBoxWith :: CodeBoxConfig -> CoCodeBox -- | serve a SharedRep serveRep :: SharedRep IO a -> (Markup -> [Code]) -> (Either ByteString a -> [Code]) -> CodeBoxConfig -> IO () -- | non-codensity sharedRep server. serveRepWithBox :: SharedRep IO a -> (Markup -> [Code]) -> (Either ByteString a -> [Code]) -> CodeBox -> IO () -- | Convert HTML representation to Code, replacing the input section of a -- page. replaceInput :: Markup -> [Code] -- | Convert (typically parsed representation) to Code, replacing the -- output section of a page, and appending errors. replaceOutput :: Show a => Either ByteString a -> [Code] -- | Convert (typically parsed representation) to Code, replacing the -- output section of a page, and throwing away errors. replaceOutput_ :: Show a => Either ByteString a -> [Code] -- | Stream a SharedRep sharedStream :: Monad m => SharedRep m a -> Committer m Markup -> Committer m (Either ByteString a) -> Emitter m (ByteString, ByteString) -> m () -- | Configuration to control a (re)play of an emitter with a Gap (timing) -- element. data PlayConfig PlayConfig :: Bool -> Double -> Int -> PlayConfig [playPause] :: PlayConfig -> Bool [playSpeed] :: PlayConfig -> Double [playFrame] :: PlayConfig -> Int -- | Start on pause at normal speed and at frame 0. defaultPlayConfig :: PlayConfig -- | representation of a PlayConfig repPlayConfig :: PlayConfig -> SharedRep IO PlayConfig -- | Serve an emitter controlled by a PlayConfig representation. servePlayStream :: PlayConfig -> CodeBoxConfig -> CoEmitter IO (Gap, [Code]) -> IO () -- | Serve an emitter controlled by a PlayConfig representation, with an -- explicit CodeBox. servePlayStreamWithBox :: PlayConfig -> CoEmitter IO (Gap, [Code]) -> CodeBox -> IO () -- | A simple schema for code that communicates changes to a Html page via -- JS code. data Code Replace :: ByteString -> ByteString -> Code Append :: ByteString -> ByteString -> Code Console :: ByteString -> Code Eval :: ByteString -> Code Val :: ByteString -> Code -- | Convert Code to a ByteString code :: Code -> ByteString -- | write to the console console :: ByteString -> ByteString -- | send arbitrary byestrings. val :: ByteString -> ByteString -- | replace a container and run any embedded scripts replace :: ByteString -> ByteString -> ByteString -- | append to a container and run any embedded scripts append :: ByteString -> ByteString -> ByteString -- | Double backslash newline and single quotes. clean :: ByteString -> ByteString -- | create a web socket for event data webSocket :: Js -- | Event hooks that may need to be reattached given dynamic content -- creation. refreshJsbJs :: Js -- | prevent the Enter key from triggering an event preventEnter :: Js -- | script injection js. -- -- See https://ghinda.net/article/script-tags/ for why this might -- be needed. runScriptJs :: Js instance GHC.Generics.Generic Web.Rep.Socket.SocketConfig instance GHC.Classes.Eq Web.Rep.Socket.SocketConfig instance GHC.Show.Show Web.Rep.Socket.SocketConfig instance GHC.Generics.Generic Web.Rep.Socket.PlayConfig instance GHC.Show.Show Web.Rep.Socket.PlayConfig instance GHC.Classes.Eq Web.Rep.Socket.PlayConfig instance GHC.Read.Read Web.Rep.Socket.Code instance GHC.Generics.Generic Web.Rep.Socket.Code instance GHC.Show.Show Web.Rep.Socket.Code instance GHC.Classes.Eq Web.Rep.Socket.Code instance GHC.Generics.Generic Web.Rep.Socket.CodeBoxConfig -- | A haskell library for representing: -- -- -- -- See app/examples.hs and Examples for usage. module Web.Rep -- | Information contained in a web page can usually be considered to be -- isomorphic to a map of named values - a HashMap. This is -- especially true when considering a differential of information -- contained in a web page. Looking at a page from the outside, it often -- looks like a streaming differential of a hashmap. -- -- RepF consists of an underlying value being represented, and, given a -- hashmap state, a way to produce a representation of the underlying -- value (or error), in another domain, together with the potential to -- alter the hashmap state. data RepF r a Rep :: r -> (HashMap ByteString ByteString -> (HashMap ByteString ByteString, Either ByteString a)) -> RepF r a [rep] :: RepF r a -> r [make] :: RepF r a -> HashMap ByteString ByteString -> (HashMap ByteString ByteString, Either ByteString a) -- | the common usage, where the representation domain is Html type Rep a = RepF Markup a -- | stateful result of one step, given a RepF, and a monadic -- action. Useful for testing and for initialising a page. oneRep :: Monad m => Rep a -> (Rep a -> HashMap ByteString ByteString -> m ()) -> StateT (HashMap ByteString ByteString) m (HashMap ByteString ByteString, Either ByteString a) -- | Driven by the architecture of the DOM, web page components are -- compositional, and tree-like, where components are often composed of -- other components, and values are thus shared across components. -- -- This is sometimes referred to as "observable sharing". See -- data-reify as another library that reifies this (pun intended), -- and provided the initial inspiration for this implementation. -- -- unshare should only be run once, which is a terrible flaw that might -- be fixed by linear types. newtype SharedRepF m r a SharedRep :: StateT (Int, HashMap ByteString ByteString) m (RepF r a) -> SharedRepF m r a [unshare] :: SharedRepF m r a -> StateT (Int, HashMap ByteString ByteString) m (RepF r a) -- | default representation type of Html () type SharedRep m a = SharedRepF m Markup a -- | Compute the initial state of a SharedRep and then run an action once -- (see tests). runOnce :: Monad m => SharedRep m a -> (Markup -> HashMap ByteString ByteString -> m ()) -> m (HashMap ByteString ByteString, Either ByteString a) -- | compute the initial state of a SharedRep (testing) zeroState :: Monad m => SharedRep m a -> m (Markup, (HashMap ByteString ByteString, Either ByteString a)) -- | Create a sharedRep register :: Monad m => (ByteString -> Either ByteString a) -> (a -> ByteString) -> (ByteString -> a -> r) -> a -> SharedRepF m r a -- | name supply for elements of a SharedRepF genName :: MonadState Int m => m ByteString -- | sometimes a number doesn't work properly in html (or js???), and an -- alpha prefix seems to help genNamePre :: MonadState Int m => ByteString -> m ByteString -- | Components of a web page. -- -- A web page can take many forms but still have the same underlying -- representation. For example, CSS can be linked to in a separate file, -- or can be inline within html, but still be the same css and have the -- same expected external effect. A Page represents the practical -- components of what makes up a static snapshot of a web page. data Page Page :: Markup -> Markup -> Css -> Js -> Js -> Markup -> Markup -> Page -- | css library links [libsCss] :: Page -> Markup -- | javascript library links [libsJs] :: Page -> Markup -- | css [cssBody] :: Page -> Css -- | javascript with global scope [jsGlobal] :: Page -> Js -- | javascript included within the onLoad function [jsOnLoad] :: Page -> Js -- | html within the header [htmlHeader] :: Page -> Markup -- | body html [htmlBody] :: Page -> Markup -- | Configuration options when rendering a Page. data PageConfig PageConfig :: PageConcerns -> PageStructure -> RenderStyle -> Concerns FilePath -> [FilePath] -> PageConfig [concerns] :: PageConfig -> PageConcerns [structure] :: PageConfig -> PageStructure [renderStyle] :: PageConfig -> RenderStyle [filenames] :: PageConfig -> Concerns FilePath [localdirs] :: PageConfig -> [FilePath] -- | Default configuration is inline ecma and css, separate html header and -- body, minified code, with the suggested filename prefix. defaultPageConfig :: FilePath -> PageConfig -- | A web page typically is composed of some css, javascript and html. -- -- Concerns abstracts this structural feature of a web page. data Concerns a Concerns :: a -> a -> a -> Concerns a [cssConcern] :: Concerns a -> a [jsConcern] :: Concerns a -> a [htmlConcern] :: Concerns a -> a -- | The common file suffixes of the three concerns. suffixes :: Concerns FilePath -- | Create filenames for each Concern element. concernNames :: FilePath -> FilePath -> Concerns FilePath -- | Is the rendering to include all Concerns (typically in a html -- file) or be separated (tyypically into separate files and linked in -- the html file)? data PageConcerns Inline :: PageConcerns Separated :: PageConcerns -- | Various ways that a Html file can be structured. data PageStructure HeaderBody :: PageStructure Headless :: PageStructure Snippet :: PageStructure -- | Indented 0 puts newlines in between the tags. data () => RenderStyle Compact :: RenderStyle Indented :: Int -> RenderStyle -- | css as a string. newtype Css Css :: ByteString -> Css [cssByteString] :: Css -> ByteString -- | Render Css as text. renderCss :: RenderStyle -> Css -> ByteString -- | Css snippet for reponsiveness to preferred color-scheme. cssColorScheme :: Css -- | Javascript as string newtype Js Js :: ByteString -> Js [jsByteString] :: Js -> ByteString -- | Add the windows.onload assignment onLoad :: Js -> Js -- | A map from keys to values. A map cannot contain duplicate keys; each -- key can map to at most one value. data () => HashMap k v -- | Some simple usage examples to get started with the library. -- -- The most important example is repExamples which forms the basis -- of the app example. module Web.Rep.Examples -- | simple page example page1 :: Page -- | page with localised libraries page2 :: Page -- | Page with separated css and js. cfg2 :: PageConfig -- | One of each sharedrep input instances. data RepExamples RepExamples :: ByteString -> ByteString -> Int -> Double -> Int -> Double -> Bool -> Bool -> Int -> [Int] -> Shape -> ByteString -> RepExamples [repTextbox] :: RepExamples -> ByteString [repTextarea] :: RepExamples -> ByteString [repSliderI] :: RepExamples -> Int [repSlider] :: RepExamples -> Double [repSliderVI] :: RepExamples -> Int [repSliderV] :: RepExamples -> Double [repCheckbox] :: RepExamples -> Bool [repToggle] :: RepExamples -> Bool [repDropdown] :: RepExamples -> Int [repDropdownMultiple] :: RepExamples -> [Int] [repShape] :: RepExamples -> Shape [repColor] :: RepExamples -> ByteString -- | one of each input SharedReps repExamples :: Monad m => SharedRep m RepExamples -- | For a typed dropdown example. data Shape SquareShape :: Shape CircleShape :: Shape -- | shape printer fromShape :: Shape -> ByteString -- | shape parser toShape :: ByteString -> Shape instance GHC.Generics.Generic Web.Rep.Examples.Shape instance GHC.Show.Show Web.Rep.Examples.Shape instance GHC.Classes.Eq Web.Rep.Examples.Shape instance GHC.Generics.Generic Web.Rep.Examples.RepExamples instance GHC.Classes.Eq Web.Rep.Examples.RepExamples instance GHC.Show.Show Web.Rep.Examples.RepExamples