fix previous/next album
authorgc <gc>
Sun, 15 May 2005 22:28:46 +0000 (22:28 +0000)
committergc <gc>
Sun, 15 May 2005 22:28:46 +0000 (22:28 +0000)
bin/booh-backend
lib/booh/booh-lib.rb

index 9a68c907b722ef13cdf7d40baea6774ec9b64d3b..a6525ec75270dc17ac8d295db8fdc2f84a2d6525 100755 (executable)
@@ -382,14 +382,14 @@ 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
+        if xmldir.previous_element_byname('dir')
+            xmldir = xmldir.previous_element_byname('dir')
             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
+                while nextchild = child.next_element_byname('dir')
+                    child = nextchild
                 end
                 relative_pos += xmldir2destdir(child) + '/'
                 xmldir = child
@@ -414,8 +414,8 @@ def find_next_album(xmldir)
         if firstchild = xmldir.elements['dir']
             xmldir = firstchild
             relative_pos += xmldir2destdir(xmldir) + '/'
-        #- next brother (is necessarily a <dir>)
-        elsif nextbro = xmldir.next_element
+        #- next brother
+        elsif nextbro = xmldir.next_element_byname('dir')
             xmldir = nextbro
             relative_pos += '../' + xmldir2destdir(xmldir) + '/'
         else
index 5cfe2a5201795fea68dcc998a871d25d6efe5a16..fbea22fbed217fc458b8cd5996e92ea117e179b3 100644 (file)
@@ -22,6 +22,8 @@
 require 'iconv'
 require 'timeout'
 
+require 'rexml/document'
+
 require 'gettext'
 include GetText
 bindtextdomain("booh")
@@ -358,3 +360,27 @@ class File
         return path.gsub(/\w+\/\.\.\//, '')
     end
 end
+
+class REXML::Element
+    def previous_element_byname(name)
+        n = self
+        while n = n.previous_element
+            if n.name == name
+                return n
+            end
+        end
+        return nil
+    end
+
+    def next_element_byname(name)
+        n = self
+        while n = n.next_element
+            if n.name == name
+                return n
+            end
+        end
+        return nil
+    end
+end
+
+