Register to post in forums, or Log in to your existing account
 

This forum is locked: you cannot post, reply to, or edit topics.  This topic is locked: you cannot edit posts or make replies.     Home » Forums » General zApp Discussion
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Sat Apr 23, 2005 10:07 pm   

"Mail Merge" added to zApp!
 
I was bored today. I wanted to do something *fun*. I've been thinking about a "template" system for zApp, so I decided I wanted to implement it today.

It's mostly finished and working now. Here's how it works:

First, there is a zTemplate object that you can use. It has a Template field and a Text field. The Template field is the template text that needs to be expanded, and the Text field is the expanded text (or if the ShowTemplate is True, then the Text field also shows the embedded templates). You can also assign a DataSource object to the template.

Here is some of the syntax that I've implemented in the template:
#datafield#
expand this to the value of the given "datafield" from the current data source.
<=expression>
evaluate the "expression" using the current scripting language and return the result. "expression" is parsed for #datafield# templates.
I plan to add some more cool stuff to this simple syntax, such as IF/ELSE statements, CASE statements, and LOOPs. If I have time later tonight I'll add those.

Now, even cooler is that I've encorporated these templates into the zMemo component. There is a new action called _MemoInsertTemplate that prompts you for a template to enter. When entering the <=expression> templates you can just enter =expression into the prompt. There is another action called _MemoShowTemplate that toggles whether the template definitions are shown in the editor, or whether templates are expanded.

When you right-click on a template field in the memo control, an "Edit Template" option appears in the right-click menu that allows you to edit the definition of the template. Otherwise the template itself is a "block" of un-editable text (like a picture or other non-text item).

Text styles work fine, so after inserting a template you can make it bold, or colored, or whatever. When you save the memo or print it (and ShowTemplate is false), then the result has the expanded template text.

I merged the editor.zml and dbview.zml demos into a single dbeditor.zml demo that allows you to connect a database to the memo. Then I added some text to the memo and inserted some #field# templates to it. As I select a different record from the database, the memo field automatically updates to show the next text.

I'll include this demo in the next release and will document it more fully soon. All I can say is that it practically worked the first time and is *very* cool. I really love how this RichView control is implemented. It makes adding stuff like this really easy.

And now that I understand the RichView component a bit better, adding syntax highlighting shouldn't be far off Wink

