Skip to content

Commit

Permalink
Improve README
Browse files Browse the repository at this point in the history
  • Loading branch information
soficshift committed Jul 6, 2024
1 parent 9aaea69 commit 48b33cb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The main idea is to reuse existing libraries that will provide the target langu

For instance, this is how you could define an if/else expansion with ~Ondim~:
#+begin_src haskell
ifElse :: (Monad m, OndimNode t) => Bool -> Expansion m t
ifElse :: (OndimNode t) => Bool -> Expansion s t
ifElse cond node = do
let els = children node
yes = filter ((Just "else" /=) . identify) els
Expand All @@ -20,10 +20,10 @@ ifElse cond node = do
else expandSubs no
#+end_src

Now, suppose you have a variable ~isCat :: Bool~ and you want your templates to choose between two snippets depending on its value. Such HTML template could have type ~[HtmlNode]~, so that if you "lift" it into the Ondim monad binding ~ifElse isCat~ to the name ~if-cat~,
Now, suppose you have a variable ~isCat :: Bool~ and you want your templates to choose between two snippets depending on its value. Such HTML template could have type ~[HtmlNode]~, so that if you expand it while binding ~ifElse isCat~ to the name ~if-cat~,

#+begin_src haskell
liftNodes myTemplateContent
expandNode myTemplateContent
`binding` do
"if-cat" #* ifElse isCat
#+end_src
Expand All @@ -41,7 +41,7 @@ you can now write in your HTML templates...

...and the output will depend on the value of ~isCat~.

The beauty of ondim (and one aspect that takes it further from Heist) is that the ~ifElse~ splice is polymorphic on the format type, so the same code works for formats other than HTML. If you want to template JSON, the same code above would work if src_haskell{myTemplateContent} had type src_haskell{[Value]}, and a similar template could be written as:
The beauty of ondim (and one aspect that takes it further from Heist) is that the ~ifElse~ splice is polymorphic on the format type, so the same code works for formats other than HTML. If you want to template JSON, the same code above would work if ~myTemplateContent~ had type ~[Value]~, and a similar template could be written as:
#+begin_src yaml
- $: if-cat
$children:
Expand Down

0 comments on commit 48b33cb

Please sign in to comment.