+ 01 + .<extension>.
Note that the numbers should go from 01 to 99. Starting
from "1" (as opposed to "01") causes trouble.
5. Generate the XML file with the -x parameter.
6. Edit the XML file by adding proper titles for each slide
and commentary between <p> tags. You can have more than one
paragraph of commentary (in <p> tags.)
7. Generate the site by running this program with the -s parameter.
8. To change the look of the pages you can edit the
PageTemplate Constant below. The program will substitute
content for the @@@?????@@@ codes.
END_HELP
# Here are the Constants.
ProjectTitle = "Santa Fe; A Photo Essay" # This is the title for the project. Used below.
ProjectSeed = "santafe" # This is the seed for the html file names
Thumbnails = "thumbs" # This is where thumbnails should reside. Put "no" if no thumnails.
Signature = "GR. June 2003" # This goes at the end of each page
ImageExtension = "jpg" # This is the extension for the images handled
PageTemplate =<<END_CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>@@@pageTitle@@@</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#000000" text="#FF9933@@@</font>
<p>
<font size="-2">
<a href="@@@prev@@@">[Previous]</a>
<a href="@@@next@@@">[Next]</a>
</font>
</p>
<p>
@@@thumbs@@@
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
END_CODE
XMLTemplate = <<END_CODE
<?xml version="1.0" ?>
<slideShow>
<head>
<title>@@@pageTitle@@@</title>
<date>@@@date@@@</date>
</head>
<body>
@@@pageContent@@@
</body>
</slideShow>
END_CODE
require "cgi" # Used by CgiSession
require "rexml/document"
include REXML
require "getoptlong"
class XMLPage
def initialize(template = XMLTemplate)
@pageOut = template
end
def fill(title = "Test Page", content = "Hello World")
@pageOut.gsub!("@@@pageTitle@@@", title)
@pageOut.gsub!("@@@pageContent@@@", content)
end
def retPage
return @pageOut
end
def outPut(titleTxt = "Test Page", content = "Hello World")
cgi = CGI.new("html3")
cgi.out {
cgi.html {
cgi.head { cgi.title{titleTxt} } +
cgi.body { content }
}
}
end
def writePage(fileName = ProjectSeed, extension = ".txt")
myFile = FCreate.new(fileName, extension, @pageOut)
end
def XMLPage.tag(content, tagName = "p")
return "<" + tagName + ">" + content + "</" + tagName + ">"
end
end
class FCreate
def initialize(fileName = ProjectSeed, extension = ".txt", contents = "")
docFile = File.open(fileName + extension, "w")
docFile.puts(contents)
docFile.close()
end
end
class WebSite
def initialize(seed = ProjectSeed, xmlFile = "", template = PageTemplate)
@seedN = seed
if xmlFile != "" then
fileIn = File.new( xmlFile )
@doc = Document.new fileIn
end
@template = PageTemplate
@thumbsHtml = ""
end
def buildPages
counter = 1
maxNumber = XPath.match( @doc, "//slide" )
@doc.elements.each("//slide") do | item |
page = buildPage(item, counter, maxNumber.length)
counter = counter + 1
end
end
def buildPage(slideIn, num, max)
page = ""
fileName = ""
page << @template
htmlFrag = ""
slideIn.elements.each("title") do | item |
htmlFrag = item.text.to_s
end
page.gsub!("@@@title@@@", htmlFrag)
page.gsub!("@@@pageTitle@@@", ProjectTitle)
page.gsub!("@@@signature@@@", Signature)
slideIn.elements.each("image") do | item |
htmlFrag = item.text.to_s
fileName = htmlFrag
end
page.gsub!("@@@image@@@", htmlFrag)
htmlFrag = ""
slideIn.elements.each("p") do | item |
htmlFrag << item.to_s # item.text.to_s
end
page.gsub!("@@@text@@@", htmlFrag)
fileName.gsub!("." + ImageExtension, "")
fileN = fileName
if num == 1 then
filePrev = fileName.chop.chop + max.to_s + ".html"
else
filePrev = fileName.chop.chop + prevNum(num) + ".html"
end
page.gsub!("@@@prev@@@", filePrev)
if num == max then
fileNext = fileName.chop.chop + "01" + ".html"
else
fileNext = fileName.chop.chop + nextNum(num) + ".html"
end
page.gsub!("@@@next@@@", fileNext)
if Thumbnails != "no" then
page.gsub!("@@@thumbs@@@", @thumbsHtml)
else
page.gsub!("@@@thumbs@@@", "")
end
newPage = FCreate.new(fileN, ".html", page)
end
def nextNum(number)
nxt = number + 1
if nxt < 10 then
return "0" + nxt.to_s
else
return nxt.to_s
end
end
def prevNum(number)
previous = number - 1
if previous < 10 then
return "0" + previous.to_s
else
return previous.to_s
end
end
def buildThumbs(location)
thumbs = ""
thumbslist = FileList.new( "*." + ImageExtension, Thumbnails)
thumbsA = thumbslist.retArray
thumbsA.each do | item |
itemshort = item.gsub(location + "/", "")
itemshort.gsub!(".jpg", "")
thumbs << "<a href=\"" + itemshort + ".html" + "\"><img src=\"" + item + "\"></a>"
end
@thumbsHtml = thumbs
end
end
class FileList
def initialize( pttrn = "*." + ImageExtension , folder = "" )
if folder == "" then
folderLoc = ""
else
folderLoc = folder + "/"
end
whatToFind = folderLoc + pttrn
@fileList = Dir[whatToFind]
end
def retArray
return @fileList
end
def retTagged
taggedFrag = ""
@fileList.each do | item |
taggedFrag << "<slide>\n<title>" + item + "</title>\n" + "<p>\n\n</p>\n"
taggedFrag << XMLPage.tag(item, "image") + "\n</slide>\n\n"
end
return taggedFrag
end
end
# get command line options
opts = GetoptLong.new(
[ "--makeXml", "-x", GetoptLong::NO_ARGUMENT ],
[ "--makeSite", "-s", GetoptLong::NO_ARGUMENT ],
[ "--help", "-h", GetoptLong::NO_ARGUMENT ]
)
# process the parsed options
param1 = ""
opts.each do |opt, arg|
param1 = "s" if opt == "--makeSite"
param1 = "" if opt == "--makeXml"
param1 = "h" if opt == "--help"
end
# main program
if param1 == "" then
# Get list of files
listOfFiles = FileList.new("*." + ImageExtension,"")
fileList = listOfFiles.retTagged
# Create Web Page
pageCreate = XMLPage.new(XMLTemplate)
pageCreate.fill(ProjectTitle, fileList)
pageCreate.writePage(ProjectSeed, ".xml")
print pageCreate.retPage
elsif param1 == "s" then
mySite = WebSite.new(ProjectSeed, ProjectSeed + ".xml")
if Thumbnails != "no" then
mySite.buildThumbs(Thumbnails)
end
mySite.buildPages
elsif param1 == "h" then
print HelpText
end