Compare commits
4
Commits
36f9bb390d
...
0.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fde68ee833 | ||
|
|
610c819483 | ||
|
|
3fd4177cd4 | ||
|
|
9881b44fa2 |
@@ -1 +1,21 @@
|
|||||||
# utoy
|
# utoy
|
||||||
|
|
||||||
|
## Building the executable
|
||||||
|
|
||||||
|
```
|
||||||
|
$ $(nix-build utoy.nix)/bin/utoy
|
||||||
|
```
|
||||||
|
|
||||||
|
## Building the Docker image
|
||||||
|
|
||||||
|
```
|
||||||
|
$ docker load < $(nix-build nix/docker-image.nix)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Development Shell
|
||||||
|
|
||||||
|
Includes Stack, `haskell-language-server`, `gen-hie` etc.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ nix-shell
|
||||||
|
```
|
||||||
|
|||||||
+27
-15
@@ -62,7 +62,7 @@ app = serve (Proxy :: Proxy API) server
|
|||||||
|
|
||||||
type API =
|
type API =
|
||||||
"bytes" :> Capture "bytes" Text :> Get '[PlainText, HTML] BytesModel
|
"bytes" :> Capture "bytes" Text :> Get '[PlainText, HTML] BytesModel
|
||||||
:<|> "codepoints" :> Capture "codepoints" Text :> Get '[PlainText] CodepointsModel
|
:<|> "codepoints" :> Capture "codepoints" Text :> Get '[PlainText, HTML] CodepointsModel
|
||||||
:<|> "text" :> Capture "text" Text :> Get '[HTML] TextModel
|
:<|> "text" :> Capture "text" Text :> Get '[HTML] TextModel
|
||||||
|
|
||||||
server :: Server API
|
server :: Server API
|
||||||
@@ -108,12 +108,7 @@ instance MimeRender PlainText BytesModel where
|
|||||||
]
|
]
|
||||||
|
|
||||||
instance MimeRender HTML BytesModel where
|
instance MimeRender HTML BytesModel where
|
||||||
mimeRender _ model = renderHtml $ H.docTypeHtml $ do
|
mimeRender _ model = renderHtml $ documentWithBody $ do
|
||||||
H.head $ do
|
|
||||||
H.meta ! A.charset "utf-8"
|
|
||||||
H.title "utoy"
|
|
||||||
H.style $ H.toHtml $ Encoding.decodeUtf8 $(embedFile "static/utoy.css")
|
|
||||||
H.body $ do
|
|
||||||
H.table $ for_ model.codepoints $ \(bytes, eiC) -> do
|
H.table $ for_ model.codepoints $ \(bytes, eiC) -> do
|
||||||
H.tr $ do
|
H.tr $ do
|
||||||
H.td $ H.pre $ H.toHtml $ unlines $ map unwords [map showByteHex bytes, map showByteBin bytes]
|
H.td $ H.pre $ H.toHtml $ unlines $ map unwords [map showByteHex bytes, map showByteBin bytes]
|
||||||
@@ -121,8 +116,7 @@ instance MimeRender HTML BytesModel where
|
|||||||
Left err ->
|
Left err ->
|
||||||
H.td ! A.colspan "4" $ H.toHtml $ "Decoding error: " ++ err
|
H.td ! A.colspan "4" $ H.toHtml $ "Decoding error: " ++ err
|
||||||
Right c -> do
|
Right c -> do
|
||||||
H.td $ do
|
H.td $ H.input ! A.class_ "charbox" ! A.value (H.toValue [c])
|
||||||
H.input ! A.class_ "charbox" ! A.value (H.toValue [c])
|
|
||||||
H.td $ H.code $ printfHtml "U+%04X" c
|
H.td $ H.code $ printfHtml "U+%04X" c
|
||||||
H.td $ H.code $ H.toHtml $ intercalate ", " $ maybeToList (UnicodeNames.name c) ++ map (++ "*") (UnicodeNames.nameAliases c)
|
H.td $ H.code $ H.toHtml $ intercalate ", " $ maybeToList (UnicodeNames.name c) ++ map (++ "*") (UnicodeNames.nameAliases c)
|
||||||
H.td $ H.code $ H.toHtml $ fromMaybe "" $ blockName c
|
H.td $ H.code $ H.toHtml $ fromMaybe "" $ blockName c
|
||||||
@@ -162,6 +156,20 @@ instance MimeRender PlainText CodepointsModel where
|
|||||||
| (codepoint, eiC) <- model.codepoints
|
| (codepoint, eiC) <- model.codepoints
|
||||||
]
|
]
|
||||||
|
|
||||||
|
instance MimeRender HTML CodepointsModel where
|
||||||
|
mimeRender _ model = renderHtml $ documentWithBody $ do
|
||||||
|
H.table $ for_ model.codepoints $ \(codepoint, eiC) ->
|
||||||
|
H.tr $ do
|
||||||
|
H.td $ H.code $ H.toHtml $ Text.pack $ printf "0x%X" codepoint
|
||||||
|
case eiC of
|
||||||
|
Left err -> do
|
||||||
|
H.td ! A.colspan "4" $ H.code $ H.toHtml $ "Decoding error: " <> Text.pack err
|
||||||
|
Right c -> do
|
||||||
|
H.td $ H.input ! A.class_ "charbox" ! A.value (H.toValue [c])
|
||||||
|
H.td $ H.code $ printfHtml "U+%04X" c
|
||||||
|
H.td $ H.code $ H.toHtml $ intercalate ", " $ maybeToList (UnicodeNames.name c) ++ map (++ "*") (UnicodeNames.nameAliases c)
|
||||||
|
H.td $ H.code $ H.toHtml $ fromMaybe "" $ blockName c
|
||||||
|
|
||||||
-- /text/<text>
|
-- /text/<text>
|
||||||
|
|
||||||
newtype TextModel = TextModel
|
newtype TextModel = TextModel
|
||||||
@@ -169,12 +177,7 @@ newtype TextModel = TextModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
instance MimeRender HTML TextModel where
|
instance MimeRender HTML TextModel where
|
||||||
mimeRender _ model = renderHtml $ H.docTypeHtml $ do
|
mimeRender _ model = renderHtml $ documentWithBody $ do
|
||||||
H.head $ do
|
|
||||||
H.meta ! A.charset "utf-8"
|
|
||||||
H.title "utoy"
|
|
||||||
H.style $ H.toHtml $ Encoding.decodeUtf8 $(embedFile "static/utoy.css")
|
|
||||||
H.body $ do
|
|
||||||
H.table $ for_ (Text.unpack model.text) $ \c -> do
|
H.table $ for_ (Text.unpack model.text) $ \c -> do
|
||||||
H.tr $ do
|
H.tr $ do
|
||||||
H.td $ H.input ! A.class_ "charbox" ! A.value (H.toValue [c])
|
H.td $ H.input ! A.class_ "charbox" ! A.value (H.toValue [c])
|
||||||
@@ -203,6 +206,15 @@ orThrow (Right val) _ = pure val
|
|||||||
printfHtml :: PrintfArg a => String -> a -> H.Html
|
printfHtml :: PrintfArg a => String -> a -> H.Html
|
||||||
printfHtml fmt = (H.toHtml :: String -> H.Html) . printf fmt
|
printfHtml fmt = (H.toHtml :: String -> H.Html) . printf fmt
|
||||||
|
|
||||||
|
documentWithBody :: H.Html -> H.Html
|
||||||
|
documentWithBody body =
|
||||||
|
H.docTypeHtml $ do
|
||||||
|
H.head $ do
|
||||||
|
H.meta ! A.charset "utf-8"
|
||||||
|
H.title "utoy"
|
||||||
|
H.style $ H.toHtml $ Encoding.decodeUtf8 $(embedFile "static/utoy.css")
|
||||||
|
H.body body
|
||||||
|
|
||||||
-- HTML routes
|
-- HTML routes
|
||||||
|
|
||||||
data HTML
|
data HTML
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ let
|
|||||||
in
|
in
|
||||||
pkgs.dockerTools.buildImage {
|
pkgs.dockerTools.buildImage {
|
||||||
name = "git.pbrinkmeier.de/paul/utoy";
|
name = "git.pbrinkmeier.de/paul/utoy";
|
||||||
tag = "0.2";
|
tag = utoy.version;
|
||||||
config.Cmd = [ "${utoy}/bin/utoy" ];
|
config.Cmd = [ "${utoy}/bin/utoy" ];
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
# Adapted from new-template.hsfiles
|
# Adapted from new-template.hsfiles
|
||||||
|
|
||||||
name: utoy
|
name: utoy
|
||||||
version: 0.2
|
version: 0.3
|
||||||
git: "https://git.pbrinkmeier.de/paul/utoy"
|
git: "https://git.pbrinkmeier.de/paul/utoy"
|
||||||
license: MIT
|
license: MIT
|
||||||
author: "Paul Brinkmeier"
|
author: "Paul Brinkmeier"
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ cabal-version: 1.12
|
|||||||
-- see: https://github.com/sol/hpack
|
-- see: https://github.com/sol/hpack
|
||||||
|
|
||||||
name: utoy
|
name: utoy
|
||||||
version: 0.2
|
version: 0.3
|
||||||
author: Paul Brinkmeier
|
author: Paul Brinkmeier
|
||||||
maintainer: hallo@pbrinkmeier.de
|
maintainer: hallo@pbrinkmeier.de
|
||||||
copyright: 2023 Paul Brinkmeier
|
copyright: 2023 Paul Brinkmeier
|
||||||
|
|||||||
Reference in New Issue
Block a user