Re: Why do Enlive template functions return a seq instead of a str?
Hi Cody ! On Wed, Jul 15, 2009 at 5:41 PM, cody koeninger wrote: > > On Jul 11, 12:31 pm, Jarkko Oranen wrote > > Forcing them into a single string at the end would wasteful in case > > the user intends to write the output into a stream (which can be done > > a fragment at a time.) Thus, leaving the choice to the user seems like > > a good decision. > > > > Or maybe it's just a lazy seq, in which case using str on it would > > force it to be strict. :) > > Just to clarify . . . in order for this to be useful in practice, > wouldn't the following be necessary: > > 1. Disable buffering in whatever server is being used to send the data > (which in the case of http means losing the content-length header). > fixed-size buffering is useful (and isn't antagonist to the seq of strings approach) and should not be disabled 2. Lazy evaluation of all arguments to the template. I consider a seq of strings as a kind of rope [1]: when I decided to return a seq of strings rather than a single string I was after efficient concat and shared representations, lazyness of those seqs is contingent. Christophe [1] minus indexing but indexing is evil :-) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Why do Enlive template functions return a seq instead of a str?
On Jul 11, 12:31 pm, Jarkko Oranen wrote > Forcing them into a single string at the end would wasteful in case > the user intends to write the output into a stream (which can be done > a fragment at a time.) Thus, leaving the choice to the user seems like > a good decision. > > Or maybe it's just a lazy seq, in which case using str on it would > force it to be strict. :) Just to clarify . . . in order for this to be useful in practice, wouldn't the following be necessary: 1. Disable buffering in whatever server is being used to send the data (which in the case of http means losing the content-length header). 2. Lazy evaluation of all arguments to the template. Otherwise the client isn't going to get any content at all until the entire string has already been forced. . . or am I missing something? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Why do Enlive template functions return a seq instead of a str?
On Mon, Jul 13, 2009 at 11:26 AM, Robert Campbell wrote: > > I need the _exact_ functionality of the "sniptest" function (which > appears to have been removed) in production code. sniptest lives now in http://github.com/cgrand/enlive/blob/master/test/net/cgrand/enlive_html/test.clj I may have been over-zealous when I moved test-related functions into separate files. > I am trying to > create a decorator in compojure that will accept a response body and > modify the styling in various ways. I can just use the old sniptest > definition: > > (apply str (emit* ((transformation [:h1] (content "hey")) (html-src > (:body response) > > but is there a better way? I'm also not sure what emit* does exactly. emit* serialize one or several trees to a seq of strings. 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 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 -~--~~~~--~~--~--~---
Re: Why do Enlive template functions return a seq instead of a str?
Thanks guys, that makes perfect sense to me. I have another Enlive question: I need the _exact_ functionality of the "sniptest" function (which appears to have been removed) in production code. I am trying to create a decorator in compojure that will accept a response body and modify the styling in various ways. I can just use the old sniptest definition: (apply str (emit* ((transformation [:h1] (content "hey")) (html-src (:body response) but is there a better way? I'm also not sure what emit* does exactly. Is it breaking :content values out of lists so they stand alone as strings? BTW, I want to thank you Christophe for making this library. It's everything xslt-driven views were supposed to be, but elegant instead of evil. It's also going to be much nicer for the designers than all the custom tags/embedded code frameworks I've used in the past. Rob On Mon, Jul 13, 2009 at 12:37 AM, Christophe Grand wrote: > Hi ! > > On Sat, Jul 11, 2009 at 7:31 PM, Jarkko Oranen wrote: >> >> On Jul 11, 6:01 pm, Robert Campbell wrote: >> > Hey guys, >> > >> > I'm just curious why Christophe chose to return seq instead of a str >> > for Enlive for his template functions. >> >> Most likely Enlive generates each of those fragments separately; >> Forcing them into a single string at the end would wasteful in case >> the user intends to write the output into a stream (which can be done >> a fragment at a time.) Thus, leaving the choice to the user seems like >> a good decision. > > Yes you are spot on: most of the time the resulting html is wrote into a > stream (disk/network/pipe). > This is also why I modified Ring to accept a seq of string as the body of a > http response. > > 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 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 -~--~~~~--~~--~--~---
Re: Why do Enlive template functions return a seq instead of a str?
Hi ! On Sat, Jul 11, 2009 at 7:31 PM, Jarkko Oranen wrote: > On Jul 11, 6:01 pm, Robert Campbell wrote: > > Hey guys, > > > > I'm just curious why Christophe chose to return seq instead of a str > > for Enlive for his template functions. > > Most likely Enlive generates each of those fragments separately; > Forcing them into a single string at the end would wasteful in case > the user intends to write the output into a stream (which can be done > a fragment at a time.) Thus, leaving the choice to the user seems like > a good decision. Yes you are spot on: most of the time the resulting html is wrote into a stream (disk/network/pipe). This is also why I modified Ring to accept a seq of string as the body of a http response. 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 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 -~--~~~~--~~--~--~---
Re: Why do Enlive template functions return a seq instead of a str?
On Jul 11, 6:01 pm, Robert Campbell wrote: > Hey guys, > > I'm just curious why Christophe chose to return seq instead of a str > for Enlive for his template functions. > > Example: > > (deftemplate my-page-transformation "index.html" [message style] > [:style] (content style) > [:h1] (content message)) > > orchid> (my-page-transformation "my wonderful header" "h1 { color: blue }") > ("" "\n\t" "" "\n\t\t" "" "h1 { color: blue }" > "" "\n\t" "" "\n\t" "" "\n\t\t" "" "test" > "" "\n\t" "" "\n" "") > > It's trivial to call (apply str (my-page..)) but I'm just curious > about the thinking behind using a seq. Is it related to xml-seq and > traversing the tree? > Most likely Enlive generates each of those fragments separately; Forcing them into a single string at the end would wasteful in case the user intends to write the output into a stream (which can be done a fragment at a time.) Thus, leaving the choice to the user seems like a good decision. Or maybe it's just a lazy seq, in which case using str on it would force it to be strict. :) > Thanks, > > Rob -- Jarkko --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Why do Enlive template functions return a seq instead of a str?
Hey guys, I'm just curious why Christophe chose to return seq instead of a str for Enlive for his template functions. Example: (deftemplate my-page-transformation "index.html" [message style] [:style] (content style) [:h1] (content message)) orchid> (my-page-transformation "my wonderful header" "h1 { color: blue }") ("" "\n\t" "" "\n\t\t" "" "h1 { color: blue }" "" "\n\t" "" "\n\t" "" "\n\t\t" "" "test" "" "\n\t" "" "\n" "") It's trivial to call (apply str (my-page..)) but I'm just curious about the thinking behind using a seq. Is it related to xml-seq and traversing the tree? Thanks, Rob --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---