I was doing some work on my Templating Engine again, and I wanted a name for a variable that nobody else would ever use. What's the usual way to do that? Right, include the name of your application. Easy enough, right?
The only problem I came across was the fact that I had no real name for the engine. So that's why I had to think of one. I came up with... LookingGood. It may or may not be the final name, it may or may not mean that I use similar names for my similar scripts (though I must say you can do a lot of things with the Good postfix).
Just thought I would drop that by - as I really want to be posting more I can just keep you informed (not caring whether you are interested or not :P) about such things. So, LookingGood is what I am working on right now. And maybe, just maybe all of you will be using LookingGood some day. (Probably not, though - this is just my project for my work, which others may use, but are not advised to.)
Wednesday, January 30, 2008
Monday, January 28, 2008
Reinventing The Wheel? (To Run Myself Over)
I have been working on a templating system for quite some time now. It's one of the reasons I have not been posting. Shame on me for that, by the way. Anyway, there are probably people who are reading this and now wonder what a templating system is. Well, it's definition can differ slightly, but in this case it's a system that separates the layout from the programming logic completely.
Take for example the syntax of my templating system... anything normally typed is html and is not touched by the engine at all (okey, it's touched, but left in tact completely). Anything between <: :="" and=""> is handled by the templating system, however. Any value between the two script-delimiters (that's what they are called) will be printed to the output. So if the programming logic of a page gives the page access to a 'username' I can write "Hello <:username:>" to have it say hello Jasper to me and fill it with another name.
Besides printing values the scripts can be used to call functions, I planned two functions so far, include("page.html") and nameForCounter(varName), which can execute certain tasks. Include will insert a certain file in that location, and nameForCounter will assign a variable name to the counter of the topmost for or foreach loop (which I will explain more on later), giving you a handle to refer to it in the rest of your template.
The third thing a script can do is define a control structure. Planned of these are if, else, (possibly elseif as well), for, foreach and end ... . These work on script and plain text alike, if (statement) only considers the following content if statement is true, otherwise it will simply ignore it. An if anything that occurs before the next end if or else. Likewise else only considers the content if the last if evaluated to false - and it also ends at end if. for (value1 ++>/--> value2) will repeat the content enclosed by it and end for - starting at value1, increasing (++>) or decreasing (-->) it until value2 is reached. foreach (variableName in array). Array should be one of these variables supplied by the programming logic, but it has to be an array (surprise, surprise) then we will repeat the content (ended by end foreach, you guessed it) for each element the array has, the element always being accessible through variableName.
Multiple actions can be done in one script, in such a case they must be seperated by semicolons (;).
There is another kind of delimiter the engine recognises, <:- -:="" and="">. Anything between those two is regarded as a comment and will be removed from the document. Comments can be inside and outside script tags.
So that's what my engine is supposed to do - what does it have to do with reinventing the wheel?
(warning: technical terms - unexplained - ahead)
Now, while my syntax is different, there are other templating systems around already. None of them what I wanted though, simply take your template at real time and turn it in the website you want the users to see. I discovered this is for a reason, when making my own system. Because this costs way too much time and thus is very processor intensive. So what's the alternative? I looked into the source of the most notable templating engines, Smarty (it's open source as well, really). It simply compiles the userfriendly template to a (normally) unseen php script, which runs a lot faster, the first time a page is requested since it has been modified. I decided I would have to use a similar system to come closest to my wishes. Also I learned the trick of looking at the last time modified attribute of a file to see if it needs to be recompiled. However, when looking through Smarty's source code, it made me wonder what this new choices leave as reasons to actually make my own templating system.
It took me a while to figure out if I wanted to continue development of my engine, but I decided I would. Firstly, this script is mine, so other people may use it, but I can tweak it to my needs and make it the way I want to behave. Secondly, the syntax of my system is "better" (read as: I like it more). Thirdly, I will provide some functionality that Smarty does not provide. For now, this functionality would be: reading templates from a database and writing compiled files to a database. So yes, I will make my own system, and yes I have my reasons for it. Just drop me a line if you would be interested in using my system as well.
Now, for anyone wondering about the title, try googling that phrase. Say you would not find anything (which I cannot believe, but anyway) try finding the unrelated label for this post and look in that area.
Take for example the syntax of my templating system... anything normally typed is html and is not touched by the engine at all (okey, it's touched, but left in tact completely). Anything between <: :="" and=""> is handled by the templating system, however. Any value between the two script-delimiters (that's what they are called) will be printed to the output. So if the programming logic of a page gives the page access to a 'username' I can write "Hello <:username:>" to have it say hello Jasper to me and fill it with another name.
Besides printing values the scripts can be used to call functions, I planned two functions so far, include("page.html") and nameForCounter(varName), which can execute certain tasks. Include will insert a certain file in that location, and nameForCounter will assign a variable name to the counter of the topmost for or foreach loop (which I will explain more on later), giving you a handle to refer to it in the rest of your template.
The third thing a script can do is define a control structure. Planned of these are if, else, (possibly elseif as well), for, foreach and end ... . These work on script and plain text alike, if (statement) only considers the following content if statement is true, otherwise it will simply ignore it. An if anything that occurs before the next end if or else. Likewise else only considers the content if the last if evaluated to false - and it also ends at end if. for (value1 ++>/--> value2) will repeat the content enclosed by it and end for - starting at value1, increasing (++>) or decreasing (-->) it until value2 is reached. foreach (variableName in array). Array should be one of these variables supplied by the programming logic, but it has to be an array (surprise, surprise) then we will repeat the content (ended by end foreach, you guessed it) for each element the array has, the element always being accessible through variableName.
Multiple actions can be done in one script, in such a case they must be seperated by semicolons (;).
There is another kind of delimiter the engine recognises, <:- -:="" and="">. Anything between those two is regarded as a comment and will be removed from the document. Comments can be inside and outside script tags.
So that's what my engine is supposed to do - what does it have to do with reinventing the wheel?
(warning: technical terms - unexplained - ahead)
Now, while my syntax is different, there are other templating systems around already. None of them what I wanted though, simply take your template at real time and turn it in the website you want the users to see. I discovered this is for a reason, when making my own system. Because this costs way too much time and thus is very processor intensive. So what's the alternative? I looked into the source of the most notable templating engines, Smarty (it's open source as well, really). It simply compiles the userfriendly template to a (normally) unseen php script, which runs a lot faster, the first time a page is requested since it has been modified. I decided I would have to use a similar system to come closest to my wishes. Also I learned the trick of looking at the last time modified attribute of a file to see if it needs to be recompiled. However, when looking through Smarty's source code, it made me wonder what this new choices leave as reasons to actually make my own templating system.
It took me a while to figure out if I wanted to continue development of my engine, but I decided I would. Firstly, this script is mine, so other people may use it, but I can tweak it to my needs and make it the way I want to behave. Secondly, the syntax of my system is "better" (read as: I like it more). Thirdly, I will provide some functionality that Smarty does not provide. For now, this functionality would be: reading templates from a database and writing compiled files to a database. So yes, I will make my own system, and yes I have my reasons for it. Just drop me a line if you would be interested in using my system as well.
Now, for anyone wondering about the title, try googling that phrase. Say you would not find anything (which I cannot believe, but anyway) try finding the unrelated label for this post and look in that area.
Saturday, December 15, 2007
XmlHttpRequest script 2.0
Quite a while ago, I told you about this script that I had written, which would make xmlHttpRequests for me. Now I have made a version 2.0, I ramp up all the way to the next major version umber. Why? Because there are considerable changes, including ones in syntax.
I changed the name of my function, added an argument (called args for irony's sake). Besides that the script now supports POST calls besides the regular GET calls. Also, it no longer ought to make any kind of complain when new requests are made before the first one is finished.
The script is available from here, but there are some things I really want to say. For my bandwidth (even though it won't matter much) and your security, do not include the script right from my website. Instead, download it, and put it with your website on a host and then include it using a script tag. And to make sure I won't mistake you for a "includer" do not link directly to the file, link to this post instead.
If you stick to these few rules you can use my script. A guide is to be found within the file (all commented out of course) - using the script shouldn't be too hard. Good luck with your web designing.
Changelog
I changed the name of my function, added an argument (called args for irony's sake). Besides that the script now supports POST calls besides the regular GET calls. Also, it no longer ought to make any kind of complain when new requests are made before the first one is finished.
The script is available from here, but there are some things I really want to say. For my bandwidth (even though it won't matter much) and your security, do not include the script right from my website. Instead, download it, and put it with your website on a host and then include it using a script tag. And to make sure I won't mistake you for a "includer" do not link directly to the file, link to this post instead.
If you stick to these few rules you can use my script. A guide is to be found within the file (all commented out of course) - using the script shouldn't be too hard. Good luck with your web designing.
Changelog
- changed the name of main function from send to request
- added an argument to request in preparation for POST support
- changed GET cases to work with new args argument
- added POST support
- made XMLHttpRequest variable local - solving problems with multiple calls after eachother
- renamed the XMLHttpRequest variable from submitting to XHRequest
- removed time-out as changes should have taken away any reason for it
- deleted highPrioritySend function, as it would do nothing now
- removed global variables busy and time_out that were related to time outs
- made receive an inline, unnamed function inside request - allowing easier variable names
- removed global variable next_function, as this allowed todo to be used directly (woot, no global variables anymore)
Wednesday, December 12, 2007
POST in xmlHttpRquests
Just a quick hello and dropping by a link. It's what helped me getting POST working in xmlHttpRequest.
The point is that you actually need to set some headers, to go along with that request. No long story about it for now, just a link: http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
Hope it helps some of you out.
The point is that you actually need to set some headers, to go along with that request. No long story about it for now, just a link: http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
Hope it helps some of you out.
Subscribe to:
Posts (Atom)