Hacker News new | ask | show | jobs
by asmala 4961 days ago
Based on my experience, Hiccup is more productive than just about anything else if the frontend person is the backend person or otherwise comfortable with Clojure. The ability to easily and cleanly define and combine abstractions in the presentation layer has been big productivity boost for me as a solo developer.

As a concrete example, a small hobby project I did resulted in a fairly comprehensive library of Bootstrap helpers with very little effort:

* https://github.com/asmala/giddyup

I don't have much experience with Enlive but I find the approach is intriguing. On paper it seems perfect for clean separation of markup and logic, but you're right that careless use of the library leads to tight coupling due to the selector naming. I wonder if it would be possible to circumvent this issue using custom HTML attributes or even pseudo-CFML custom tags to indicate logical units in HTML?

1 comments

Enlive's author here. I prefer to think of templates as a mapping between data and presentation. When the HTML provided by the designers changes drastically you only need to update selectors in your templates and be done with it. The same is true of the data you pass to templates: when the schema change you have to change the template. A template is both a contract on some properties of the input HTML provided by the designer and on the input data provided by the logic layer.
Gotcha. How would you handle minor HTML changes, e.g. something like this:

  <!-- Original -->
  <span class="username">joe</span>
  
  <!-- New -->
  <span class="username"><strong>joe</strong></span>
Updating the selector in the template is easy enough but seems a bit tedious if the design team decides to go for italics next week. Another option would be adding another CSS class or a data attribute to indicate which element should wrap username.

How do you usually handle such scenarios?

By doing such a change they violates their contract. Can't you negotiate an alternative change? Eg the strong around the span or using styles instead of strong or move the username class to the strong tag?

Anyway if you really want to program defensively against such changes, roll your own replacement to content fn which would replace the cornets not of the current node but of all its terminal descendants.

I'd like to know more about your workflow.

My example above was possibly too simplistic. I'm not using Enlive at the moment but am merely trying to gauge what kinds of contracts would allow the developers and designers work together most efficiently. I can imagine a fairly big difference between, for example, the following two contracts:

a) "Don't touch the markup without an explicit agreement between the two of us."

b) "Please make sure you have an element with a data-content-for='user.username' somewhere in the HTML."

More often than not it's a variation of b) not involving custom attrs (a matter of taste). It's the same kind of contracts you have to set up if you are also doing some heavy JS anyway.

Sometimes the design is forced upon the team (eg corporate intranet) and then one has to resort to ugly and brittle selectors but still I prefer that to slicing and dicing the design to add loops and conditionals – especially when the intranet's corporate branding change every 9 months :-/

(Thanks for rewording your reply)