Thursday, May 22, 2008

Include External Files

I use certain "boilerplate" text in all of my scripts for work. I use the same toolsets with the same setup in different combinations with different filtering, but getting started is always the same. So far, I've been happiest with Idea Knot, but I've always wanted to that flexibility in a format I could easily share with others.

So yesterday I started looking for a JavaScript, XML, or PHP way to display external files selectively. I did not find an easy PHP approach with Google. I found an XML merge that I thought would be easiest to configure although a little harder for others to use, but it didn't work for me. I probably didn't configure my input XML files properly, although they passed xmllint. I have ideas on what to tweak to get it to work, but I decided instead to maximize my time and move on to what would be easier for everyone (myself included!) to use: JavaScript. I found an excellent tutorial on including other files on a web page, with an example. There's another example that converts the other file before displaying it. Very cool! So I whipped up a quick variant using my files, and what do you know?: it worked! Since I have no experience with JavaScript, I'm allowed to be surprised that it was easy. I even understand what the code does! Very nice.

On the first pass, I found how to do this with JavaScript with all of the boilerplate contained in JavaScript variables, but that made the monolithic web page so very large. Also, I do update my boilerplate as I learn new tricks and add new toolsets, and updating a monolithic page is tedious to say the least. So that's when I started looking for a way move from inline variables to external files to store my code building blocks. I feel good about using good code that I understand, and storing my information in multiple external files that will be easy to maintain.

Building the code generation page and moving from Idea Know to external files will take me a while, but at least now I have all of the components needed. This will be a useful tool to share at work!

No comments:

Post a Comment