# ralbum require 'ralbum/image_strategies/scaled_image_strategy' class SkinEngine attr_reader :skin attr_reader :image_strategies attr_accessor :album_dirname def initialize(skin) @skin = skin @image_strategies = { "thumb" => ScaledImageStrategy.new( "100x100", 100, 100, 75 ), "default" => ScaledImageStrategy.new( "640x480", 640, 480, 75 ) } 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" ) skin_el.attributes["name"] = skin.skin_name xml_is = skin_el.add_element( "image_stategies" ) @image_strategies.each_pair{ |name,is| is.write_xml( xml_is ) } # xml_res = skin.add_element( "resources") # @resources.each{ |r| # xml_r = xml_res.add_element("resource") # 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 albumTree.prefix_path = skin.skin_name + "/" # visitor = PrintTreeNodeVisitor2.new # albumTree.accept( visitor ) visitor = CallbackTreeNodeVisitor.new 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( 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( 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 # def create_tree_page( album ) # require "inc/skins/#{skin.skin_name}/tree_page" # args = { # :array => Array, # :rootalbum => album, # } # page = view_tree_page args # outpath = @albums_dir + File::Separator + "tree.html" # puts " Writing in #{outpath}" # File.open( outpath , "w" ) { |f| # f.puts page # } # end end