After just having a quick discussion with Rich I think the specificity discussion threw me off with regards to the functional aspect of the templates transforming the document.
I'm definitely munging the two together in my examples and, at the time, my expectations. But I think I have a better idea of what's going on / what to expect. Sorry for getting off track there. Cheers, Tom On Feb 12, 1:40 pm, Tom Hickey <thic...@gmail.com> wrote: > Hi Christophe, > > Thank you for the quick reply! > > Snippets > I think what you have suggested for snippets sounds perfect. Using > [selector to single out this snippet] from within a file is definitely > way better then what I was envisioning. I think having the ability to > define a single snippet as well as multiple at once would both be > useful. > > 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.) > > Selectors & attributes > Thank you for the examples as well as the quick updates! I'll be doing > some testing with these today. > > 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!) > > Selector "specificity" > Your reply here made me pause a little and after running some tests > has me a bit concerned. Although your example employed specificity it > does not seem that the specificity of the rules is the determining > factor. It seems there is a more general overriding rule regarding > updates to the hierarchy. > > 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. Granted, > all of my examples use set-attr, so perhaps there is something about > my use or it's own behavior which is to blame. > > 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. > > Sorry for being long-winded (again). And thanks again for your time on > this! > > Cheers, > Tom Hickey > > Given the following HTML: > <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> > > And the following templates: > > (deftemplate update-links1 "net/cgrand/enlive_html/ > example_links.html" [] > [:.last] (html/set-attr :last "true") > [:a] (html/set-attr :title "links rock!")) > > (deftemplate update-links2 "net/cgrand/enlive_html/ > example_links.html" [] > [:.last :.store] (html/set-attr :type "store") > [:a] (html/set-attr :title "links rock!")) > > (deftemplate update-links3 "net/cgrand/enlive_html/ > example_links.html" [] > [:.last :.store] (html/set-attr :type "store") > [:.last] (html/set-attr :last "true") > [:a] (html/set-attr :title "links rock!")) > > (deftemplate update-links4 "net/cgrand/enlive_html/ > example_links.html" [] > [:body] (html/set-attr :class "special") > [:.last :.store] (html/set-attr :type "store") > [:.last] (html/set-attr :last "true") > [:a] (html/set-attr :title "links rock!")) > > (deftemplate update-links5 "net/cgrand/enlive_html/ > example_links.html" [] > [:.last :.store] (html/set-attr :type "store") > [:.last] (html/set-attr :last "true") > [:a] (html/set-attr :title "links rock!") > [:body] (html/set-attr :class "special")) > > 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>" > > 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>" > > 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>" > > 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>" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---