Hi Christophe,

I was not on the latest version (and I now know that the "download"
button on github does not necessarily give you the latest!). I am now
seeing the differences in output on descendent updates.

I understand about only one rule being applied, and the warning
definitely helps to see this more obviously. Part of me is thinking
about the possibility of chaining templates together for multiple
transformations, but that's just my mind wandering and not a real
problem at the moment. (besides, my eyes tend to glaze over when the
topic of compile-time versus runtime comes up ;)

I still have to test out the selector updates as well as snippets.
Thanks for getting these changes in so quickly!

I hope to have some more feedback for you on Monday.

Cheers,
Tom

On Feb 13, 4:36 am, Christophe Grand <christo...@cgrand.net> wrote:
> Hi Tom,
>
> Tom Hickey a écrit :
>
> > Snippets
> > I think what you have suggested for snippets sounds perfect.
>
> I added defsnippet and defsnippets.
>
> > Setting content & escaping
> > Thanks you for explaining the cases here. Having a better idea of what
> > to expect will help in testing further. (I'm still trying to wrap my
> > head around when I need to unquote or not.)
>
> You need to unquote to pass the matched element to a template-macro (at,
> show, set-attr, remove-attr, text, do->, xhtml-strict and select) but at
> the top level of the right hand form of a rule.
>
> > Before I move on to the next section (which gets quite long) I had a
> > quick question: How do I get/use an elements content? Say for instance
> > I wanted a rule for all <a> tags that wrapped their content in an
> > additional <span> so <a href="blah">my link text</a> would become <a
> > href="blah"><span>my link text</span></a>, how would I accomplish
> > this? (I have a feeling I'm missing something obvious again like I did
> > with set-attr!)
>
> You aren't missing anything, there's nothing like jQuery.wrap.
> But you can easily define your own template-macro:
>
> (html/deftemplate-macro wrap [xml tag & attrs]
>   {:tag tag :attrs (apply hash-map attrs) :content [xml]})
>
> usage:
> (deftemplate wrap-links "net/cgrand/enlive_html/example_links.html" []
>   [:a] (wrap :span :title "wrapper"))
> user=> (apply str (wrap-links))
> "<html><body><ul>
> <li><span title=\"wrapper\"><a
> href=\"http://www.google.com\";>google</a></span></li>
> <li><span title=\"wrapper\"><a href=\"http://www.cnn.com\";
> class=\"news\">cnn</a></span></li>
> <li class=\"last\"><span title=\"wrapper\"><a
> href=\"http://www.apple.com\";>apple</a></span>
> <span title=\"wrapper\"><a href=\"http://store.apple.com\";
> class=\"store\">apple store</a></span></li>
> </ul></body></html>"
>
> > Selector "specificity"
> > I have an example below with a number of permutations but they show
> > that any time an ancestor is updated in the hierarchy, no rules for
> > decedents are applied (whether before or after). And also that once an
> > element is updated, no further rule will be applied to it.
>
> Hmm, currently only one rule is applied per element BUT rules are
> applied on descendants before the update of the ancestor.
> Are you using an old version of Enlive?
>
> The current restriction of only one update per element can certainly be
> relaxed if I found a good policy for handling conflicting updates.
>
> Meanwhile, I added warnings (they can be disabled by setting
> *warn-on-rule-collision* to false):
> user=> (deftemplate update-links2
> "net/cgrand/enlive_html/example_links.html" []
>   [:.last :.store] (html/set-attr :type "store")
>   [:a] (html/set-attr :title "links rock!"))
> Rule collision at: {:tag :a, :attrs {:hrefhttp://store.apple.com,
> :class store}, :content [apple store]}
> between:
>    (html/set-attr :type store)
>    (html/set-attr :title links rock!)
> #'user/update-links2
>
> > In my opinion, it would be great to have rules applied in the order
> > they appear and that rules applied later would see all previous
> > changes to the tree and could find/manipulate/update those elements as
> > desired.
>
> Enlive is not that dynamic: the tree is modified and serialized at
> compile-time hence you can not see the result of changes depending on
> runtime data.
>
> > Here is the output:
>
> > net.cgrand.enlive-html.examples/ (apply str (update-links1))
> > "<html><body><ul><li><a title=\"links rock!\" href=\"http://
> >www.google.com\">google</a></li><li><a title=\"links rock!\" href=
> > \"http://www.cnn.com\"; class=\"news\">cnn</a></li><li last=\"true\"
> > class=\"last\"><a href=\"http://www.apple.com\";>apple</a><a href=
> > \"http://store.apple.com\"; class=\"store\">apple store</a></li></ul></
> > body></html>"
>
> It should work (descendants should be updates) on my box I get:
> user=> (apply str (update-links1))
> "<html><body><ul><li><a title=\"links rock!\"
> href=\"http://www.google.com\";>google</a></li><li><a title=\"links
> rock!\" href=\"http://www.cnn.com\"; class=\"news\">cnn</a></li><li
> last=\"true\" class=\"last\"><a title=\"links rock!\"
> href=\"http://www.apple.com\";>apple</a><a title=\"links rock!\"
> href=\"http://store.apple.com\"; class=\"store\">apple
> store</a></li></ul></body></html>"
>
> > net.cgrand.enlive-html.examples/ (apply str (update-links2))
> > "<html><body><ul><li><a title=\"links rock!\" href=\"http://
> >www.google.com\">google</a></li><li><a title=\"links rock!\" href=
> > \"http://www.cnn.com\"; class=\"news\">cnn</a></li><li class=\"last
> > \"><a title=\"links rock!\" href=\"http://www.apple.com\";>apple</a><a
> > type=\"store\" href=\"http://store.apple.com\"; class=\"store\">apple
> > store</a></li></ul></body></html>"
>
> Only one update per element, first update wins.
>
> > net.cgrand.enlive-html.examples/ (apply str (update-links3))
> > "<html><body><ul><li><a title=\"links rock!\" href=\"http://
> >www.google.com\">google</a></li><li><a title=\"links rock!\" href=
> > \"http://www.cnn.com\"; class=\"news\">cnn</a></li><li last=\"true\"
> > class=\"last\"><a href=\"http://www.apple.com\";>apple</a><a href=
> > \"http://store.apple.com\"; class=\"store\">apple store</a></li></ul></
> > body></html>"
>
> Here I get:
> "<html><body><ul><li><a title=\"links rock!\"
> href=\"http://www.google.com\";>google</a></li><li><a title=\"links
> rock!\" href=\"http://www.cnn.com\"; class=\"news\">cnn</a></li><li
> last=\"true\" class=\"last\"><a title=\"links rock!\"
> href=\"http://www.apple.com\";>apple</a><a type=\"store\"
> href=\"http://store.apple.com\"; class=\"store\">apple
> store</a></li></ul></body></html>"
>
> > net.cgrand.enlive-html.examples/ (apply str (update-links4))
> > "<html><body class=\"special\"><ul><li><a href=\"http://www.google.com
> > \">google</a></li><li><a href=\"http://www.cnn.com\"; class=\"news
> > \">cnn</a></li><li class=\"last\"><a href=\"http://www.apple.com
> > \">apple</a><a href=\"http://store.apple.com\"; class=\"store\">apple
> > store</a></li></ul></body></html>"
>
> > net.cgrand.enlive-html.examples/ (apply str (update-links5))
> > "<html><body class=\"special\"><ul><li><a href=\"http://www.google.com
> > \">google</a></li><li><a href=\"http://www.cnn.com\"; class=\"news
> > \">cnn</a></li><li class=\"last\"><a href=\"http://www.apple.com
> > \">apple</a><a href=\"http://store.apple.com\"; class=\"store\">apple
> > store</a></li></ul></body></html>"
>
> 4 & 5 yield:
> "<html><body class=\"special\"><ul><li><a title=\"links rock!\"
> href=\"http://www.google.com\";>google</a></li><li><a title=\"links
> rock!\" href=\"http://www.cnn.com\"; class=\"news\">cnn</a></li><li
> last=\"true\" class=\"last\"><a title=\"links rock!\"
> href=\"http://www.apple.com\";>apple</a><a type=\"store\"
> href=\"http://store.apple.com\"; class=\"store\">apple
> store</a></li></ul></body></html>"
>
> Can you try with the latest version?
>
> Christophe
>
> --
> Professional:http://cgrand.net/(fr)
> On Clojure:http://clj-me.blogspot.com/(en)
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to