Shpadoinkle-backend-static 0.1.0.1 → 0.1.0.2
raw patch · 4 files changed
+47/−44 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- LICENSE +21/−20
- README.md +3/−2
- Shpadoinkle-backend-static.cabal +3/−3
- Shpadoinkle/Backend/Static.hs +20/−19
LICENSE view
@@ -1,26 +1,27 @@-Shpadoinkle Static, I think I know exactly what it means-Copyright © 2020 Isaac Shpaira+Shpadoinkle Static aka S11 Static+Copyright © 2020 Isaac Shapira All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:-1. Redistributions of source code must retain the above copyright-notice, this list of conditions and the following disclaimer.-2. Redistributions in binary form must reproduce the above copyright-notice, this list of conditions and the following disclaimer in the-documentation and/or other materials provided with the distribution.-3. Neither the name of the <`3:organization`> nor the-names of its contributors may be used to endorse or promote products-derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY <|2|> ''AS IS'' AND ANY-EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE-DISCLAIMED. IN NO EVENT SHALL <|2|> BE LIABLE FOR ANY-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ * Redistributions of source code must retain the above copyright notice,+ this list of conditions and the following disclaimer.+ * Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the distribution.+ * Neither the name of Shpadoinkle nor the names of its contributors may be+ used to endorse or promote products derived from this software without+ specific prior written permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE+POSSIBILITY OF SUCH DAMAGE.
README.md view
@@ -1,6 +1,7 @@ # Shpadoinkle Backend Static [](https://gitlab.com/fresheyeball/Shpadoinkle)+[](https://shpadoinkle.org/backend-static) [](https://opensource.org/licenses/BSD-3-Clause) [](https://builtwithnix.org) [](https://hackage.haskell.org/package/Shpadoinkle-backend-static)@@ -9,7 +10,7 @@ This module provides a static rendering backend that translates Shpadoinkle `Html` into `Text`. -For example+For example: ```haskell page :: Html' a@@ -19,7 +20,7 @@ main = putStrLn $ unpack $ renderStatic page ``` -will output+will output: ```html <div class="header"><h1>Trappers!</h1></div>
Shpadoinkle-backend-static.cabal view
@@ -4,12 +4,12 @@ -- -- see: https://github.com/sol/hpack ----- hash: 10c22468330265f5a289c3bd653839967387f602db4e70b02ae2d37205b03688+-- hash: 9d3d4c783f822f5b3b09c7c4fbe024377cae3b31724f8694584df2e31207f9ac name: Shpadoinkle-backend-static-version: 0.1.0.1+version: 0.1.0.2 synopsis: A backend for rendering Shpadoinkle as Text.-description: Shpadoinkle's static backend, renders Html as Text. Event listeners are ignored. This is useful when rendering on the server, or for static site generation.+description: Shpadoinkle's static backend, which renders Html as Text. Event listeners are ignored. This is useful when rendering on the server or for static site generation. category: Web author: Isaac Shapira maintainer: fresheyeball@protonmail.com
Shpadoinkle/Backend/Static.hs view
@@ -1,10 +1,12 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} + {-| Get your view as plain text, ignoring event listeners. -} + module Shpadoinkle.Backend.Static ( renderStatic ) where @@ -15,25 +17,26 @@ import Shpadoinkle hiding (name, props, text) --- | Render @Shpadoinkle.Html@ as @Text@+-- | Render as @Text@ renderStatic :: Html m a -> Text-renderStatic = \case- Node tag props _ | isSelfClosing tag- -> renderSelfClosing tag props- Node tag props cs -> renderWrapping tag props cs- Potato _ -> mempty- TextNode t -> t+renderStatic = cataH renderTag (const mempty) id +renderTag :: Text -> [(Text, Prop m a)] -> [Text] -> Text+renderTag tag props cs+ | isSelfClosing tag = renderSelfClosing tag props+ | otherwise = renderWrapping tag props cs++ isSelfClosing :: Text -> Bool isSelfClosing = flip elem [ "area", "base", "br", "embed", "hr", "iframe" , "img", "input", "link", "meta", "param", "source", "track" ] -renderWrapping :: Text -> [(Text, Prop m a)] -> [Html m a] -> Text+renderWrapping :: Text -> [(Text, Prop m a)] -> [Text] -> Text renderWrapping tag props cs = renderOpening tag props <> ">"- <> mconcat (renderStatic <$> cs) <> "</" <> tag <> ">"+ <> mconcat cs <> "</" <> tag <> ">" renderSelfClosing :: Text -> [(Text, Prop m a)] -> Text@@ -50,14 +53,12 @@ renderProp :: Text -> Prop m a -> Maybe Text-renderProp name = \case- PListener _ -> Nothing- PText t -> Just $ lice name <> "=\"" <> t <> "\""- PFlag True -> Just name- PFlag False -> Nothing- where- lice = \case- "className" -> "class"- x -> x-+renderProp name = cataProp renderTextProp renderListener renderFlag + where renderTextProp t = Just $ lice name <> "=\"" <> t <> "\""+ renderListener _ = Nothing+ renderFlag True = Just name+ renderFlag False = Nothing+ lice = \case+ "className" -> "class"+ x -> x