Hello David, David Nolen a écrit : > Considering the above, I'm left wondering if it's possible to further > eliminate these redundancies and make templates more reusable. I'm not > sure if this is what you had in mind for Enlive, but allowing > templates to be created without references to files would make it > possible to build very, very composable interfaces. > Of course it's quite possible that you can already do this with Enlive > and I'm just unclear about how to accomplish it.
I'm sorry for the lack of documentation. The "source" of a template/snippet can either be: - a string (a resource path resolved by the classloader) - a File, URI or URL, - a map (a "literal" xml/html tree). A template is a function that returns a seq of strings. (It's the end of the "pipeline".) A snippet is a function that now (in the "new" enlive) returns a seq of nodes. (I suppose I should add "seq of nodes" as a valid source type.) Snippets are valid values on the right-hand side of rules. The only difference between templates and snippets is that templates serialize their return value. > This is great. I had thought that supporting some kind of partial > template thing would be interesting, but that's actually just my poor > logic at work ;) > > It seems like with the new version of Enlive I could do something like > this: > > (deftemplate pageA-template path > [] > [[:div (attr? :tiptree:replace)]] (fn [xml-node] > (find-the-widget-html-file-that-corresponds-to-a-certain-attr-and-return-as-result))) > > (deftemplate pageB-template path > [] > [[:div (attr? :tiptree:replace)]] (fn [xml-node] > (find-the-widget-html-file-that-corresponds-to-a-certain-attr-and-return-as-result))) > > (def pageAPartial (pageA-template)) > (def pageBPartial (pageB-template)) > > ;; the following would work only if templates allowed passing html as > strings and not just as files > > (deftemplate widgetsPageA pageAPartial > [map] > [[:div (attr? :tiptree:widget)]] (fn [xml] > (use-xml-attr-and-map-to-apply-and-return-a-snippet)) > > (deftemplate widgetsPageB pageBPartial > [map] > [[:div (attr? :tiptree:widget)]] (fn [xml] > (use-xml-attr-and-map-to-apply-and-return-a-snippet)) > > (def pageA (widgetsPageA someMap)) > (def pageB (widgetsPageA someMap)) > I suppose you really want to break the computation in two and not write: (deftemplate pageA-template path [map] [[:div (attr? :tiptree:replace)]] (fn [xml-node] (find-the-widget-html-file-that-corresponds-to-a-certain-attr-and-return-as-result)) [[:div (attr? :tiptree:widget)]] (fn [xml] (use-xml-attr-and-map-to-apply-and-return-a-snippet))) or: (deftemplate pageA-template path [map] [[:div (attr? :tiptree:replace)]] (do-> (fn [xml-node] (find-the-widget-html-file-that-corresponds-to-a-certain-attr-and-return-as-result)) (fn [xml] (use-xml-attr-and-map-to-apply-and-return-a-snippet)))) (well, it would work if do-> has been ported to the new enlive) Keeping in mind the difference between a snippet and a template, you will be able to do what you describe with the new enlive once I implement 'attr? and add support for seq of nodes as a valid source type. hth, Christophe --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---