readme + refactor
This commit is contained in:
parent
b6f757c35e
commit
045908d7c3
5 changed files with 72 additions and 93 deletions
|
|
@ -1,38 +1,62 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module HtmlPrimitives where
|
||||
module HtmlPrimitives (mainPage, editPage) where
|
||||
|
||||
import Control.Monad.RWS (lift)
|
||||
-- NOTE: this looks like shit, but that's what happens when u dont use library and u bad
|
||||
-- TODO: check if compiler does in fact inline this mess as it has no buisness beeing computed more than once pro build
|
||||
|
||||
{-# INLINE mainPage #-}
|
||||
mainPage content =
|
||||
html "en" "todo" $
|
||||
h1 "Todo Liste"
|
||||
<> h2 "Stuce"
|
||||
<> f content
|
||||
<> newItemForm
|
||||
<> rawEditButton
|
||||
where
|
||||
f content = concatMap item (lines content)
|
||||
newItemForm = form "action=\"/add\" method=\"post\"><input type=\"text\" name=\"text\" placeholder=\"o add a new item>" $ button "type=\"submit\"" "add"
|
||||
rawEditButton = link "/edit" "edit todo list"
|
||||
|
||||
{-# INLINE editPage #-}
|
||||
editPage content =
|
||||
html "en" "edit" $ wrapContentWithArgs "form" "action=\"/edit\" method=\"post\"" (editForm content)
|
||||
where
|
||||
editForm content = editLabel <> br <> editTextArea content <> br <> editButton
|
||||
editLabel = label "list" "Edit the todo list"
|
||||
editTextArea = textArea "list" "30" "33"
|
||||
editButton = button "type=\"submit\"" "submit"
|
||||
|
||||
openingTag tag = "<" <> tag <> ">"
|
||||
closingTag tag = "</" <> tag <> ">"
|
||||
wrapContent tag content = openingTag tag <> content <> closingTag tag
|
||||
wrapContentWithArgs tag arg content = openingTag (tag <> arg) <> content <> closingTag tag
|
||||
singleWrap content = "<" <> content <> "/>"
|
||||
|
||||
docType = "<!DOCTYPE html>"
|
||||
wrapContent tag content = openingTag tag <> content <> closingTag tag
|
||||
wrapContentWithArgs tag arg content = openingTag (tag <> " " <> arg) <> content <> closingTag tag
|
||||
singleWrap = closingTag
|
||||
|
||||
br = "<br>"
|
||||
h1 = wrapContent "h1"
|
||||
h2 = wrapContent "h2"
|
||||
h3 = wrapContent "h3"
|
||||
link = wrapContent "a"
|
||||
li = wrapContent "li"
|
||||
link href = wrapContentWithArgs "a" ("href=\"" <> href <> "\"")
|
||||
p = wrapContent "p"
|
||||
|
||||
checkboxPrimitive id name True = singleWrap $ "input type='checkbox' id=" <> id <> " name=" <> name <> " checked"
|
||||
checkboxPrimitive id name False = singleWrap $ "input type='checkbox' id=" <> id <> " name=" <> name
|
||||
|
||||
label for = wrapContentWithArgs "label " ("for=" <> for)
|
||||
|
||||
button = wrapContentWithArgs "button"
|
||||
form = wrapContentWithArgs "form"
|
||||
label for = wrapContentWithArgs "label" ("for=" <> for)
|
||||
textArea id rows cols = wrapContentWithArgs "textarea" ("id=\"" <> id <> "\" name=\"" <> id <> "\" rows=\"" <> rows <> "\" cols=\"" <> cols <> "\"")
|
||||
checkbox id name checked = checkboxPrimitive id name checked <> label id name
|
||||
where
|
||||
checkboxPrimitive id name True = singleWrap $ "input type='checkbox' id=" <> id <> " name=" <> name <> " checked"
|
||||
checkboxPrimitive id name False = singleWrap $ "input type='checkbox' id=" <> id <> " name=" <> name
|
||||
|
||||
-- | Takes a raw line as in untouched from the file
|
||||
item rawLine = "<form action=\"/post/" <> rawLine <> "\" method=\"POST\"><button type=\"submit\">" <> rawLine <> "</button></form>"
|
||||
item rawLine = "<form action=\"/check/" <> rawLine <> "\" method=\"POST\"><button type=\"submit\">" <> rawLine <> "</button></form>"
|
||||
|
||||
path = "./app/res/b"
|
||||
|
||||
simpleSite fileContent =
|
||||
docType
|
||||
<> h1 "Bienvenue sur la todo liste"
|
||||
<> p "this website is a simple example of how haskell can quickly become a great tool to write websites fast"
|
||||
|
||||
ul content = wrapContent "ul" $ concatMap (wrapContent "li") content
|
||||
html lang title content = headHtml lang title <> content <> tailHtml
|
||||
where
|
||||
headHtml lang title =
|
||||
"<!doctype html><html lang=\""
|
||||
<> lang
|
||||
<> "\"><head><meta charset=\"UTF-8\" /><meta name=\"viewport\" content=\"width=device-width\" /><title>"
|
||||
<> title
|
||||
<> "</title></head><body>"
|
||||
tailHtml = "</body></html>"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue