handle captions
authorgc <gc>
Sat, 5 Mar 2005 16:23:11 +0000 (16:23 +0000)
committergc <gc>
Sat, 5 Mar 2005 16:23:11 +0000 (16:23 +0000)
booh
html_merges.rb

diff --git a/booh b/booh
index 6e1f197a88febb851f842554cde97d53d5ba7abf..1cf0533edc092e0b9f38416e604aaf5cea21fef9 100755 (executable)
--- a/booh
+++ b/booh
@@ -37,6 +37,8 @@ $options = [
 
     [ '--theme',         '-t', GetoptLong::REQUIRED_ARGUMENT, "Select HTML theme to use" ],
     [ '--size',          '-z', GetoptLong::REQUIRED_ARGUMENT, "Size of images for `fullscreen' slideshow" ],
+    [ '--captions',      '-C', GetoptLong::REQUIRED_ARGUMENT, "File containing captions of images" ],
+    [ '--captions-skel', '-k', GetoptLong::REQUIRED_ARGUMENT, "Filename where the script will output a captions skeleton" ],
 
     [ '--mproc',         '-m', GetoptLong::REQUIRED_ARGUMENT, "Specify the number of processors for multi-processors machines" ],
 
@@ -48,6 +50,7 @@ $options = [
 $convert = 'convert -interlace line +profile "*"'
 $size = 'medium'
 $verbose_level = 2
+$captions = {}
 
 def usage
     puts "Usage: #{File.basename($0)} [OPTION]..."
@@ -103,10 +106,23 @@ def handle_options
                 select_theme(arg)
             when '--size'
                 $size = arg
+            when '--captions'
+                if File.readable?(arg)
+                    use_captions(arg)
+                else
+                    die 'Captions file does not exist or is unreadable.'
+                end
+            when '--captions-skel'
+                if File.exists?(arg)
+                    die 'Captions skeleton file already exists, won\'t overwrite'
+                else
+                    $captions_skel = arg
+                    $images_list_for_captions = Array.new
+                end
 
             when '--mproc'
                 $mproc = arg.to_i
-                $pids = Array.new()
+                $pids = Array.new
 
             when '--verbose-level'
                 $verbose_level = arg.to_i
@@ -147,6 +163,16 @@ def select_theme(name)
     require "#{themedir}/parameters.rb"
 end
 
+def use_captions(filename)
+    for line in IO.readlines(filename)
+        if line =~ /(\S+): (.+)/
+            $captions[$1] = $2
+        else
+            die "Unrecognized line in #{filename}: #{line}"
+        end
+    end
+end
+
 def check_installation
     if $no_check
         return
@@ -199,6 +225,13 @@ def psys(cmd)
     end
 end
 
+def find_captions(images)
+    if $captions_skel
+        $images_list_for_captions += images
+    end
+    return images.collect { |img| $captions[img] }
+end
+
 def walk_source_dir
     `find #{$source} -type d`.each { |dir|
         dir.chomp!
@@ -231,9 +264,11 @@ def walk_source_dir
         }
 
         html = $skeleton.collect { |l| l.clone }
-        images4js = final_images.collect { |img| "\"#{img}\"" }.join(', ')
+        images4js = final_images.collect { |e| "\"#{e}\"" }.join(', ')
+        captions4js = find_captions(images).collect { |e| "\"#{e}\"" }.join(', ')
         for i in html
             i.sub!(/~~images~~/, images4js)
+            i.sub!(/~~captions~~/, captions4js)
             i.sub!(/~~title~~/, File.basename(dir))
         end
 
@@ -241,6 +276,12 @@ def walk_source_dir
         ios.write(html)
         ios.close
     }
+
+    if $captions_skel
+        ios = File.open($captions_skel, "w")
+        ios.write($images_list_for_captions.collect { |img| "#{img}: \n" })
+        ios.close
+    end
 end
 
 handle_options
index a3863a3d00a00bf436bd96806bb5422da1cd40a7..a8aaffe66ee8e2c9c7f0bd511bea8a2ee3fe4a85 100644 (file)
@@ -25,6 +25,7 @@ $head_code = <<'EOF'
 <script language="JavaScript1.1" type="text/JavaScript">
 
 var images = new Array(~~images~~);
+var captions = new Array(~~captions~~);
 
 var images_ary = new Array();
 var images_loaded = new Array();
@@ -136,7 +137,7 @@ function show_current_text() {
         eval("document.getElementById('image_counter')" +
                      ".firstChild.data = '" + ( current + 1 ) + "/" + images.length + "'");
         eval("document.getElementById('main_text')" +
-                     ".firstChild.data = '" + images[current] + "'");
+                     ".firstChild.data = '" + ( captions[current] || images[current] ) + "'");
         set_cursor("default");
     } else {
         setTimeout("show_current_text()", 100);