I replied to this a long time ago and in the original case - I did not see 
huge value in the suggestion. But recently I wanted to do exactly what 
Murtaza suggests.

There are a couple of reasons why I think this capability would be useful. 
(And rereading Murtaza's email - I think this is what he meant)

1. The functions defined in hiccup and other libraries are not portable. if 
you rely on these, they will only work if the library maintained has copied 
the function interface exactly. This is not always the case. (as a separate 
comment these utility functions 
would be better separated from the rendering code).

2. I would be great to write markup that describes your domain, not HTML so
[:address :street "here" :city "there"]

rather than [:div ....lots of html specific bits ... street...]

3. It would be great to be able to switch the rendering of your domain 
without editing the overall markup structure.

4. if webcomponents take off - which I hope they do - you may be able to 
gracefully transition by disabling the various tag rewriting again, not 
touching the main markup logic.

So I had a look to see if this can be done - and it can - relatively 
easily. 
I implemented it the easiest way initially - but there are alternative 
possibilities for how this might work. Currently it uses a multimethod - 
but it might be better to pass in "tag expanding functions" when rendering 
- this would be more flexible.

The changes to hiccup to achieve this are quite minor.

See here: https://github.com/davesann/hiccup/commit/custom-tags

I added a basic repl example file
https://github.com/davesann/hiccup/blob/custom-tags/repl/example.clj

A nice thing here is that incompatibilities between hiccup and cljs 
equivalents could be mitigated if we could agree on a "standard" for 
allowing custom tags.

Thoughts anyone?

Dave








On Monday, 14 May 2012 00:31:48 UTC+10, Walter Tetzner wrote:
>
> You could do this without adding anything to hiccup.
>
> If you wrote a function that, say, used walk, you could have it go
> through the vectors, and replace the custom tags with what they
> represent. Then you could just call that before calling `html'.
>
> (html
>   (transform
>     [:html
>       [:head
>         [:title "some page"]]
>       [:body
>         [:link-to {:url "http://www.google.com/"} "Hi this is Google"]]]))
>
> The benefit to doing it this way over having the macro is that it's
> clear where the custom tags come from when looking at the invocation
> of `html'.
>
> If you really want `html' to handle it, maybe it could be called with
> a map of tranform functions?
>
> (html {:link-to link-to}
>  [:html
>    [:head
>      [:title "some page"]]
>   [:body
>     [:link-to {:url "http://www.google.com/"} "Hi this is Google"]]])
>
> Either way, I think this ends up being nicer than a macro that changes
> the behavior of `html'.
>
>
> On Sunday, May 13, 2012 12:35:46 AM UTC-4, Murtaza Husain wrote:
>>
>>
>>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to