[plt-scheme] Web programming .

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Tue Dec 29 01:22:06 EST 2009

You could do that with read and eval, but that doesn't mean it would
be a good idea. =) This is a similar thing to what I discuss in the
FAQ:

http://docs.plt-scheme.org/web-server/faq.html#(part._.How_do_.I_use_templates__dynamically__)

IMHO, you shouldn't transliterate Genshi but should rewrite. I would
be surprised if there was an interesting reason they are using XPath,
it seems like all they had available; in contrast you have abstraction
power in the form of function, modules, units, macros, etc.

Jay

On Mon, Dec 28, 2009 at 11:17 PM, Nevo <sakur.deagod at gmail.com> wrote:
> hi Jay:
>    Thanks for your kind suggestion and explanation. I myself have a happy
> time to play with PLT template system just ,you know, still need more
> practice to get into it. The difference between Plt template and Genshi
> template is not my concern. Actually I'm trying to translate the Trac
> template (particular fullblog plugin) to PLT web, and seeing those XPath
> related syntax everywhere in Genshi template files , so just wondering if a
> similar syntax would be supported in PLT template.  Now I have more sense
> (compared to my previous usage) about how to deal with PLT template , it's
> handy to treat PLT template as a Scheme program with simple syntax as
> pointed out by you, compared with that traditional template engine like
> Genshi (read, parse, expand, generate). That's great!
>    Btw, sorry , I have another (maybe non sense) question that, for example,
> I now have a template file piece like follows:
>  <XHTML>
>     .....
>    @select-node["content/title/title1/text()"]
>     .....
>   </XHTML>
>
>   and "select-node" is defined in another scheme file:
>   (define (select-node xpath-textual)
>     (let ((q1 (sxpath xpath-textual)))
>       (q1 current-xml-template)))
>
>   and "current-xml-template" is a SXML document representation of :
>   <content>
>     ...
>     <title>
>       <title1> @get-page-1-title[]</title>
>       ....
>     </title>
>     ...
>   </content>
>
>   As you probably see , the @select-node will produce just
> "@get-page-1-title[]" , so is it possible to let template compiler to
> recompile the produced stream second pass so that @get-page-1-title[] will
> also be got expanded ?  I knew this question may sound no sense and not a
> problem at all ( I could simply call @get-page-1-title in template instead
> of bothering SXPATH at all), just a silly question though.
>
> Nevo
>
> 2009/12/29 Jay McCarthy <jay.mccarthy at gmail.com>
>>
>> I think the difference you're getting at is that because the PLT
>> template system is more powerful, there is less that you can do with
>> it externally. The PLT templates are not necessarily XML, so it
>> doesn't make sense to parse them and analyze them as if they were. PLT
>> templates are simple Scheme programs that when run produce the text
>> you want, but they have a convenient syntax (thanks to Eli primarily)
>> for primarily text documents.
>>
>> If you wanted you could enforce upon yourself the restriction that
>> your templates were actually XML and parse them, but I'm still not
>> sure what you feel that that (or Genshi) would do for you.
>>
>> Jay
>>
>> On Sat, Dec 26, 2009 at 10:43 PM, Nevo <sakur.deagod at gmail.com> wrote:
>> > hi,
>> >   Sorry, forgive me not able to clarify more on this topic . Here's the
>> > piece of code from the Genshi template file :
>> >   <py:match path="body" once="true" buffer="false"><body>
>> >     ${select('*|text()')}
>> >     </body> </py:match>
>> >
>> >   The above code is just instructing the template engine to *select* the
>> > text content of node "body" from the XHTML streams.  That's the one I
>> > was
>> > asking actually.  There's a difference between Genshi and PLT scheme web
>> > template from my point of view , the former separates the template
>> > macros
>> > and the real content streams ,while the latter  combines the template
>> > macros
>> > (S-expressions) with the content. As suggested by Jay, I could use
>> > SXML/SXPATH library to parse the XHTML content and select those nodes
>> > which
>> > I'm interested in. Yeah, this is possible , but I havn't used that yet,
>> > on
>> > a quick read of its tutorial
>> > (http://modis.ispras.ru/Lizorkin/sxml-tutorial.html) , I probably need
>> > to
>> > obtain a SXML representation of a document which means the template file
>> > should be expanded first (using @include-template) and then parse it
>> > using
>> > SXML parser into a SXML document before I can use SXPath on it, am I
>> > right ?
>> > Or is there a way to do it in template file itself ? Thanks.
>> >
>> > Nevo
>> >
>> >
>> > Actually, I think you misunderstood.
>> >
>> > Tell us what you want and it may be pretty easy to do.
>> >
>> > On Sat, Dec 26, 2009 at 11:28 PM, Nevo <sakur.deagod at gmail.com> wrote:
>> >
>> >
>> > hi Todd:
>> >    Yeah... your words sound like a style of education to me but useful
>> > (really appreciate) . Of course I will take the stabs at writing pieces
>> > of
>> > prototype and ask here for review. As currently I'm still on the way to
>> > fully understand and practice with the powerful PLT scheme web framework
>> > by
>> > means of building up my blog service , the quick follow up in this topic
>> > is
>> > just a curious wonder and hope not offending the underlying laws  of
>> > this
>> > mailing list. I really want to contribute to this great community and be
>> > able to help others in exchange to the huge helps from here, but as you
>> > know
>> > my numb brain just tells me you should dig in it before you give any
>> > output
>> > ,as emphasized by you.  So thanks anyway , I'll see what I would help in
>> > the
>> > future.
>> >
>> > Nevo
>> >
>> > On Sat, Dec 26, 2009 at 10:12 PM, Nevo <sakur.deagod at gmail.com> wrote:
>> >
>> >
>> >
>> > Yes, it's  pretty useful and enjoyable to do web programming in plt
>> > scheme.
>> > But I just wonder any plan to continue to extend the powerness of Plt
>> > scheme
>> > web framework ? Like provide XPath select support in current HTML
>> > template
>> > system which I've been using  in  Genshi ( a python template component
>> > used
>> > in Trac (trac.edgewall.org) ? thanks .
>> >
>> > Nevo
>> >
>> >
>> >
>> > Assuming it works the way most other development in PLT has seemed to
>> > work, here's all you need to do:
>> >
>> > Step 1. Find a student who wants a Master's or Ph.D. in Computer
>> > Science.
>> >
>> > Step 2. Interest him/her in what you want.
>> >
>> > Step 3. Get him/her to interest a member of the PLT group as an advisor.
>> >
>> > Step 4. Wait for the goodies. :-)
>> >
>> > But seriously, I'm working with some of my (high school) students on a
>> > couple of PLT web apps and we're seeing things we wish we had and
>> > taking stabs at putting them together. If you can give examples of the
>> > kind of functionality you want and take stabs at writing parts of the
>> > code, this mailing list is incredibly good about helping you along.
>> >
>> > As someone who's gotten huge amounts of help on this list in exchange
>> > for a mere pittance of very basic help for the few people even more
>> > clueless than himself, my suggestion is dig in, start writing, ask for
>> > help, and before you know it, you'll have what you always wanted.
>> >
>> > Todd
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>>
>>
>>
>> --
>> Jay McCarthy <jay at cs.byu.edu>
>> Assistant Professor / Brigham Young University
>> http://teammccarthy.org/jay
>>
>> "The glory of God is Intelligence" - D&C 93
>
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.