lib/ralbum/skin_engine.rb in gf-ralbum-0.0.2 vs lib/ralbum/skin_engine.rb in gf-ralbum-0.0.5
- old
+ new
@@ -1,5 +1,8 @@
+# ralbum
+require 'ralbum/image_strategies/scaled_image_strategy'
+
class SkinEngine
attr_reader :skin
attr_reader :image_strategies
attr_accessor :album_dirname
@@ -9,18 +12,18 @@
@image_strategies = {
"thumb" => ScaledImageStrategy.new( "100x100", 100, 100, 75 ),
"default" => ScaledImageStrategy.new( "640x480", 640, 480, 75 ) }
end
- def copy_skin_res
- skin_res_dir = File.join( skin.skin_dirname, "res" )
- album_res_dir = File.join(@album_dirname, "res")
- if File.directory?( skin_res_dir )
- copy_dir( skin_res_dir, album_res_dir, /(.gif$)|(.css$)|(.js$)|(.png$)/ )
- end
+ # might be refined by subclasses
+ def compile
end
+
+ #############################################################################
+ # configuration
+ #
def configure_skin( xml_skin )
end
def write_xml( xml_skins)
skin_el = xml_skins.add_element( "skin" )
@@ -35,10 +38,24 @@
# xml_r.attributes[r.name] = r.value
# }
end
+ #############################################################################
+ # utilities for album creation
+ #
+ def copy_skin_res
+ skin_res_dir = File.join( skin.skin_dirname, "res" )
+ album_res_dir = File.join(@album_dirname, "res")
+ if File.directory?( skin_res_dir )
+ copy_dir( skin_res_dir, album_res_dir, /(.gif$)|(.css$)|(.js$)|(.png$)/ )
+ end
+ end
+
+ #############################################################################
+ # create album
+ #
def create( albumTree )
ralbum_verbose(1, "skin create #{skin.skin_name}")
copy_skin_res
# TODO: aggiungere parametro di configurazione per dire se si vuole una sottodirectory per lo skin
@@ -46,37 +63,35 @@
# visitor = PrintTreeNodeVisitor2.new
# albumTree.accept( visitor )
- # exit
-
visitor = CallbackTreeNodeVisitor.new
- visitor.onEnterTreeNode { |album| self.create_album_page( album ) }
- visitor.onVisitLeafNode { |image| self.create_image_page( image ) }
+ visitor.on_enter_tree_node { |album| self.create_album_page( album ) }
+ visitor.on_visit_leaf_node { |image| self.create_image_page( image ) }
albumTree.accept( visitor )
# create_tree_page( album )
end
#
# create album page
#
- def create_album_page( albumNode )
- page = render_album_page( albumNode )
- album_dirname = File.join( @album_dirname, albumNode.path_from_root )
+ def create_album_page( album_node )
+ page = render_album_page( album_node )
+ album_dirname = File.join( @album_dirname, album_node.path )
FileUtils.mkpath( album_dirname ) unless File.exist?( album_dirname )
outpath = File.join( album_dirname, "index.html" )
ralbum_verbose(2, "Writing #{album_dirname}" )
File.open( outpath , "w" ) { |f|
f.puts page
}
end
- def create_image_page( imagePoolNode )
- page = render_image_page(imagePoolNode)
- outpath = File.join( @album_dirname, imagePoolNode.parent.path_from_root, imagePoolNode.defaultImageFile.pageurl )
- ralbum_verbose( 2, " Writing #{imagePoolNode.defaultImageFile.pageurl} " )
+ def create_image_page( image_pool_node )
+ page = render_image_page(image_pool_node)
+ outpath = File.join( @album_dirname, image_pool_node.parent.path, image_pool_node.default_image_file.page_url )
+ ralbum_verbose( 2, " Writing #{image_pool_node.default_image_file.page_url} " )
File.open( outpath , "w" ) { |f|
f.puts page
}
end