|
|
09.27.2004 |
|
||||||||||
| Web Publishing with Ant Tutorial | ||||||||||||
I'm quite interested in the concept of software components and how those ideas can be applied to Java code. Thoughts or ideas I have on this subject get dropped here for the benefit of humanity and my own hubris.
|
I suppose that everyone has their own particular style for creating web sites. Let me describe some of the features that I need/want:
I don’t think this is too much to ask, do you? I’ve been in the web publishing business a loooong time, and I haven’t found anything that fits this bill, so I’ve been creating a tool to do this job. I now have a number of commercial web sites built using my web publishing system (including my own), and I thought it time to share it will the world. While I am still crafting this thing, it is currently very useful, but it building a web site with this tool is a bit different… Different enough that I thought I better write a tutorial. We’ll dance through this tutorial as a series of steps … stop whenever you get the hang of it and want to take off doing your own moves. 1. Download the GunkTo make this trivial, I’ve created a directory structure that contains everything you need. Download WebSite-Start.zip and unzip it somewhere. All of the supporting code is in the “support” directory, and while you may not need it all, it is all there (and to think the zip file is only a couple of megs). I will assume that you have a JVM(Java Virtual Machine) installed as well as Ant. If not, get those installed before proceeding. Add all of the Jar files in the “support” directory to your 2. Build the Web SiteThe source as well as a default template have already been created as an example for you to use, so just build the site by typing: cd WebSite-Start ant I told you it was simple. Any time you make a change to your content files or your templates, rebuild your web site by invoking 3. Editing Text FilesThe files in the The are actually formatted, but in such a way that a filter can interpret them and convert them into HTML markup, but is also understandable by a human. For instance, instead of typing You can read more about the formatting syntax on the Markdown web site, but I’ve had to add a couple of extra features. If the first line is less than 50 characters, we assume that it is the title of the file (and is available to the template as such). So, it should be very easy for you to drop into that directory and use Notepad or your favorite text editor and create a web page, like: Testing Title This is just a test of the emergency web publishing system. If this had been an actual emergency, you would have been given *actual* content. But you weren't, so it isn't. 4. Edit the Template FileEach file in that It should be time to take a look at the You’ll see them scattered throughout this example template as things that look like By default, you have the following two tags available:
Right now, it is time for you to go forth and play. Manipulate the template and rebuild the site. I should mention that if you change the template, you will need to execute 5. Sidebars and Meta ContentThat isn’t too shabby, but a web site isn’t just about content surrounded by beautiful graphics… well, some are. Let’s suppose we have a template with two columns. The main column will contain the actual content, but the second will contain other stuff. But this other stuff is not constant across all web pages, but changes with each one. Let’s call it a “call-out” and in our case, it will be a quote from the content, but displayed outside of the regular content area. Yes, it is time to introduce some new features. In one of your text files, add the following to the end of the file: sidetext=The lazy dog jumped over the cow. This line is actually not included in the Go ahead and try it. Add that line to the bottom of the You can create and use as many of these lines as you want. It is generally a good idea to make their use conditional in your template engine. For instance, you would do something like For instance, my template file allows you to have the text file contain a 6. I Don’t Like TextYou may or may not like text files as the basis of your web site, but even if you do, there are times that it isn’t enough. Granted, you can type any HTML content you want in these text files and they come across unharmed. But you can create simple HTML pages in DreamWeaver or your favorite web editor and save them off in that directory with an extension of How do I do the sidebars? You simply add the content for sidebars as <meta name="sidetext" content="That old dog..."/> And any of these are now accessible in your template. 6. I Don’t Like XXXXWhile I won’t get into it in much detail, if you aren’t fond of Markdown, you can use Textile instead. You just change the extension of your files from If you aren’t fond of using FreeMarker for the template system, you use either Velocity or StringTemplate. You just need to edit the If you have another template engine you’d rather use, you can, once again, create a plugin for my Ant task. It isn’t that involved, but if programming isn’t your thing, you could drop me a line and see if you can talk me into adding it. If you don’t like my naming convention (like my choice of 6. What’s Next?I haven’t finished illustrating all of my initial requirements, so the next step would be for you to read Part 2 of this tutorial. For in my sequels, I will describe creating dynamic navigational bars and whatnot. However, what I have described should be sufficient for a lot of web sites, but I will leave you with one final, and quite boring, step… 7. Investigating the Directory StructureLet me explain a bit about the directory structure you see. build.xml This is the Ant build script and is used to “do the work” described above. This build script is really just an example, but it just might be fine enough as it is. If you want to use a different template engine or something like that, however, you’ll need to modify it. datafiles This directory contains all of the “source” text files. The contents of these files will be used to create each web page. You’ll notice templates/default.ftl This is the default template that all the text files will be “run through” in order to create each web page. It uses the FreeMarker template format, but should be pretty easy to figure out. templates The templates directory also includes other supporting files and directories, like the support Jar library files needed to build the web site are in here as well as a couple of Perl scripts from John Gruber. Markdown is used to convert text files into simple HTML content, and SmartyPants is used to introduce curly quotes and other typographical features to HTML files. The All of the files in this directory are open source and freely available… including my own. Once you have built the web site, you see a couple of other directories that are created: tmp/htmldata Text files from the tmp/web Each file from the web Each of the simple web pages in Read Part 2 …
Thought originally posted on Monday, 27 September 2004
© 2004-2005, Howard Abrams • Except where otherwise noted, all original content is licensed under a Creative Commons License (see details). Another web page that references this entry...
Web Publishing with Ant Tutorial
|
|||||||||||
|
||||||||||||