Re: [racket-users] web-server: generating HTML with styles
Hi John, On 8/24/2015 4:31 PM, John Clements wrote: On Aug 24, 2015, at 12:35 PM, George Neuner gneun...@comcast.net wrote: I'm trying to generate some very simple web pages - basically success/failure status for URLs followed from an email. However, I can't seem to figure out how to apply styles - other than predefined headings h1, etc. - to the document. Can you explain in more detail what you mean by “styles”? It sounds like you want to take a plain-looking HTML page and change the way it looks—colors, fonts, etc. If I’m right about this, then most of what you want will likely be accomplished by associating a CSS file with your page. That's exactly what I want, but I would like to avoid having separate files associated with this. I would like to generate the HTML in Racket because I need to dynamically insert information into it. E.g., (send/back (response/xexpr `(html (body (list (p Hello (b ,username)) (p (style color:red ; - how to do this? An error occurred processing your request.)) : as in the web-server documentation (sans the style clause). There are examples of reading HTML from a string ... and I suppose I could do that ... but not of generating styled content directly. There is a style struct and a style function in the HTML module, and it seems like many of the generating functions permit attributes to be attached to their document nodes, but there don't seem to be any examples, and I am unable to figure it out from the documentation (which seems quite cryptic in relation to most Racket documentation). George -- You received this message because you are subscribed to the Google Groups Racket Users group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] web-server: generating HTML with styles
Hi George, There is no feature of the Web server that you need. All you need to do is generate a different HTML page. For instance, if you are currently generating htmlbodypYo!/p/body/html with `(html (body (p Yo!))) And you want to add a stylesheet, so that you get the output htmlheadlink rel=stylesheet type=text/css href=theme.css/headbodypYo!/p/body/html then write `(html (head (link ([rel stylesheet] [type text/css] [href theme.css]))) (body (p Yo!))) And if you want to add style attributes on a single element, like the p: htmlbodyp style=color: puce;Yo!/p/body/html Then write `(html (body (p ([style color: puce;]) Yo!))) Jay On Mon, Aug 24, 2015 at 3:35 PM, George Neuner gneun...@comcast.net wrote: Hi all, I'm trying to generate some very simple web pages - basically success/failure status for URLs followed from an email. However, I can't seem to figure out how to apply styles - other than predefined headings h1, etc. - to the document. Are there any extended examples of generating HTML with styling or of attaching attributes to document nodes? I've been looking through the documentation all day, but I have found only the list of functions and struct types available: e.g., (style v ...) → procedure? v : outputable/c Not terribly informative as to what is expected as input. I have discovered include-template, but AFAICT it seems to be meant for compile-time use ... I need to insert information into the pages dynamically at run-time. Obviously, I could read/process HTML files from disk, but I need to create several pages and having separate files seems like a good way for the code and the page templates to get out of sync. Thanks, George -- You received this message because you are subscribed to the Google Groups Racket Users group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- Jay McCarthy http://jeapostrophe.github.io Wherefore, be not weary in well-doing, for ye are laying the foundation of a great work. And out of small things proceedeth that which is great. - DC 64:33 -- You received this message because you are subscribed to the Google Groups Racket Users group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] web-server: generating HTML with styles
Hi Matthew, Jay beat you to the answer 8-) [though the list apparently bounced my reply to him] I do appreciate your detailed explanation. I knew that I did not need the html module to use response/xexpr in the web-server, but I was looking for some syntax to add styling to the content, and I was searching through every html related link in the documentation. I really wish I could have figured it out on my own. Thanks, George On 8/24/2015 6:13 PM, Matthew Butterick wrote: I haven't used the HTML module (though it is, AFAICT, intended for parsing HTML, not writing it). But the examples in the webserver docs (e.g., `send/back`) don't use that module. Instead, they construct responses out of X-expressions. Judging from your example, perhaps you are mixing up the two? (Or maybe three — the documentation snippet you cited for `style` was from `scribble/html/html`, which is yet another thing.) For example, the quasiquoting on this expression makes it an X-expression, so the tag names (html, body, p) are just quoted symbols, not structs or functions from another module. So as you've written it, it won't work. `(html (body (list (p Hello (b ,username)) (p (style color:red ; - how to do this? An error occurred processing your request.)) There's no `list` necessary in an X-expression, and the attributes are separated. So the correct X-expression syntax would be: `(html (body (p Hello (b ,username)) (p ((style color:red)) An error occurred processing your request.))) For styling, you have three choices. 1) Apply the styling directly to the tag as an attribute. As shown above. 2) Apply the styling indirectly through an external CSS file, as John Clements suggested. To do this, you'd need to give your target a 'class' or 'id', and then it would take on whatever styling was defined in the CSS file, e.g., `(html (body (p Hello (b ,username)) (p ((class error)) An error occurred processing your request.))) 3) Or, since you don't want an external file, you can apply the styling indirectly with inline CSS. You'd still need to give your target a 'class' or 'id', but then the style sheet itself can live inside the X-expression: `(html (style ((type text/css)) .error {color: red;}) (body (p Hello (b ,username)) (p ((class error)) An error occurred processing your request.))) Again, none of these options use external functions. They're just X-expressions and you can generate them however you like. -- You received this message because you are subscribed to the Google Groups Racket Users group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] web-server: generating HTML with styles
On 8/24/2015 4:49 PM, Jay McCarthy wrote: And if you want to add style attributes on a single element, like the p: htmlbodyp style=color: puce;Yo!/p/body/html Then write `(html (body (p ([style color: puce;]) Yo!))) Thanks Jay! That's exactly what I needed. George -- You received this message because you are subscribed to the Google Groups Racket Users group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.