2007/5/24, Oleg Kobchenko <[EMAIL PROTECTED]>:
[snip]
JHP templates are good for multi-line markup output,
such as HTML, XML, RTF, XAML, etc. For small strings,
other methods work better, such as printf or positional
templates (see Edit|Configure, External Programs, Exec CMD).

  'Hello %N, now is %T!' rplc '%N';'JHP';'%T';'time'
Hello JHP, now is time!

Thank you for short and nice example of using rplc for templating.


For the provided use case, here's how it's done:

require 'web/jhp'

v=: 3 : 0
 r=: ''
 print=: 3 : 'r=: r,padj y'
 3 : (hrep y)''
 r
)

  name=: 'JHP'
  v 'Hello <%=name%>!'
Hello JHP!

  v 'Hello <%=i.3 4%>!'
Hello 0 1  2  3
4 5  6  7
8 9 10 11!


v is "destructive". It has a couple of (global) side effects. Firstly,
the use of v changes the behaviour of jhp's original print afterwards.
(maybe we should reset the meaning of print before returning back).
Secondly, and more importantly, it isn't possible to do nested
templating, which is crucial in modular templating[1]. (which you use
in phrview example; btw, your maketable example doesn't use template
facility but suppose it uses)


[1] http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf


--- June Kim <[EMAIL PROTECTED]> wrote:

> Hi,
>
> I've been playing with JHP recently. While it does well what it
> originally attempts to do, I'd like to extend and generalize its use.
> I want to use it for general templating.
>
> The first step could be letting JHP return a result string. However,
> the code isn't particularly designed for extension. (I have to copy
> and modify the code directly)
>
>    template=: 'hello Mr./Mrs. <%= name %>'
>    name=:'Jane'
>    hrep template
> print 'hello Mr./Mrs. '
> print  name
>    0!:0 hrep template   NB. since this session is from J window print
> is smoutput
> hello Mr./Mrs.
> Jane
>
> What I want is a verb v that does:
>
>    'hello Mr./Mr.s Jane' -: v template
>
> I could modify the code directly myself, but that doesn't seem like a
> proper way of extending a code. Code should be closed for modification
> but open for extension[1].
>
> Obviously, next step would be handing over a key, value pairs(maybe
> the name of a locale that contains those variables) to the templating
> verb.
>
>
> [1] Open-Closed principle 
http://www.objectmentor.com/resources/articles/ocp.pdf
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>




____________________________________________________________________________________
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to