Re: [racket] Ensuring data fed to web-server/templates is textual
On Feb 8, 2012, at 10:17 AM, Jay McCarthy jay.mccar...@gmail.com wrote: web-server/templates uses scribble/text So, if you return a function, then it will be called. I'm not sure I understand the implication: that I could achieve what I'm after by wrapping the images in a function? I'm not clear on how that would work. We could also change scribble/text to support a struct/class property for JIT transformation. Does that sound good? This sounds like it might be the kind of thing I'm after. Given that I don't necessarily know how the images are being created, could attaching such a property be done without changing how the image%s are instantiated? Thanks, Jordan Is that okay with you, Eli? Jay On Tue, Feb 7, 2012 at 4:50 PM, Jordan Johnson j...@fellowhuman.com wrote: Hi all, I'm using web-server/templates to generate text, and the data in variables I reference in the template include s-exps that may, in some cases, contain image% objects. I want it to render the image%s as plain text; even just the string IMAGE or similar would be adequate. So, my question is: how (via the template system or other libraries) can I best make racket perform this translation, ideally without writing code to walk the s-exp trees? It seems there must be a way someplace to tweak the output function used by the template library, but I don't know where that would be. Best, Jordan Racket Users list: http://lists.racket-lang.org/users -- Jay McCarthy j...@cs.byu.edu Assistant Professor / Brigham Young University http://faculty.cs.byu.edu/~jay The glory of God is Intelligence - DC 93 Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Ensuring data fed to web-server/templates is textual
Yesterday, Jay McCarthy wrote: web-server/templates uses scribble/text So, if you return a function, then it will be called. We could also change scribble/text to support a struct/class property for JIT transformation. Does that sound good? Is that okay with you, Eli? Why a property? There is already a `with-writer' that can be used to apply a custom writer, and that's how `scribble/html' does things. But that feature is not really great, IMO, and I really want to get something better instead -- something where I can compose a bunch of writers (in a form of input-regexp, output-string), disable some, etc. If anyone is interested in trying to get something here I'd be happy to provide more details. (And going back to the property, if you're looking for a way to do this for some particular value, then the right way to do this is to use the procedure property -- the text outputter treats anything that looks as a thunk by applying it to get the value to actually put out.) -- ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: http://barzilay.org/ Maze is Life! Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Ensuring data fed to web-server/templates is textual
On Thu, Feb 9, 2012 at 11:45 AM, Jordan Johnson j...@fellowhuman.com wrote: On Feb 8, 2012, at 10:17 AM, Jay McCarthy jay.mccar...@gmail.com wrote: web-server/templates uses scribble/text So, if you return a function, then it will be called. I'm not sure I understand the implication: that I could achieve what I'm after by wrapping the images in a function? I'm not clear on how that would work. If a template includes a function, then the function gets called to produce the value to display. So rather than having image you'd have (lambda () (convert-to-what-i-want image)) We could also change scribble/text to support a struct/class property for JIT transformation. Does that sound good? This sounds like it might be the kind of thing I'm after. Given that I don't necessarily know how the images are being created, could attaching such a property be done without changing how the image%s are instantiated? Thanks, Jordan Is that okay with you, Eli? Jay On Tue, Feb 7, 2012 at 4:50 PM, Jordan Johnson j...@fellowhuman.com wrote: Hi all, I'm using web-server/templates to generate text, and the data in variables I reference in the template include s-exps that may, in some cases, contain image% objects. I want it to render the image%s as plain text; even just the string IMAGE or similar would be adequate. So, my question is: how (via the template system or other libraries) can I best make racket perform this translation, ideally without writing code to walk the s-exp trees? It seems there must be a way someplace to tweak the output function used by the template library, but I don't know where that would be. Best, Jordan Racket Users list: http://lists.racket-lang.org/users -- Jay McCarthy j...@cs.byu.edu Assistant Professor / Brigham Young University http://faculty.cs.byu.edu/~jay The glory of God is Intelligence - DC 93 -- Jay McCarthy j...@cs.byu.edu Assistant Professor / Brigham Young University http://faculty.cs.byu.edu/~jay The glory of God is Intelligence - DC 93 Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Ensuring data fed to web-server/templates is textual
On Thu, Feb 9, 2012 at 12:19 PM, Eli Barzilay e...@barzilay.org wrote: Yesterday, Jay McCarthy wrote: web-server/templates uses scribble/text So, if you return a function, then it will be called. We could also change scribble/text to support a struct/class property for JIT transformation. Does that sound good? Is that okay with you, Eli? Why a property? There is already a `with-writer' that can be used to apply a custom writer, and that's how `scribble/html' does things. I see no docs for with-writer or scribble/html, so I don't know what these are. But that feature is not really great, IMO, and I really want to get something better instead -- something where I can compose a bunch of writers (in a form of input-regexp, output-string), disable some, etc. If anyone is interested in trying to get something here I'd be happy to provide more details. (And going back to the property, if you're looking for a way to do this for some particular value, then the right way to do this is to use the procedure property -- the text outputter treats anything that looks as a thunk by applying it to get the value to actually put out.) Ya, the procedure property sounds like the way to go. Jay -- Jay McCarthy j...@cs.byu.edu Assistant Professor / Brigham Young University http://faculty.cs.byu.edu/~jay The glory of God is Intelligence - DC 93 Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Ensuring data fed to web-server/templates is textual
A few minutes ago, Jay McCarthy wrote: On Thu, Feb 9, 2012 at 12:19 PM, Eli Barzilay e...@barzilay.org wrote: Yesterday, Jay McCarthy wrote: web-server/templates uses scribble/text So, if you return a function, then it will be called. We could also change scribble/text to support a struct/class property for JIT transformation. Does that sound good? Is that okay with you, Eli? Why a property? There is already a `with-writer' that can be used to apply a custom writer, and that's how `scribble/html' does things. I see no docs for with-writer or scribble/html, so I don't know what these are. No docs becasue I don't have a good API yet, so it's still a kind of a private backdoor. (And that's what I'd like to change.) (And going back to the property, if you're looking for a way to do this for some particular value, then the right way to do this is to use the procedure property -- the text outputter treats anything that looks as a thunk by applying it to get the value to actually put out.) Ya, the procedure property sounds like the way to go. OK. (I was hoping that there's a need for an organized writer thing to sort out the above...) -- ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: http://barzilay.org/ Maze is Life! Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Ensuring data fed to web-server/templates is textual
web-server/templates uses scribble/text So, if you return a function, then it will be called. We could also change scribble/text to support a struct/class property for JIT transformation. Does that sound good? Is that okay with you, Eli? Jay On Tue, Feb 7, 2012 at 4:50 PM, Jordan Johnson j...@fellowhuman.com wrote: Hi all, I'm using web-server/templates to generate text, and the data in variables I reference in the template include s-exps that may, in some cases, contain image% objects. I want it to render the image%s as plain text; even just the string IMAGE or similar would be adequate. So, my question is: how (via the template system or other libraries) can I best make racket perform this translation, ideally without writing code to walk the s-exp trees? It seems there must be a way someplace to tweak the output function used by the template library, but I don't know where that would be. Best, Jordan Racket Users list: http://lists.racket-lang.org/users -- Jay McCarthy j...@cs.byu.edu Assistant Professor / Brigham Young University http://faculty.cs.byu.edu/~jay The glory of God is Intelligence - DC 93 Racket Users list: http://lists.racket-lang.org/users
[racket] Ensuring data fed to web-server/templates is textual
Hi all, I'm using web-server/templates to generate text, and the data in variables I reference in the template include s-exps that may, in some cases, contain image% objects. I want it to render the image%s as plain text; even just the string IMAGE or similar would be adequate. So, my question is: how (via the template system or other libraries) can I best make racket perform this translation, ideally without writing code to walk the s-exp trees? It seems there must be a way someplace to tweak the output function used by the template library, but I don't know where that would be. Best, Jordan Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Ensuring data fed to web-server/templates is textual
Jordan Johnson wrote at 02/07/2012 06:50 PM: I'm using web-server/templates to generate text, and the data in variables I reference in the template include s-exps that may, in some cases, contain image% objects. I want it to render the image%s as plain text; even just the string IMAGE or similar would be adequate. I don't know about web-server/templates, but if you want to do this translation at the last minute, rather than simply avoiding putting invalid values in the s-expression in the first place, another library will do it: #lang racket/base (require (planet neil/html-writing:1:0)) (define-struct some-image-thing (x)) (define (my-html-writing-filter context thing) (cond ((some-image-thing? thing) (format IMAGE ~S (some-image-thing-x thing))) (else (error 'my-html-writing-filter Don't know how to filter ~S in context ~S thing context (write-html `(html (head (title My Title)) (body (@ (bgcolor white)) (h1 My Heading) (p This is a paragraph.) (p This is a foreign thing: ,(make-some-image-thing 42)) (p This is another paragraph.))) (current-output-port) my-html-writing-filter) This writes the output: htmlheadtitleMy Title/title/headbody bgcolor=whiteh1My Heading/h1pThis is a paragraph./ppThis is a foreign thing: lt;IMAGE 42gt;/ppThis is another paragraph./p/body/html I originally implemented that feature 7 years ago, for last-minute translation of URI objects -- to output URLs as relative to the URL of the HTML object being written, rather than absolute. -- http://www.neilvandyke.org/ Racket Users list: http://lists.racket-lang.org/users