The genius of Enlive as a template system
github.com
github.com
<?php
for($i = 0; $i < $len; $i++) {
?><p>Foo <?echo $i?></p><?
}
?>
vs <? foreach($foo as $i): ?>
<p>Foo <?= $i ?> </p>
<? endforeach ?>
I understand you want to sell your project, but don't make the examples deceiving. ~$ python
>>> A = "<?php for($i = 0; $i < $len; $i++) { ?><p>Foo <?echo $i?></p><? } ?>"
>>> B = "<? foreach($foo as $i): ?> <p>Foo <?= $i ?> </p> <? endforeach ?>"
>>> L = [A,B]; import re
>>> map(len, L)
[68, 65]
>>> map(lambda x: len([s for s in x if re.match('\w', s)]), L)
[23, 29]
Isn't it about the same amount of alphanum vs noise? About the same length too.I'm not sure B is more readable than A in any way. Maybe more 'idiomatic', meaning 'way humans think'; but I'm not sure about that.
(Incidentally, though, the <?= tags are now considered a fundamental feature and not part of the short tags syntax, so you can use those everywhere.)
https://github.com/cgrand/enlive/issues?state=open
I got hit by a bug the other day (it assumes http resources are UTF8), and even though fixes are available, none have been merged in.
See also "Is Enlive Alive?"
https://groups.google.com/forum/?fromgroups=#!topic/enlive-c...
Having said that, I still think Enlive is awesome. I just which development was more active. Take a look at the network graph and you'll see people fixing a lot of issues on their own branches.
Even in Javascript traditional templates have seen a surge in popularity, even though push-style templates have always been the more natural way to operate (in the case of Javascript, modifying the DOM directly).
Of course, then it's on you as a developer to use Enlive to replace whatever stub/sample elements are present in the HTML with real data, so it's not an entirely free lunch.
<ul>
<li class="item-template">
<a href="#" class="item-link-template"><strong class="item-caption-template">Some dummy caption</strong></a>
— <span class="item-description-standin">Some dummy description</span>
</li>
</ul>
The item-template marks the outer-most element to use for repetition. The item-link-template can be used to set the href attribute. The contents of the tag marked with item-caption-template will be replaced with whatever content. The item-description-standin gets replaced with content outright. If you, say, want to remove the <strong> tags around the caption, just move the templating class to the parent item. <ul>
<li class="item-template">
<a href="#" class="item-link-template item-caption-template">Some dummy caption</a>
— <span class="item-description-standin">Some dummy description</span>
</li>
</ul>
If you come up with some conventions, e.g. "-standin" gets replaced completely, whereas "-template" just gets transformed; each marker is only used for one purpose (don't conflate the link and the caption marker in the latter example), it works rather well, probably better than any other templating system I've used.My only gripes with Enlive at the time were that it was overly macro-heavy (def'ing everything as opposed to returning values), and loading templates was quite slow, which made on-the-fly modifications to HTML generated elsewhere ineffecient. I suspect both are better these days, as it was still heavily in development at the time.
I have never understood why someone would another abstraction layer to templating.