Permalink
Browse files

Merge branch '0.10' of git://github.com/adinapoli/snap-website

  • Loading branch information...
2 parents 8cd1e5a + 53179e7 commit 0b927437c7077090e67a20b72a4200a445d3a741 @mightybyte mightybyte committed Nov 25, 2012
View
@@ -1,5 +1,5 @@
Name: snap-website
-Version: 0.8
+Version: 0.10
Synopsis: The Snap Framework Website
Homepage: http://snapframework.com
License: BSD3
@@ -23,11 +23,11 @@ Executable snap-website
data-lens-template >= 2.1 && < 2.2,
directory,
filepath,
- heist >= 0.7 && < 0.9,
+ heist >= 0.10 && < 0.11,
MonadCatchIO-transformers >= 0.2 && < 0.4,
mtl >= 2 && <3,
process,
- snap >= 0.9 && <0.10,
+ snap >= 0.10 && <0.11,
snap-core >= 0.9 && <0.10,
snap-blaze >= 0.2.1 && <0.3,
snap-server >= 0.9 && <0.10,
@@ -169,7 +169,7 @@ template:
~~~~~~~~~~~~~~~
-### The `<content>` tag
+### The `<apply-content>` tag
Sometimes it is useful to pass information (usually in the form of HTML
data) into the template when it is applied so the template can insert
@@ -179,7 +179,7 @@ not just static blocks of code.
In our previous example, we did not pass any parameters to the `nav`
template when it was applied, so the `<apply>` tag was empty. If we
include data inside the body of the `<apply>` tag, the template being
-called can access this data with the `<content>` tag. The following
+called can access this data with the `<apply-content>` tag. The following
simple example illustrates this concept. We create a site template
called `default.tpl`:
@@ -193,7 +193,7 @@ called `default.tpl`:
<h1>XYZ Inc.</h1>
</div>
<div id="content">
- <content />
+ <apply-content />
</div>
<div id="footer">
<p>Copyright XYZ Inc</p>
@@ -203,7 +203,7 @@ called `default.tpl`:
~~~~~~~~~~~~~~~
-The `<content>` tag "pulls in" the page content from the calling
+The `<apply-content>` tag "pulls in" the page content from the calling
template and inserts it into the content `<div>`.
Now we have a template for our home page called home.tpl:
@@ -253,9 +253,9 @@ illustrates the power of a simple concept like `apply`.
What if, in the above example, we decided that the contents of the
header div should be different for different pages? To do this, we
need a way to pass multiple parameters into a template. Heist
-provides this capability with the `<bind>` tag. Inside the body of a
+provides this capability with the `<bind-content>` tag. Inside the body of a
`<apply>` tag, you can have multiple bind tags surrounding data to be
-passed as separate parameters. Each `<bind>` tag must have a `tag`
+passed as separate parameters. Each `<bind-content>` tag must have a `tag`
attribute that provides a name for its contents just as described
above. Then, inside the template, those tags will be substituted with
the appropriate data.
@@ -283,33 +283,33 @@ to allow multiple parameters.
~~~~~~~~~~~~~~~
-And `home.tpl` uses the `<bind>` tag with a name attribute to define
+And `home.tpl` uses the `<bind-content>` tag with a name attribute to define
values for the `<header/>` and `<main/>` tags:
~~~~~~~~~~~~~~~ {.html}
<apply template="default">
- <bind tag="header">
+ <bind-content tag="header">
<h1>XYZ Inc.</h1>
- </bind>
+ </bind-content>
Some in-between text.
- <bind tag="main">
+ <bind-content tag="main">
<h1>Home Page</h1>
<p>Welcome to XYZ Inc</p>
- </bind>
+ </bind-content>
</apply>
~~~~~~~~~~~~~~~
The result template for this example is the same as the previous
example.
-NOTE: In this example the `<content/>` tag is still bound as described
-above. The `<content/>` tag is always bound to the complete contents
-of the calling `apply` tag. However, any `bind` tags inside the apply
+NOTE: In this example the `<bind-content/>` tag is still bound as described
+above. The `<bind-content/>` tag is always bound to the complete contents
+of the calling `apply` tag. However, any `bind-content` tags inside the apply
will disappear. If we changed `default.tpl` to the following:
~~~~~~~~~~~~~~~ {.html}
<foo>
- <content/>
+ <bind-content/>
</foo>
~~~~~~~~~~~~~~~
@@ -409,7 +409,8 @@ The following is code for a splice that calculates the factorial of a
number.
~~~~~~~~~~~~~~~ {.haskell}
-import Text.Templating.Heist
+import Heist
+import Heist.Interpreted
import qualified Data.Text as T
import qualified Text.XmlHtml as X
@@ -103,7 +103,7 @@ The next thing we need to do is define an initializer.
> , ("/barname", with bar namePage)
> , ("/company", companyHandler)
> ]
-> wrapHandlers (<|> heistServe)
+> wrapSite (<|> heistServe)
> ref <- liftIO $ newIORef "fooCorp"
> return $ App hs fs bs ref
@@ -167,10 +167,10 @@ monad. It has a `MonadState` instance that lets you access and modify the
current snaplet's state, and a `MonadSnap` instance providing the
request-processing functions defined in Snap.Types.
-wrapHandlers
+wrapSite
------------
-`wrapHandlers` allows you to apply an arbitrary `Handler` transformation to
+`wrapSite` allows you to apply an arbitrary `Handler` transformation to
the top-level handler. This is useful if you want to do some generic
processing at the beginning or end of every request. For instance, a session
snaplet might use it to touch a session activity token before routing happens.
@@ -4,7 +4,7 @@
<div class="inner-page">
<div class="newspaper">
- <content/>
+ <apply-content/>
</div>
</div>
@@ -4,7 +4,7 @@
<body>
<div id="main">
<apply template="nav"/>
- <content />
+ <apply-content />
</div><!--end main-->
<div id="footer">
<p class="part-1">Powered by <b>Snap <snap-version/></b></p> <p class="part-2">Snap is <a rel="license" href="http://creativecommons.org/licenses/BSD/">BSD
View
@@ -28,7 +28,8 @@ import Snap.Util.FileServe
import Snap.Util.GZip
import Text.Blaze.Html5 (toHtml)
import qualified Text.Blaze.Html5 as H
-import Text.Templating.Heist
+import Heist
+import Heist.Interpreted
data App = App
{ _heist :: Snaplet (Heist App)
@@ -56,11 +57,11 @@ undirify = do
appInit :: SnapletInit App App
appInit = makeSnaplet "snap-website" description Nothing $ do
hs <- nestSnaplet "" heist $ heistInit "templates"
- bs <- nestSnaplet "blog" blog $ staticPagesInit "blogdata"
+ bs <- nestSnaplet "blog" blog $ staticPagesInit hs "blogdata"
addSplices [ ("snap-version", serverVersion)
- , ("feed-autodiscovery-link", liftHeist $ textSplice "")
+ , ("feed-autodiscovery-link", textSplice "")
]
- wrapHandlers (\h -> catch500 $ withCompression $
+ wrapSite (\h -> catch500 $ withCompression $
undirify >> h <|> setCache (serveDirectory "static"))
return $ App hs bs
where
@@ -98,8 +99,8 @@ catch500 m = (m >> return ()) `catch` \(e::SomeException) -> do
setResponseStatus 500 "Internal Server Error" emptyResponse
-serverVersion :: SnapletSplice b v
-serverVersion = liftHeist $ textSplice $ decodeUtf8 snapServerVersion
+serverVersion :: SnapletISplice b
+serverVersion = textSplice $ decodeUtf8 snapServerVersion
main :: IO ()

0 comments on commit 0b92743

Please sign in to comment.