7 ms·
HTML isn't meant to handle presentation. Ideally, it's a way of marking up content to allow an arbitrary presentation layer to be laid on top. I prefer generat
by weavejester 17y ago
HTML isn't meant to handle presentation. Ideally, it's a way of marking up content to allow an arbitrary presentation layer to be laid on top.
I prefer generating HTML content through s-expressions. It's more flexible and concise than a templating library, and it forces you to bear in mind the separation of content and presentation. In turn, this makes it easier to unit-test the views, and to write automated integration tests.
For instance, if I were a designer writing a template, I have control over both the CSS and the HTML. This might tempt me to write the HTML around a particular design:
<div class="post">
<div class="small">
<%= post.points %> points by <%= author.name %>
</div>
</div>
But if I am a programmer, without necessarily much knowledge of the presentation, I might be more careful to write more semantic HTML that's presentation-neutral.
[:div.post {:id (str "post-" (:id post))}
[:div.header
[:span.points (:points post)]
" points by "
[:span.author (:name author)]]
Which has the useful side effect of making it easier to write tests:
(is (= (css-select "#post-1 .author" (:body response))
"Test User"))