-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a98a80c
commit 7a2b40d
Showing
5 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
showHomePage: showHomePage.hs MustacheTemplates.hs Records.hs | ||
ghc -Wall -fno-warn-name-shadowing $^ -o $@ | ||
|
||
MustacheTemplates.hs: homePage.mustache post.mustache | ||
../mustache2hs -m Records.hs homePage.mustache Blog post.mustache Post > MustacheTemplates.hs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Records where | ||
|
||
import Text.Blaze.Html | ||
import Text.Blaze.Html.Renderer.String | ||
import Text.PrettyPrint.Leijen | ||
|
||
newtype HTML = HTML Html | ||
|
||
data Blog = Blog { | ||
postCount :: Int, | ||
posts :: [Post] | ||
} | ||
|
||
data Post = Post { | ||
entryTitle :: String, | ||
entryContent :: HTML | ||
} | ||
|
||
instance Pretty HTML where | ||
pretty (HTML html) = string $ renderHtml html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Blog Home</title> | ||
</head> | ||
|
||
<body> | ||
{{#postCount}} | ||
<ol class="hfeed"> | ||
{{#posts}} | ||
<li class="hentry"> | ||
<section> | ||
{{> post.mustache}} | ||
</section> | ||
</li> | ||
{{/posts}} | ||
</ol> | ||
{{/postCount}} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h1 class="entry-title">{{entryTitle}}</h1> | ||
|
||
<div class="entry-content">{{{entryContent}}}</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Main where | ||
|
||
import Text.Blaze.Internal | ||
import Text.Blaze.Html5 | ||
import Blaze.ByteString.Builder | ||
import qualified Data.ByteString as BS | ||
import qualified Data.Text as T | ||
|
||
import Records | ||
import MustacheTemplates | ||
|
||
htmlEscape :: String -> String | ||
htmlEscape = concatMap escChar | ||
where | ||
escChar '&' = "&" | ||
escChar '"' = """ | ||
escChar '<' = "<" | ||
escChar '>' = ">" | ||
escChar c = [c] | ||
|
||
main :: IO () | ||
main = toByteStringIO BS.putStr $ | ||
homePage htmlEscape (Blog { | ||
postCount = 2, | ||
posts = [ | ||
Post { | ||
entryTitle = "This is a post!", | ||
entryContent = HTML $ text $ T.pack "And the contents of that post!" | ||
}, | ||
Post { | ||
entryTitle = "Earlier post...", | ||
entryContent = HTML $ b $ text $ T.pack "Text all bold" | ||
} | ||
] | ||
}) |