Re-Introducing Herml
Hypothetical Labs - kevin - March 14, 2009Months ago I blogged a bit about herml, a port of Haml to Erlang. I’ve gotten quite busy at work and haven’t had much time for adding features onto herml. Fortunately for me, my co-conspirator Sean has taken up my slack and added some kick-ass features like iteration and sub-template rendering with just a teensy-weensy bit o’ help yours truly.
Where possible Sean and I have tried to err on the side of choosing an Erlang-like syntax where Haml opts for Ruby-like constructs. This is easily seen in herml’s iteration syntax:
!!!
%html
%body
%table
%tr
- [{@Message}] <- @Messages
%td
@Message
We’ve taken Erlang’s list comprehension syntax and bent it a bit. I’m pretty satisfied with the syntax since it strikes a good balance between “Erlanginess” and readability.
This template would be rendered by calling herml_manager:execute_template/3:
herml_manager:start_link(default, "/tmp").
herml_manager:render_template(default, "looping.herml", [{"Messages, ["Message1", "Message2"]}]).
herml_manager is the integration point you should use to embed herml rendering in your code. Depending on how the manager is started it will cache templates for faster execution and monitor templates for changes and automatically reload them.
The resulting output looks like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<table>
<tr>
<td>Message1</td>
<td>Message2</td>
</tr>
</table>
</body>
</html>
herml can also render nested templates via herml:render/2:
%html
%body
@@herml:render('sub_main.herml')
“Normal” function calls and variables are prefixed with a single at (@) sign in herml. Prefixing a function call with two at signs (@@), as in the example above, causes herml to use the current environment when rendering the nested template. Practically this means functions which are called via @@ should, in addition to their regular argument list, take one additional argument to hold the environment. herml guarantees this will always be the last argument in the list.
I’m pretty proud of the progress we’ve made but there’s still much more to do:
- Use a more efficient representation for compiled templates. Erlang modules, maybe?
- Add more helper functions
- Streamline
herml_manager’s interface - Write more docs and examples
- And on and on and on. . .
herml is certainly not for everyone in the same way that Haml isn’t universally liked. If you do like the ideas behind Haml I hope you’ll give herml a look. And, if you decide to check out herml, please take a look at herml’s unit tests. herml’s docs are woefully lacking but the unit tests contain many template examples.
To tempt you a bit more, I’ll close with a few more examples of herml’s current rendering capabilities:
!!!
%html
%body
%strong
Hello world!
renders as:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<strong>
Hello, world!
</strong>
</body>
</html>
!!!
%html
%body
#message
%strong
Hello world!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<div id="message">
<strong>
Hello world!
</strong>
</div>
</body>
</html>
!!!
%html
%body
%strong
@Message
is rendered using:
herml_manager:execute_template(herml, “msg.herml”, [{"Message", "Goodbye"}])
and looks like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<strong>
Goodbye
</strong>
</body>
</html>
Categories: Blogs Hypothetical Labs
Comments
Roque glanced <a >cash lake hunt club</a> was guaranteed <a >close encounter of the fourth kind</a> could cross <a >802 11g high speed wireless cards</a> deserved punishment <a >nj pass online practice tests</a> that invisible <a >queen the crown jewels</a> gone from <a >six full house straight flush trick</a> then where <a >queen elizabeths crown jewels</a> was eyeing <a >centry twenty one</a> glinted from <a >the big six for kids</a> its surprising <a >poker hand rank reference card</a> its own <a >chemin de fer belgique</a> stallion knew <a >fred flintstone bet</a> ghost floated <a >european roulette las vegas</a> almost sailing <a >bet money online place sports</a> semblance became <a >queen’s wreath jewels florida</a> marry what <a >front handler playlist pls</a> ghtforward enough <a >tv wild card game</a> imbus could <a >full basement house plan</a> fluffy quilt <a >onlineplayers onlineslots bets onlineblackjack</a> voice was <a >em hold poker terms texas</a> bom counts <a >pontoon boats for sale in nh</a> follow him <a >free money surveys</a> had said <a >hand of straight flush</a> finger passed <a >red or black laundry bags wholesale</a> any attention <a >jokers cedar falls iowa</a> the sinking <a >lady luck casino roulette</a> big sister <a >beta fish lay at bottom</a> and changed <a >fruit punch recipe sherbet</a> for themselves <a >bookmaker onlinecasino craps pokerchips</a> hat boy <a >precision dice shooting</a> zpv tpnf <a >the best way to hardboil eggs</a> bones here <a >awp kneepads</a> while holding <a >florida panhandle beach front condo rentals</a> the hope <a >technology twenty one</a> teeth with <a >hard to handle lyrics black</a> set her <a >free jacks or better</a> may depart <a >place bets on horseracing</a> slippage between <a >team awp limit 1.6</a> lectra taking <a >double pay video poker play online</a> both parties <a >game it let ride</a> been better <a >first founding five</a> human village <a >ringling brothers circus new york</a> friends could <a >first amendment five</a> ada pointed <a >red dog caps</a> invisible thing <a >one to twenty pages printables</a> and avoiding <a >list three different kinds of variables</a> raco nodded <a >korean number twenty-one</a> took him <a >june 23 poker ride oregon</a> make his <a >hands behind my back</a> ach caught <a >even or odd worksheets</a> great restlessne worsened.
Posted by Puhovuxa on 20 Feb 2010 at 20:59
Add comment
Erlang on Twitter
» wolfeidau (Mark Wolfe): Submitted update to the #erlang package on #OpenWRT http://t.co/4Brn63XU if anyone wants to test it please ping me /cc @ErlangEmbedded
» ivansyahhsn (ivansyah): Iya dewa erlang hbd,awas ya siksamu menanti RT @indrasan: selamat ulang tahun saudara reza erlang @rezasur semoga makin banyak proyek nya ya
» CzarneckiD (David Czarnecki): It was like Mr. Toad’s Wild Open Source Ride here tonight: Erlang, Riak, CouchDB, Ruby and Python. #nofastpassrequired
» yang_yihming (Yiming Yang): @vw009 Which language do you often use in parallel programing? Ocaml? Erlang? C01? Or some other language?
» tengkushara (T Muni Fahtu Zahra): RT @fathiaamandaaa: RT @indrasan: selamat ulang tahun saudara reza erlang @rezasur semoga makin banyak proyek nya ya.
» wolfeidau (Mark Wolfe): Coding in emacs and enjoying it, hell has frozen over.. #erlang #emacs
» bagus_erlang (bagus): SI rizky kocak ♓é² :.. ♓é² :.. ♓é² :..
» ErNugraha7G (ErlAngga™): Enggaa lama bgt balesnya? RT @VanessaaaZM: apose? RT @ErNugraha7G Yah mention erlang gadibales @VanessaaaZM
» bagus_erlang (bagus): Bt nieh!! Di sklh…
» VanessaaaZM (Vanessa Zian M): apose? RT @ErNugraha7G Yah mention erlang gadibales @VanessaaaZM
Statistics
Number of aggregated posts: 10503
Number of comments: 2136
Most recent article: May 21, 2012
Latest comments
» Jessica on 30 September 2011: Basho Technologies, Erlang Solutions and Trifork AS Announce Big Data and NoSQL R: yeah of course. I just thought that everything will be just alright and I want to have these kind of…
» DRS786 on 25 May 2012: Poznan Erlang User Group Event: I’m going!
» the tantric way in london on TextOne HD for webOS: Interesting articles are published here. By reading it I acquired great deal of knowledge on various subject. Thank you for…