# -*-ruby-*- # # Picture gallery processor/generator # Part of nysagallery # # Copyright (c) 2006, 2007 Stephen Williams, all rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the copyright holder may not be used to endorse or # promote products derived from this software without specific prior # written permission. # # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # require './gallery_lib' class GalleryPage RCS_ID = "$Id: gallery.rbx,v 1.9 2007/01/03 12:40:14 stephen Exp $" include GalleryLib attr_reader :cgi # Constructor def initialize @cgi = CGI.new @gallery = nil @gallery_name = nil @section_html = "" @section_title = nil @thumbnail_on_left = true end # Generates the gallery document def generate @gallery_name = @cgi['gallery'] die("BAD_REQUEST", "No gallery specified") if @gallery_name.length == 0 File.open("gallery.dump", "r") do |file| galleries = Marshal.restore(file) @gallery = galleries[@gallery_name] die("NOT_FOUND", "No such gallery") unless @gallery end section_name = @cgi['section'] section_name = nil if section_name.length == 0 if !section_name if @gallery.sections.size > 1 generate_section_selection else generate_all_sections end generate_link_back elsif section_name == "ALL" generate_all_sections else generate_section(section_name) generate_navbar(section_name) if @gallery.sections.size > 1 end end # Outputs the HTML def output desc = @gallery.description ? "
#{@gallery.description}
" : "" subtitle = @section_title ? " : " + @section_title : "" @cgi.out do <Created: #{@gallery.created}
#{desc} #{@section_html}Generated from
#{@gallery_name}.xml
#{GalleryLib.rcs_mangle(RCS_ID)}
#{GalleryLib.rcs_mangle(GalleryLib::RCS_ID)}
#{section.description}
\n" if section.description @section_html << "" +
GalleryLib.format_thumbnail(@gallery, section, picture) +
" #{picture.width} x #{picture.height} | "
text_cell = "" + GalleryLib.format_picture(@gallery, section, picture) + " | " if @thumbnail_on_left @section_html << thumbnail_cell @section_html << text_cell else @section_html << text_cell @section_html << thumbnail_cell end @section_html << "
This gallery consists of #{@gallery.sections.size} sections, " << "containing a total of #{@gallery.picture_count} pictures. " << "Choose which section you would like to view, or " << "view the entire gallery " << "on one page.
\n| #{thumb} | \n" << "" <<
"#{section.title} #{section.description} " if section.description @section_html << " |