add a "previous album" and "next album" link for each thumbnails and image page
authorgc <gc>
Fri, 13 May 2005 20:54:42 +0000 (20:54 +0000)
committergc <gc>
Fri, 13 May 2005 20:54:42 +0000 (20:54 +0000)
bin/booh-backend
data/booh/themes/simple/skeleton_image.html
data/booh/themes/simple/skeleton_thumbnails.html
lib/booh/booh-lib.rb

index 2fc0095e094ef332f1ad7a49225642c695ed8a11..9a68c907b722ef13cdf7d40baea6774ec9b64d3b 100755 (executable)
@@ -374,6 +374,84 @@ def substitute_html_sizes(html, sizeobj, type)
     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%
@@ -544,6 +622,9 @@ def walk_source_dir
             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
@@ -592,6 +673,7 @@ def walk_source_dir
                     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)
@@ -606,6 +688,7 @@ def walk_source_dir
             #- 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(', ')
@@ -625,6 +708,7 @@ def walk_source_dir
                         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')
index f46342a9d3a99f04e7c6817308a1159c5ed566a0..fc2589e6ef5493c4ebe68623c849a27c2d157d19 100644 (file)
@@ -70,7 +70,7 @@ input {
         ~~~button_slideshow~~~
         ~~~pause_slideshow~~~
         <br/>
-        <font size="-1">~~thumbnails~~</font>
+        <font size="-1">~~previous_album~~ ~~ifprevious_album?~~|~~fi~~ ~~thumbnails~~ ~~ifnext_album?~~|~~fi~~ ~~next_album~~</font>
 </tr>
 </table>
 </html>
index 6f54032befb0eaa909e376d552ff0bbb9ad7bccc..5ab84e15420b774cf279de5ef0aed6090c18a414 100644 (file)
@@ -60,7 +60,7 @@ input {
 ~~iterate1_close~~
 </table>
 
-<p align="center">~~return_to_albums~~</p>
+<p align="center">~~previous_album~~ ~~ifprevious_album?~~|~~fi~~ ~~return_to_albums~~ ~~ifnext_album?~~|~~fi~~ ~~next_album~~</p>
 
 </body>
 </html>
index 94107f79982ca0e8f10cd735032f66aafba019b6..5cfe2a5201795fea68dcc998a871d25d6efe5a16 100644 (file)
@@ -350,4 +350,11 @@ module Booh
     def max(a, b)
         a > b ? a : b
     end
+
+end
+
+class File
+    def File.reduce_path(path)
+        return path.gsub(/\w+\/\.\.\//, '')
+    end
 end