Class: GenerateAlbumTreeNodeVisitor
- Inherits:
-
CallbackTreeNodeVisitor2
- Object
- CallbackTreeNodeVisitor2
- GenerateAlbumTreeNodeVisitor
- Defined in:
- lib/ralbum/album_tree/generate_album_tree_node_visitor.rb
Instance Method Summary collapse
- #_on_enter_tree_node(photo_tree_node, parent_album_node) ⇒ Object
- #_on_visit_leaf_node(photo_item, parent_album_node) ⇒ Object
-
#initialize(album_dirname, catalog, image_strategies) ⇒ GenerateAlbumTreeNodeVisitor
constructor
A new instance of GenerateAlbumTreeNodeVisitor.
- #run(photo_tree) ⇒ Object
Constructor Details
#initialize(album_dirname, catalog, image_strategies) ⇒ GenerateAlbumTreeNodeVisitor
Returns a new instance of GenerateAlbumTreeNodeVisitor.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ralbum/album_tree/generate_album_tree_node_visitor.rb', line 13 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 |
Instance Method Details
#_on_enter_tree_node(photo_tree_node, parent_album_node) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/ralbum/album_tree/generate_album_tree_node_visitor.rb', line 36 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 |
#_on_visit_leaf_node(photo_item, parent_album_node) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ralbum/album_tree/generate_album_tree_node_visitor.rb', line 43 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 |
#run(photo_tree) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/ralbum/album_tree/generate_album_tree_node_visitor.rb', line 29 def run( photo_tree ) ralbum_verbose( 1, "generate albumtree" ) ralbum_verbose( 1, "create images" ) photo_tree.accept( self ) root end |