Re: got tired of waiting for IDE support - new tool to preview FreeMarker templates

"Jonathan Revusky" <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
On Wed, Apr 9, 2008 at 1:49 PM, Jeromy Evans
<[email protected]> wrote:
> Daniel Dekany wrote:
>  >
>  > I think many will find it useful, also it would be useful for learning
>  > FTL. However, the context model should support numbers, boolean,
>  > dates, and maps and lists as variables. So it should be recursive (due
>  > to nested maps and lists), and there should be pulldown to chose the
>  > variable type (that defaults to string).
>  >
>  >

Actually, in my thinking about this kind of tool, I often end up
thinking that there is a general need in FreeMarker for more literal
types. Of course, the normal usage of a templating engine is that the
data comes from outside the template (that's even really the whole
point) and then there's all that ultra purist separation of concerns
stuff.... BUT OTOH, in various contexts, it looks to me to be quite
useful to be able to define fairly complex sample data on the page
itself. Just from the point of view of unit testing, the idea that the
template is its own unit test, except that it needs some sample data.

I was wondering whether having a literal type for something like JSON
or YAML (I think YAML is really a superset of JSON), so that you could
maybe just define a whole data model right in FTL.

<#assign dataModel = y"
   arbitrarily nested blah blah
">

(That's assuming a syntax roughly like that of raw strings.)

Another syntax that occurred to me was x{....} with the idea being
that this is an extended version of {...} the literal map syntax.
Though maybe x would be better to keep for an XML literal type.

Also, I was wondering about having it as an option in the FTL tag, like:

<#ftl testdata=x{
...
}>

I mean, there's the general problem wrt tools, that in order to
display the template, you do need some sample data set to work with.
>From a learning POV, the ability to define some data in the page and
then just output it looks pretty attractive. Well, not just for
learning, a tool that helps you edit templates could have a preview
facility, but there is a need for some sample data for that.

By the way, Jeromy, your thing is a servlet, isn't it? DId you think
about doing an applet?

The reason I ask is that I had been thinking about putting my VTL->FTL
syntax converter on the web and for the longest time, I was thinking
in terms of a servlet, but then I remembered that applets existed. I
swear I think I had forgotten about them. Though it turned out that
putting that in an applet is hard because I was using Velocity to
build the VTL tree, and it is awfully hard to just get Velocity to
parse a file without having it try to start up a whole "engine" that
tries to read files all over the place and so on. And that runs into
all these applet security exceptions. I would have to get in there and
cut away all that stuff. Not so hard, but time consuming and I left it
for later.

OTOH, the other conversion thing I have in the works is switching
between FTL syntaxes, from the angle brackets to square brackets. I
have a converter for that and I could put that in an applet, it just
occurs to me, pretty easily. And I think that a converter that
generally just gets rid of all deprecated constructs and replaces them
by the approved one would be a good thing to stick on the web. Also,
an applet that just shows a template's output looks like a pretty
useful thing, but it again runs up against the problem of defining the
data model to use.

BTW, I don't know where you're maintaining your code for this. If you
want to put it in our SVN, you are quite welcome to maintain it there.
Probably initially in the sandbox directory.

Regards,

JR
>
>  Thanks for the good feedback.  I'd definitely use all these features
>  myself and will start adding them.



>
>
>  > I think it also would be good if you can edit multiple templates, the
>  > first being the main template (that generates the output), the second
>  > one being something just can include/import as, say, /t2.ftl the third
>  > as /t3.ftl, etc.
>  >
>  >
>
>  I can do this.  I should be to give each template an editable path.  The
>  struts2 tags all use includes and my objective is to make it possible to
>  paste them straight in without modification (I've commented out the
>  includes in the examples).
>
> > Lastly, while an input is edited, and the output is not yet updated,
>  > an indicator like a spinning hourglass next to the output window would
>  > be useful. If that's not there, then you know that the output already
>  > reflects the input.
>  >
>  Oh, that's a bug.  An animated gif is there but it's on top of or behind
>  the top-right section of the scroll-bar in the result (depending on the
>  browser).
>  It posts to the server when 1000ms have passed since the last keypress
>  or state change and shows the gif while waiting for a response.
>
>  Thanks!
>
>
>
>  -------------------------------------------------------------------------
>  This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>  Don't miss this year's exciting event. There's still time to save $100.
>  Use priority code J8TL2D2.
>  http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>  _______________________________________________
>  FreeMarker-user mailing list
>  [email protected]
>  https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.