Class: Project

Inherits:
Object
  • Object
show all
Defined in:
lib/ralbum/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(skin_manager) ⇒ Project

Returns a new instance of Project.



17
18
19
# File 'lib/ralbum/project.rb', line 17

def initialize(skin_manager)
  @skin_manager = skin_manager
end

Instance Attribute Details

#album_dirnameObject

Returns the value of attribute album_dirname.



10
11
12
# File 'lib/ralbum/project.rb', line 10

def album_dirname
  @album_dirname
end

#debug_album_treeObject

Returns the value of attribute debug_album_tree.



15
16
17
# File 'lib/ralbum/project.rb', line 15

def debug_album_tree
  @debug_album_tree
end

#debug_photo_treeObject

Returns the value of attribute debug_photo_tree.



14
15
16
# File 'lib/ralbum/project.rb', line 14

def debug_photo_tree
  @debug_photo_tree
end

#photo_tree_typeObject

Returns the value of attribute photo_tree_type.



8
9
10
# File 'lib/ralbum/project.rb', line 8

def photo_tree_type
  @photo_tree_type
end

#phototree_dirnameObject

Returns the value of attribute phototree_dirname.



7
8
9
# File 'lib/ralbum/project.rb', line 7

def phototree_dirname
  @phototree_dirname
end

#skin_namesObject

Returns the value of attribute skin_names.



12
13
14
# File 'lib/ralbum/project.rb', line 12

def skin_names
  @skin_names
end

Instance Method Details

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/ralbum/project.rb', line 22

def run
      
  # TODO: carica file xml di project
  # TODO: da file xml di project ricava le image strategy
  
  @phototree_dirname = File.expand_path( @phototree_dirname )
  @album_dirname     = File.expand_path( @album_dirname )
  catalog_dirname    = File.join( @phototree_dirname, Catalog::DEFAULT_CATALOG_DIRNAME )
  FileUtils.mkpath( catalog_dirname ) unless File.directory?( catalog_dirname )
  
  #
  # =================================
  #
  skin_name = @skin_names.first
  skin = @skin_manager.get_skin( skin_name )
  skin.engine.album_dirname = @album_dirname
  # TODO: skin.configure( xml_project )

  #
  # step 1: reading phototree
  #

  case @photo_tree_type
  when "rubyphoto"
    require 'ralbum/photo_tree/rubyphoto_photo_tree'
    photo_tree_builder = PhotoTreeBuilder.new
  when "jalbum"
    require 'ralbum/photo_tree/jalbum_photo_tree'
    photo_tree_builder = JalbumPhotoTreeBuilder.new
  else
    raise RAlbumException.new("photo tree type '#{@photo_tree_type}' unknow" )
  end
  photo_tree = photo_tree_builder.run( phototree_dirname )
  # TODO: photoTreeBuilder.configure( xml_project )


  if(@debug_photo_tree)
    puts "---------- PhotoTree"
    puts "root is " + photo_tree.path_with_prefix
    puts photo_tree.to_str
    puts "----------"
  end



  #
  # step 2: build catalog
  #
  
  catalog = Catalog.new( catalog_dirname )
  # catalog.create_images( photoTree, @album_dirname, skin.image_strategies )
  # albums = catalog.create_model( phototree, albums_dir )
  # catalog.model_to_txt( albums )

  #
  # step : generate album_tree
  #
  # TODO: l'album tree e' generato in base allo skin
  generator = GenerateAlbumTreeNodeVisitor.new( album_dirname, catalog, skin.engine.image_strategies )
  album_tree = generator.run( photo_tree )

  if(@debug_album_tree)
    puts "---------- AlbumTree"
    puts "root is " + album_tree.path_with_prefix
    puts album_tree.to_str
    puts "----------"
  end

  #
  # step 3: generate albums
  #
  # $options.outputfilters.each { |filter|
  #   skin = Generator::SkinFactory.get( filter )
  #   skin.create( albums_dir, albums )
  # }
  
  
  #
  # output album tree
  #
  # puts "------------------------------------ AlbumTree"
  # albumTree.accept( PrintTreeNodeVisitor.new )
  
  # TODO: se generare l'album nella directory "skin_name" oppure nella root
  skin.create( album_tree )
  
  retun 0

  #
  # save project
  #
  ralbum_verbose( 1, "phototree - writing metainfo in #{catalog_dirname}" )
  doc = REXML::Document.new
  doc << REXML::XMLDecl.new
  xml_project = doc.add_element( "project" )
  photo_tree_builder.write_xml(photo_tree, xml_project)
  xml_project = File.join( catalog_dirname, "project.xml")
  File.open( xml_project, "w") {|f|
    doc.write( f, 0 )
  }
  return 0
end