Class: Gallerizer
Instance Method Summary collapse
- #gallerize ⇒ Object
-
#initialize(name, output_path, theme) ⇒ Gallerizer
constructor
A new instance of Gallerizer.
Constructor Details
#initialize(name, output_path, theme) ⇒ Gallerizer
Returns a new instance of Gallerizer.
11 12 13 14 15 |
# File 'lib/gallerizer.rb', line 11 def initialize(name, output_path, theme) @name = name @output_path = output_path @theme_path = File.join(File.dirname(__FILE__), "..", "themes", theme) end |
Instance Method Details
#gallerize ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gallerizer.rb', line 17 def gallerize # Create necessary output paths mkdir_p([@output_path, File.join(@output_path, "thumbs"), File.join(@output_path, "show"), File.join(@output_path, "resources")]) # Copy resource files cp_r(File.join(@theme_path, "resources/."), File.join(@output_path, "resources")) # Gather images image_paths = Dir["*.jpg"].natural_sort @images = image_paths.collect { |image_path| Image.new(image_paths.index(image_path), File.(image_path), @output_path) } # Load templates index_template = ERB.new(File.open(File.join(@theme_path, "index.html.erb")) { |f| f.read }) show_template = ERB.new(File.open(File.join(@theme_path, "show.html.erb")) { |f| f.read }) # Create index page File.open(File.join(@output_path, "index.html"), "w") { |f| f.write(index_template.result(binding)) } # Create show pages @images.each do |image| previous_image = (image.id != 0 ? @images[image.id - 1] : nil) next_image = (@images.size - 1 != image.id ? @images[image.id + 1] : nil) File.open(File.join(@output_path, "show", "#{image.id}.html"), "w") { |f| f.write(show_template.result(binding)) } end end |