html.sub!(/~~sizes~~(.+)~~/) { sizestrings.join($1) }
end
+def xmldir2destdir(xmldir)
+ return make_dest_filename(from_utf8(File.basename(xmldir.attributes['path'])))
+end
+
+def find_previous_album(xmldir)
+ relative_pos = ''
+ begin
+ #- move to previous dir element if exists
+ if xmldir.previous_element && xmldir.previous_element.name == 'dir'
+ xmldir = xmldir.previous_element
+ relative_pos += '../' + xmldir2destdir(xmldir) + '/'
+ child = nil
+ #- after having moved to previous dir, we need to go down last subdir until the last one
+ while child = xmldir.elements['dir']
+ while child.next_element
+ child = child.next_element
+ end
+ relative_pos += xmldir2destdir(child) + '/'
+ xmldir = child
+ end
+ else
+ #- previous dir doesn't exist, move to previous dir element if exists
+ xmldir = xmldir.parent
+ if xmldir.name == 'dir'
+ relative_pos += '../'
+ else
+ return nil
+ end
+ end
+ end while !xmldir.elements['image'] && !xmldir.elements['video']
+ return File.reduce_path(relative_pos)
+end
+
+def find_next_album(xmldir)
+ relative_pos = ''
+ begin
+ #- first child dir element (catches when initial xmldir has both thumbnails and subdirs)
+ if firstchild = xmldir.elements['dir']
+ xmldir = firstchild
+ relative_pos += xmldir2destdir(xmldir) + '/'
+ #- next brother (is necessarily a <dir>)
+ elsif nextbro = xmldir.next_element
+ xmldir = nextbro
+ relative_pos += '../' + xmldir2destdir(xmldir) + '/'
+ else
+ #- go up until we have a next brother or we are finished
+ begin
+ xmldir = xmldir.parent
+ relative_pos += '../'
+ end while xmldir && !xmldir.next_element
+ if xmldir
+ xmldir = xmldir.next_element
+ relative_pos += '../' + xmldir2destdir(xmldir) + '/'
+ else
+ return nil
+ end
+ end
+ end while !xmldir.elements['image'] && !xmldir.elements['video']
+ return File.reduce_path(relative_pos)
+end
+
+def sub_previous_next_album(previous_album, next_album, html)
+ if previous_album
+ html.gsub!(/~~previous_album~~/, '<a href="' + previous_album + 'thumbnails.html">' + utf8(_('previous album')) + '</a>')
+ html.gsub!(/~~ifprevious_album\?~~(.+?)~~fi~~/) { $1 }
+ else
+ html.gsub!(/~~previous_album~~/, '')
+ html.gsub!(/~~ifprevious_album\?~~(.+?)~~fi~~/, '')
+ end
+ if next_album
+ html.gsub!(/~~next_album~~/, '<a href="' + next_album + 'thumbnails.html">' + utf8(_('next album')) + '</a>')
+ html.gsub!(/~~ifnext_album\?~~(.+?)~~fi~~/) { $1 }
+ else
+ html.gsub!(/~~next_album~~/, '')
+ html.gsub!(/~~ifnext_album\?~~(.+?)~~fi~~/, '')
+ end
+end
+
def walk_source_dir
#- preprocess the path->dir, rexml is very slow with that; we seem to improve speed by 7%
end
msg 3, _("\tgenerating HTML pages...")
+
+ previous_album = find_previous_album(xmldir)
+ next_album = find_next_album(xmldir)
#- generate thumbnails.html (page with thumbnails)
for sizeobj in $images_size
i.sub!(/~~thumbnails~~/, html_thumbnails)
i.gsub!(/~~theme~~/, $theme)
i.gsub!(/~~current_size~~/, sizeobj['name'])
+ sub_previous_next_album(previous_album, next_album, i)
end
ios = File.open("#{dest_dir}/thumbnails-#{sizeobj['name']}.html", "w")
ios.write(html)
#- generate image.html (page with fullscreen images)
if images.size > 0
captions4js = find_captions(xmldir, images).collect { |e| e ? '"' + e.gsub('"', '\"' ) + '"' : '""' }.join(', ')
+
for sizeobj in $images_size
html = $html_images.collect { |l| l.clone }
images4js = fullscreen_images[sizeobj['name']].collect { |e| "\"#{e}\"" }.join(', ')
i.gsub!(/~~captions~~/, captions4js)
i.gsub!(/~~title~~/, xmldir.attributes['thumbnails-caption'] || utf8(File.basename(dir)))
i.gsub!(/~~thumbnails~~/, '<a href="thumbnails-' + sizeobj['name'] + '.html" id="thumbnails">' + utf8(_('return to thumbnails')) + '</a>')
+ sub_previous_next_album(previous_album, next_album, i)
i.gsub!(/~~theme~~/, $theme)
i.gsub!(/~~current_size~~/, sizeobj['name'])
substitute_html_sizes(i, sizeobj, 'image')