remember preferred size of user with a cookie
authorgc <gc>
Mon, 18 Apr 2005 21:12:50 +0000 (21:12 +0000)
committergc <gc>
Mon, 18 Apr 2005 21:12:50 +0000 (21:12 +0000)
bin/booh
data/booh/themes/simple/skeleton_image.html
data/booh/themes/simple/skeleton_thumbnails.html
lib/booh/booh-lib.rb
lib/booh/html-merges.rb

index 731461c7b7cc9ea27ba65318bf4f234f0fadf818..baed8470abd9d674a61cefdf99a995ee3e90f183 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -184,7 +184,7 @@ def replace_line(surround, keyword, line)
     begin
         contents = eval "$#{keyword}"
         line.sub!(/#{surround}#{keyword}#{surround}/, contents)
-    rescue NameError
+    rescue TypeError
         die _("No `%s' found for substitution") % keyword
     end
 end
@@ -215,8 +215,11 @@ def urlencode(text)
   end
 end
 
-def html_refresh(target)
-    return "<html><head><META http-equiv='refresh' content='0;URL=#{target}'></head><body></body></html>"
+def html_reload_to_thumbnails
+    html_reload_to_thumbnails = $preferred_size_reloader.clone
+    html_reload_to_thumbnails.gsub!(/~~theme~~/, $theme)
+    html_reload_to_thumbnails.gsub!(/~~default_size~~/, $default_size['name'])
+    return html_reload_to_thumbnails
 end
 
 def discover_iterations(iterations, line)
@@ -459,6 +462,8 @@ def walk_source_dir
                     type = images.include?(file) ? 'image' : videos.include?(file) ? 'video' : nil
                     if type
                         html_thumbnails += run_iterations(iterations)
+                        html_thumbnails.gsub!(/~~theme~~/, $theme)
+                        html_thumbnails.gsub!(/~~current_size~~/, sizeobj['name'])
                         if type == 'image'
                             index = images.index(file)
                             html_thumbnails.gsub!(/~~image_iteration~~/,
@@ -493,6 +498,11 @@ def walk_source_dir
                 ios.close
             end
 
+            #- generate "main" thumbnails.html page that will reload to correct size thanks to cookie
+            ios = File.open("#{dest_dir}/thumbnails.html", "w")
+            ios.write(html_reload_to_thumbnails)
+            ios.close
+
             #- generate image.html (page with fullscreen images)
             if images.size > 0
                 #- don't ask me why I need so many backslashes... the aim is to print \\\" for each " in the javascript source
@@ -515,6 +525,8 @@ def walk_source_dir
                         i.sub!(/~~captions~~/, captions4js)
                         i.sub!(/~~title~~/, xmldir.attributes['thumbnails-caption'] || utf8(File.basename(dir)))
                         i.sub!(/~~thumbnails~~/, '<a href="thumbnails-' + sizeobj['name'] + '.html">' + utf8(_('Return to thumbnails')) + '</a>')
+                        i.sub!(/~~theme~~/, $theme)
+                        i.sub!(/~~current_size~~/, sizeobj['name'])
                         for sizeobj2 in $images_size
                             if sizeobj != sizeobj2
                                 i.sub!(/~~size_#{sizeobj2['name']}~~/,
@@ -587,13 +599,6 @@ def walk_source_dir
     end
 
     #- second pass to create index.html files
-    default_thumbnails = $images_size.detect { |sizeobj| sizeobj['default'] }
-    if !default_thumbnails
-        die _("Theme `%s' has no default size.") % $theme
-    else
-        default_thumbnails = default_thumbnails['name']
-    end
-
     msg 3, _("\trescanning directories to generate all `index.html' files...")
 
     `find #{$source} -type d`.each { |dir|
@@ -637,7 +642,7 @@ def walk_source_dir
                 gen_thumbnails_subdir(from_utf8(xmldir.attributes['thumbnails-captionfile']), xmldir, false,
                                       [ { 'filename' => thumbnail, 'size' => $albums_thumbnail_size } ], 'thumbnails')
                 html_index += run_iterations(iterations)
-                html_index.gsub!(/~~image_iteration~~/, "<a href='thumbnails-#{default_thumbnails}.html'>" + img_element(thumbnail) + '</a>')
+                html_index.gsub!(/~~image_iteration~~/, "<a href='thumbnails.html'>" + img_element(thumbnail) + '</a>')
                 html_index.gsub!(/~~caption_iteration~~/, xmldir.attributes['thumbnails-caption'])
             end
             #- cleanup temp for videos
@@ -664,7 +669,7 @@ def walk_source_dir
             end
             
         else
-            html = html_refresh("thumbnails-#{default_thumbnails}.html")
+            html = html_reload_to_thumbnails
         end
 
         ios = File.open("#{dest_dir}/index.html", "w")
index 169824fc71ae0191ca03562552383171a84d6470..d7764f8b3585da6c5e0fb92fb2a0bee7097bf85f 100644 (file)
@@ -5,7 +5,7 @@
     <title>~~title~~</title>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
     <meta name="author" content="`Simple' theme - Guillaume Cottenceau">
-    ~~~head_code~~~
+    ~~~image_head_code~~~
     <style type="text/css" media="screen">
     <!--
 body {
index a0e0f7ca688c26343ede42165a881681bdb69183..42ab8fccb39f4ca532f7d67929a6d2c2358e7e31 100644 (file)
@@ -4,6 +4,8 @@
 <head>
     <title>~~title~~</title>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+    <meta name="author" content="`Simple' theme - Guillaume Cottenceau">
+    ~~~thumbnails_head_code~~~
     <style type="text/css" media="screen">
     <!--
 body {
index efbf1ea4925c6eca443767cc2e5c38eb364ce270..15868e5f13ad43c95fd779e5f898af865a6e716c 100644 (file)
@@ -88,6 +88,9 @@ module Booh
         end
         require "#{themedir}/metadata/parameters.rb"
         $default_size = $images_size.detect { |sizeobj| sizeobj['default'] }
+        if $default_size == nil
+            die _("Theme `%s' has no default size.") % $theme
+        end
     end
 
     def entry2type(entry)
index 26489505e5cbfcdcdb2ad5932aa8b915383f453b..4ea0da4826db170d941c45487014f53a8763eb77 100644 (file)
@@ -26,7 +26,7 @@ bindtextdomain("booh")
 require 'booh/booh-lib'
 include Booh
 
-$head_code = <<'EOF'
+$image_head_code = <<'EOF'
 <meta name="generator" content="Generated by Booh! http://zarb.org/~gc/html/booh.html">
 
 <script language="JavaScript1.1" type="text/JavaScript">
@@ -98,7 +98,7 @@ function preload() {
 }
 
 function init() {
-  
+
     /* retrieve GET parameters */
     all_params = location.href.split("?")
     if (all_params.length > 1) {
@@ -269,8 +269,8 @@ function run_slideshow() {
 </script>
 EOF
 
-$head_code.sub!('~~run_slideshow~~', utf8(_('Run slideshow!')))
-$head_code.sub!('~~stop_slideshow~~', utf8(_('Stop slideshow')))
+$image_head_code.sub!('~~run_slideshow~~', utf8(_('Run slideshow!')))
+$image_head_code.sub!('~~stop_slideshow~~', utf8(_('Stop slideshow')))
 
 $body_additions = <<'EOF'
 onload="init()" id="body"
@@ -322,3 +322,40 @@ EOF
 $body_code = <<'EOF'
 EOF
 
+
+$thumbnails_head_code = <<'EOF'
+<script language="JavaScript1.1" type="text/JavaScript">
+    var expires = new Date(new Date().getTime() + (30 * 86400000));  // 30 days
+    document.cookie = 'booh-preferred-size-~~theme~~=~~current_size~~'
+                      + '; expires=' + expires.toGMTString()
+                      + '; path=/';
+</script>
+EOF
+
+
+$preferred_size_reloader = <<'EOF'
+<html>
+    <head>
+        <script language="JavaScript1.1" type="text/JavaScript">
+
+function getPreferredSize() {
+    if (document.cookie) {
+        var index = document.cookie.indexOf('booh-preferred-size-~~theme~~');
+        if (index != -1) {
+            var oleft = (document.cookie.indexOf('=', index) + 1);
+            var oright = document.cookie.indexOf(';', index);
+            if (oright == -1) {
+                oright = document.cookie.length;
+            }
+            return 'thumbnails-' + document.cookie.substring(oleft, oright) + '.html';
+        }
+    }
+    return 'thumbnails-~~default_size~~.html';
+}
+
+window.location.href = getPreferredSize();
+
+        </script>
+    </head>
+</html>
+EOF