Friday, December 24, 2010

Buried in JQuery -- Moving old pages and repurposing

For the last few days, I have been converting an old perl-based set of web pages in the a JavaScript-based set of web pages. It's sort of an interesting project in that, the perl used algorithms to create links that would display files for users.

Sounds simple, but, of course, it wasn't. First a bit about the project. These are VERY old files which are maintained for historic reasons online. They are static and the file names are created in such a way to be able to be algorithmically derived. For example "type_date.ext". So far, so good.

When this set of pages was live, the perl needed to read the folders to create the pulldowns for available files. It would start with the base day and work it's way to the current day using routines from the excellent Date::Manip module. Luckily, that isn't needed now, so JavaScript becomes a good alternative. Oh, by the way, we're moving these files from one server to another, thus the reason for rewriting.

Rather than writing programs to gather the dates from the file system, I started with the finished web pages generated by the existing perl programs. That is, I displayed the page in my browser and saved it. This gave me a base page with all the select fields already populated with the original files. If you use this technique, be sure to check for relative links which are now displayed as static links (the full link including the domain). You will want to edit these back to relative links. Usually a simple matter as you can find-and-replace with your favorite text editor.

It was then a reasonably simple matter to create the JavaScript to format the pages and display them. I found, that, for the most part, I was able to translate the perl subs into JavaScript (JQuery) functions. Straight across.

One interesting problem was unwinding some code that was in the perl to accommodate the original real-time operation of the pages. For example, depending on the hour of the day, the files might not be present. Since these are now static pages, in essence, this code is not necessary and might even cause some problems. After working through that with a couple of cases, I was able to complete the project successfully.

No comments:

Post a Comment