fix previous/next not subtituted in case of not using --config
authorgc <gc>
Thu, 26 May 2005 20:56:57 +0000 (20:56 +0000)
committergc <gc>
Thu, 26 May 2005 20:56:57 +0000 (20:56 +0000)
bin/booh-backend
lib/booh/booh-lib.rb

index 35a89680f10d64ee51e67abb957b3736f7608c1f..e40f7c723ed99d0737b2d0ca90ac8611d82c4573 100755 (executable)
@@ -493,6 +493,7 @@ def sub_previous_next_album(previous_album, next_album, html)
         html.gsub!(/~~next_album~~/, '')
         html.gsub!(/~~ifnext_album\?~~(.+?)~~fi~~/, '')
     end
+    return html
 end
 
 def walk_source_dir
@@ -674,9 +675,6 @@ def walk_source_dir
 
             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
                 info("processing size")
@@ -725,7 +723,6 @@ 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)
@@ -762,7 +759,6 @@ 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')
@@ -821,7 +817,7 @@ def walk_source_dir
         return
     end
 
-    #- second pass to create index.html files
+    #- second pass to create index.html files and previous/next links
     info("creating index.html")
     msg 3, _("\trescanning directories to generate all `index.html' files...")
 
@@ -835,6 +831,9 @@ def walk_source_dir
         end
         dest_dir = make_dest_filename(dir.sub(/^#{Regexp.quote($source)}/, $dest))
 
+        previous_album = find_previous_album(xmldir)
+        next_album = find_next_album(xmldir)
+
         if xmldir.elements['dir']
             html = $html_index.collect { |l| l.clone }
             iterations = {}
@@ -902,25 +901,26 @@ def walk_source_dir
         ios.write(html)
         ios.close
 
-        #- substitute "return to albums" correctly
-        `find '#{dest_dir}' -maxdepth 1 -name "thumbnails*.html"`.each { |thumbnails|
-            thumbnails.chomp!
-            contents = File.open(thumbnails.chomp).readlines
-            for i in contents
+        #- substitute "return to albums" and previous/next correctly
+        for sizeobj in $images_size
+            substInFile("#{dest_dir}/thumbnails-#{sizeobj['name']}.html") { |line|
+                sub_previous_next_album(previous_album, next_album, line)
                 if xmldir.elements['dir']
-                    i.sub!(/~~return_to_albums~~/, '<a href="index.html">' + utf8(_('return to albums')) + '</a>')
+                    line.sub!(/~~return_to_albums~~/, '<a href="index.html">' + utf8(_('return to albums')) + '</a>')
                 else
                     if xmldir.parent.name == 'dir'
-                        i.sub!(/~~return_to_albums~~/, '<a href="../index.html">' + utf8(_('return to albums')) + '</a>')
+                        line.sub!(/~~return_to_albums~~/, '<a href="../index.html">' + utf8(_('return to albums')) + '</a>')
                     else
-                        i.sub!(/~~return_to_albums~~/, '')
+                        line.sub!(/~~return_to_albums~~/, '')
                     end
                 end
-            end
-            ios = File.open(thumbnails, "w")
-            ios.write(contents)
-            ios.close
-        }
+                line
+            }
+            substInFile("#{dest_dir}/image-#{sizeobj['name']}.html") { |line|
+                sub_previous_next_album(previous_album, next_album, line)
+            }
+        end
+
     }
 
     msg 3, _(" all done.")
index f03beedb366d8207df0c1b7c51924a573f977e96..774672ed5c66d64c865283be65a0b252fd295411 100644 (file)
@@ -379,6 +379,13 @@ module Booh
     def max(a, b)
         a > b ? a : b
     end
+
+    def substInFile(name)
+        newcontent = IO.readlines(name).collect { |l| yield l }
+        ios = File.open(name, "w")
+        ios.write(newcontent)
+        ios.close
+    end
 end
 
 class File