Updating to reflect last changes:
(def snipgets
(let [divs (select (html-resource "widget.html")
[[:div (attr? :tiptree:widget)]])]
(into {}
(for [div divs]
[(-> div :attrs :tiptree:widget)
(snippet div [root]
[widget]
[:div.value] (content (if widget
(:value widget)
"foo")))))))
Christophe Grand a écrit :
> select, snippet, at and template are macro sugar. If you _really_ want
> to use first-class selectors then you'll have to deal directly with
> states machines and use at*, select* and snippet* (I'm going to improve
> their usability).
>
> While selectors aren't first class, they can be parametrized (as you did
> in [[:div (attr= :tiptree:widget (str widgetType))]]). You can play with
> compile-selector to see how selectors are expanded.
>
> Regarding your code, I'd like to warn you against using snippet like
> that for performance reason (and it won't get any better when I make
> templates rendering faster).
> It's better to extract snippets once for all:
>
> (def snipgets
> (let [divs (mapcat #(select % [[:div (attr? :tiptree:widget)]])
> (html-resource "widget.html"))]
> (into {}
> (for [div divs]
> [(-> div :attrs :tiptree:widget)
> (snippet div [root]
> [widget]
> [:div.value] (content (if widget
> (:value widget)
> "foo")))))))
>
> (deftemplate my-app6 "app2.html"
> [widgets]
> [[:div (attr? :tiptree:replace)]]
> (fn [node]
> (let [widgetType (:tiptree:replace (:attrs node))]
> ((snipgets widgetType) ((keyword widgetType) widgets)))))
>
>
> David Nolen a écrit :
>
>> On second thought, this is actually not that critical for what I'm
>> trying to accomplish, and I'm not sure yet if I'll ever use such a
>> feature. Macros that define snippets will probably suffice.
>>
>> (deftemplate my-app6 "app2.html"
>> [widgets]
>> [[:div (attr? :tiptree:replace)]]
>> (fn [node]
>> (let [widgetType (:tiptree:replace (:attrs node))]
>> ((snippet "widget.html" [[:div (attr= :tiptree:widget (str widgetType))]]
>> [widget]
>> [:div.value] (content (if widget
>> (:value widget)
>> "foo")))
>> ((keyword widgetType) widgets)))))
>>
>> (apply str
>> (my-app6 {:widgetA {:value "0"},
>> :widgetB {:value "1"}}))
>>
>> Works for me, and this was in general the use case I was thinking of.
>>
>>
>> On Thu, Apr 16, 2009 at 4:24 PM, David Nolen <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>> Because predicates in selectors no longer need to be quoted it
>> seems you can't use Enlive selectors in a first class way with
>> snippets:
>>
>> (let [aselector [[:div (attr= :tiptree:widget "widgetA")]]]
>> ((snippet "widget.html" aselector
>> [some-map]
>> [:div.value] (content "foo")) {}))
>>
>> I believe this might be one of my final big requests :) I
>> personally don't mind the quoted predicate forms, especially if
>> this would simplify making selectors first class. This would
>> allow templates to dynamically generate snippets based on the
>> properties of a particular node.
>>
>> There's been a wild flurry of updates to Enlive recently and I am
>> extremely excited about the possibilities. Enlive is an idea
>> which should be ripped off by every web framework worth talking
>> about! ;) Thanks again for creating and maintaining it.
>>
>> On Thu, Apr 16, 2009 at 7:15 AM, Christophe Grand
>> <[email protected] <mailto:[email protected]>> wrote:
>>
>>
>> Tom,
>>
>> The redesign is nearly over (at least from a user standpoint),
>> you may
>> want to check it http://github.com/cgrand/enlive/tree/right
>>
>> Christophe
>>
>> Tom Hickey a écrit :
>> > Hi Christophe,
>> >
>> > I keep running into the same problem with elements getting
>> replaced.
>> > I'm trying to set the content of an element with raw html
>> (from a
>> > snippet) and unable to avoid both 1) the html getting
>> escaped and 2)
>> > the element getting replaced. I can avoid one or the other, via
>> > escaped or text, just not both.
>> >
>> > I'm looking forward to see what you've got planned for the
>> redesign,
>> > as I'd really like to see this "feature" go away.
>> >
>> > Cheers,
>> > Tom
>> >
>> > On Mar 20, 3:59 am, Christophe Grand <[email protected]
>> <mailto:[email protected]>> wrote:
>> >
>> >> Phil Hagelberg a écrit :
>> >>
>> >>
>> >>> But I did notice you have the use test-is line commented
>> out in the
>> >>> implementation; it seems a bit unfortunate to have to
>> uncomment that to
>> >>> run the tests and hope you remember to re-comment it
>> before you commit.
>> >>>
>> >> The last commit was during the transition to lazy-seq and
>> test-is was
>> >> broken.
>> >> I'll fix that.
>> >>
>> >> --
>> >> Professional:http://cgrand.net/(fr)
>> <http://cgrand.net/%28fr%29>
>> >> On Clojure:http://clj-me.blogspot.com/(en)
>> <http://clj-me.blogspot.com/%28en%29>
>> >>
>> > >
>> >
>> >
>>
>>
>> --
>> Professional: http://cgrand.net/ (fr)
>> On Clojure: http://clj-me.blogspot.com/ (en)
>>
>>
>>
>>
>>
>>
>>
>>
>
>
>
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---