(Yeah, I know, templates weren't on my to-do list for the public release, but I just wanted to do something fun and different today, and besides, I need them for eMobius anyway)
Reply with quote
theNerd
Adept


Joined: 01 Mar 2005
Posts: 277

PostPosted: Sun Apr 24, 2005 1:30 am   
 
Exclamation Hey! This is exactly something I wanted implemented! One question, lets say I have a document (like an invoice or quote) that uses some fields from one table (Dear #PersonsName#) but I want a table (grid) in the document that will create a list from another table (items the person has bought, for example.) Can it do this?

Better example:

Code:
Dear #Name#

  Blah blah, #anotherfield# and blah blah, blah.

 Your Order:
 _____________________________________
 #ItemID# , #ItemName#, #ItemPrice#

 Total $#EvalTotal#

Would then become:

Code:
Dear Mr. Zugg,

 Blah blah, something and blah blah, blah.

 Your Order:
 ______________________________________
 ASD, theNerd Mobile, $500.00
 Z1F, theNerd's Greatest Hits, $25.00
 PIL, theNerd's Guide to zApp, $15.00

 Total $540.00


(obviously, the example order list is in a grid)
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Sun Apr 24, 2005 4:46 am   
 
Right now when you are doing this interactively in the zMemo component you can only have one datasource. But to implement your above example, you can use the zTemplate component and pass the data in the table as a collection, then take the resulting text and send it to the Text property of the Memo control.

In any case, when using templates interactively you can't really use the LOOP stuff to create a table, and the interactive stuff is currently limited to a single line and can't wrap. I'm hoping to improve that but I don't yet understand how to make "item" objects in the Memo control wrap to a new line. The current templates are implemented more like picture objects that don't wrap.

But the zTemplate control can generate any sort of complex text from a script, more like the template system that is part of PHP. So there are really two different systems here.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Sun Apr 24, 2005 4:48 am   
 
Oh, and to implement your example above you could also do something really tricky. You could point the Datasource of the memo control to the data used to make your table. Then for the individual fields, like the #Name# field, what you can do is create a control somewhere and set the DataSource of the edit control to the other database, set the Field name to "Name" and then in the memo instead of using #Name# you could use <=Edit.Text> to point to the contents of the edit control. A tricky way of getting data from two different sources.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Apr 26, 2005 4:35 am   
 
I got a lot of work done on the Template system today. In particular, I was able to fix it so that template text is now considered "normal" text and can word-wrap and take up more than one line in the editor.

In addition, I completed the full zTemplate object that has several powerful commands for if-then-else, case, looping, etc.

Take a look at the zTemplate documentation for more information and examples.

I'm still thinking about the looping syntax to see how it might be improved, and might add some stuff for direct access to array variables in your script.
Reply with quote
theNerd
Adept


Joined: 01 Mar 2005
Posts: 277

PostPosted: Tue Apr 26, 2005 1:32 pm   
 
Zugg, I know the Memo object can import and export HTML documents but can I use HTML directly in the document or does the memo control just convert the HTML to RTF?
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Apr 26, 2005 5:55 pm   
 
Not exactly sure what you mean:

No, you can't type HTML tags directly into the Memo control and have them work. It's not an HTML editor.

Yes, you can *paste* HTML interactively using the Paste Special command.

Yes, from a script you can use AddHTML or InsertHTML to add HTML to the end of the document or insert it at the current cursor position.

Yes, you can use the HTML field to return the entire memo contents as HTML or set the entire memo contents as HTML.

So, for most purposes the HTML support is pretty good. But it's not as powerful as something like Dreamweaver that can directly edit HTML tags quickly. To do this in zMUD you would display the HTML value of the zMemo in a regular text memo, edit the HTML and then send the HTML back to the memo to see the formatting. And the formatting doesn't exactly match what a web browser will display (the HTML export is much better than the HTML import)

Also, while the HTML export supports full CSS style sheet generation, the HTML import does not support any style sheets at all.

If the question is "Can the templates entered interactively into zMemo contain HTML?" the answer is No. The interactive templates are for plain text only. You then format the plain text using the normal interactive controls.
Reply with quote
theNerd
Adept


Joined: 01 Mar 2005
Posts: 277

PostPosted: Tue Apr 26, 2005 6:15 pm   
 
Okay, that answer covers all the bases. I understand more how the zMemo works.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Apr 26, 2005 11:26 pm   
 
Man, what an annoying day. I spent all day today trying to fix a really bad problem with zMemo. It turns out that while I was able to make templates word-wrap properly, "items" in a RichView (zMemo) control cannot contain hard line breaks. So when you try to use the <$n> in a template for a newline, it just inserts the CR and LF characters and shows them as boxes.

Creating a template item that can span multiple lines turned out to be a *real* pain. I ended up have to create "linked" items and then set it up so that when you modify the template you are always modifying the template of the "parent" item, and when you double click, it determines the full list of items in the templates and highlights all of them, and that it can dynamically create new items as needed for multiple lines, or delete items that are no longer needed if the text no longer spans so many lines.

I think it's working now, but I sure didn't expect to spend another full day on these templates. Part of me almost wishes that I didn't bother with this right now...I have too much other important stuff to work on.

Sigh.

Oh, I also decided to change the syntax of templates. The <> syntax just makes it a pain to create templates in the ZML file (you have to use CDATA). So, I changed it to {} like PHP uses for templates. So now, stuff like <$if> becomes {$if} and <=expression> becomes {=expression}. I think that will make it easier to use with HTML and XML.
Reply with quote
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.     Home » Forums » General zApp Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
© 2009 Zugg Software. Hosted on Wolfpaw.net