This is an interesting observation. However,
a broad range of use cases is needed to consider
ways to provide extensibility. 

In general, it would be good to separate the template
generation/execution engine from the CGI part, as discussed in
    http://www.jsoftware.com/jwiki/CGI/Design

As of the current design, extensibility can be achieved by
means of inheritanse and overriding.

There are two polar approaches in building libraries:
 - monolithic: large procedural methods that do tasks from start to finish
 - granular: small near-pure-functional tacit routines

With monolithic methods, it's nearly impossible to
augment behavior without replacing the whole method.

In granular, every small aspect can be replaced either
in-place or in inheriting locale. (In example below 'base'
locale inherits from 'z'.)

Since JHP is intended as a one-time task, the definitions are
in 'z' locale, however for separated API it should have its
own locale.

The code in templates need some kind of interface from which
to derive the values, such as x y arguments or an object model
or global (locale) variables.
See also phrview.ijs in Phrase DB example,
   http://olegykj.sourceforge.net/jhp/

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!

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!


--- 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

Reply via email to