#treevisitor require 'treevisitor/tree_node_visitor' require 'treevisitor/visitors/callback_tree_node_visitor2' # ralbum require 'ralbum/album_tree/album' require 'ralbum/album_tree/image_pool' require 'ralbum/album_tree/image_file' class GenerateAlbumTreeNodeVisitor < CallbackTreeNodeVisitor2 def initialize( album_dirname, catalog, image_strategies ) super() @album_dirname = album_dirname @catalog = catalog @image_strategies = image_strategies # TODO: eliminare le seguenti chiamate, trovare il visitor giusto da cui ereditare on_enter_tree_node do |photo_tree_node, parentAlbumNode| _on_enter_tree_node photo_tree_node, parentAlbumNode end on_visit_leaf_node do |photo_item, parent_album_node| _on_visit_leaf_node photo_item, parent_album_node end end def run( photo_tree ) ralbum_verbose( 1, "generate albumtree" ) ralbum_verbose( 1, "create images" ) photo_tree.accept( self ) root end def _on_enter_tree_node(photo_tree_node, parent_album_node) album_key = @catalog.album_key( photo_tree_node.path ) album_title = photo_tree_node.name # instead of photo_tree_node["title"] album_desc = photo_tree_node["shortdesc"] albumNode = Album.new( parent_album_node, album_key, album_title, album_desc ) end def _on_visit_leaf_node(photo_item, parent_album_node) photo_key = @catalog.key( photo_item.photo_file.md5 ) photo_title = photo_item.title photo_desc = photo_item.description image_pool = ImagePool.new( parent_album_node, photo_item.photo_file.md5, photo_key, photo_title, photo_desc ) msg = "" @image_strategies.each_pair {|name,image_strategy| image_basename = @catalog.photo_file( photo_item ) inpath = photo_item.photo_file.path outdir = File.join( @album_dirname, "images_" + image_strategy.name ) outpath = File.join( outdir, image_basename ) msg += "#{name} " if File.exist?(outpath) and File.mtime(inpath) < File.mtime(outpath) msg += "(s) " else Dir.mkdir( outdir ) unless File.exist?( outdir ) msg += image_strategy.build( inpath, outpath ) end src_url = File.join(image_pool.relroot_with_prefix, "images_" + image_strategy.name, image_basename) image = ImageFile.new( image_pool, outpath, src_url, image_basename + ".html" ) image_pool.image( name, image ) } ralbum_verbose( 2, sprintf("%40s: %s \n", photo_item.basename, msg ) ) end end