Raba - Defend your code RSS 2.0
# Wednesday, July 08, 2009

For more background about when we use this API you can read my last post about Rendering Objects to Html

Simple Rendering of query:

   1: var query = new StringTemplate("SELECT $column$ FROM $table$;");
   2: query.SetAttribute("column", "name");
   3: query.SetAttribute("table", "User");
   4: var data = query.ToString();
We will refactor this sample to handle the queries from an outside source:
   1: var group = new StringTemplateGroup("SimpleTemplates",@"C:\Templates\TemplateEngineTestCase");
   2: var query = group.GetInstanceOf("1_simple");
   3: query.SetAttribute("column", "name");
   4: query.SetAttribute("table", "User");
   5: var data = query.ToString();
Rows 1,2 - loading the template data from a source file. 
Here is the Template (1_simple.st):
//1_simple.st
SELECT $column$ FROM $table$;
 

Template Anonymous Type:

In the last template usage (1_simple.st) We bind the parameters using strings only. but we also have a better options: let's assume we wrote down such template:

//2_simpleObjects.st
Full Name: $Person.FirstName$ - $Person.LastName$

But let's assume that we don't have the Person class\instance, we can simply write it using the anonymous types:

   1: var user = new {FirstName = "Shani", LastName = "Raba"};
   2: var group = new StringTemplateGroup("OOTempaltes", @"C:\Templates\TemplateEngineTestCase");
   3: var query = group.GetInstanceOf("2_simpleObjects");
   4:  
   5: query.SetAttribute("Person", user);
You can also use this kind of bindings for setting template-attributes from each one of the Person sub-classes.
 
 
Template list:

Till now it is all pretty simple to implement by yourself, but the real issue here is the List binding feature.
You can write such template:

//3_simpleLoop.st
$items: {num1|
    <li>$num1$</li>
    }$
$end$

and bind the list using this code:

   1: var templateFolder = new StringTemplateGroup("SimpleLoopTemplates", @"C:\Tempaltes\TemplateEngineTestCase");
   2: var template = templateFolder.GetInstanceOf("3_simpleLoop");
   3:  
   4: template.SetAttribute("items", new List<string> {"Shani", "Doron", "Nati", "Yossi"});

 

Conclusion:

  • The code is pretty simple, the templates engine implements good functionality and is well documented.
  • The StringTemplate syntax is easy to learn and well documented.
  • I still don't like it when I need to learn a new language\syntax - it will sharpen the newbie's curve.
  • StringTemplate is missing good Object2Template Designer.
Wednesday, July 08, 2009 8:13:57 AM (GMT Daylight Time, UTC+01:00)  #    Comments [1] - Trackback
.Net 3.5 | Scripting Technology
# Sunday, April 08, 2007

I've Added new capability to my blog, this called Snap Preview Anywhere.
You probably see this before in some Web2.0 sites, but I was surprised how easy is to add it to yours.

I like this new feature of mine :).

SnapOfDasblonde.PNG

Small snap preview of a small snap preview for DasBlonde blog

You should try this too.

P.S. 1
This cool feature of snapshots is enable only on the left panel, (links and blogrolls).
I should check why this ain't work on the main page, I think that dasblog saves its links using *.ashx instead of pure href.

P.S. 2
I would like to hear your opinions about this feature and other recommendations for new features.

Sunday, April 08, 2007 11:23:10 PM (GMT Daylight Time, UTC+01:00)  #    Comments [4] - Trackback
Life | My Site | Scripting Technology
# Sunday, May 14, 2006

History
In our application we created a special (user friendly) window for showing messages to the user. The window will get its data, text, buttons through the args parameter.

We will open this window using the messageBox function (this method lies in one of our JS files).

Challenge
Everyone knows the annoying default alert of ValidationSummary in ASP.NET.
Our messageBox still couldn't rid from the alert that the WebUIValidation.js is popping up on validation error.
Why? Because in this JS, Microsoft simply write alert(msg).

Solution
Today we wrote those simple lines:

window.alert = function specailAlert(msg) {
   messageBox("title", msg, button_ok, info_icon);
}

This will cause the JS parser to call our function any time the origin window.alert is running. So from now on, when the ValidationSummary will write alert("some useful message"), our method will replace the ugly gray box with our user friendly window.

 

Sunday, May 14, 2006 8:54:57 PM (GMT Daylight Time, UTC+01:00)  #    Comments [1] - Trackback
.Net | Scripting Technology
# Saturday, April 29, 2006

A few days ago I start thinking about a new way to control our web site window size.
In our site there is a main window which hold the most important data. For editing the data or view more data: you can choose your subject in the menu and it will open a new page with the full details.

The common sense says that the window should set its own width/height for best fit, with minimum scrolling, but the reality isn't that simple because this page can open either as a regular window or as a modal window and the parameters are different. There is another problem, changing the window size in run-time (in the body) is very ugly (you can see the window re-sizing itself).

The other way is working with JavaScript file which holds the windows parameters and the opener will use this parameters for opening the wanted page. The good thing in this idea is that the menu will know all the sizes and open the windows in the wanted size (the one defined at the JS file). But here we have another problem that Server files (.cs) that writing JavaScript (from server) should know this JS file and the names of the parameters, can cause broken links. also, links to my site that sent via email won't open in the wanted size.

another idea is to use XML for server and at the first time (application) create dynamically the JS file with the parameters, still can cause broken links from (html or other JS) and this can cause a strange problem because we are connecting our files to JS file that is not created yet, I know it will work because it is happening on run-time, but it is still strange. In here we still have the problem for links to my site that sent via mail.

For the mail issue, lets say that every link should go first to my main page, and only their the main window will open the wanted page for you, so we can set the window size via the main window.

I am searching for other implementations to the JavaScript file that holds the sizes for all windows.
Is there a better way for doing this?

Saturday, April 29, 2006 2:50:31 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
.Net | Scripting Technology | Software Development

Have you ever found your self looking at a site and trying to learn from their JavaScript or HTML?
most of the time is written without indentation at all, there are some sites that also rendering their JavaScript/HTML in one line.

So I found this great site for indenting to your standards:
http://www.prettyprinter.de/index.php

Saturday, April 29, 2006 12:16:28 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
Scripting Technology
# Tuesday, January 24, 2006

I've found a great peace of code in JavaScript,
the source give us the ability to use String.Format() in our JS code, the same as we do in .Net.
I found this very usefull...

Tuesday, January 24, 2006 8:43:46 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
Scripting Technology
Archive
<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Shani Raba
Sign In
Statistics
Total Posts: 139
This Year: 6
This Month: 0
This Week: 0
Comments: 97
Cool Stuff
Add to Technorati Favorites
Themes
Pick a theme:
All Content © 2010, Shani Raba
DasBlog theme 'Business' created by Christoph De Baene (delarou)