class Jekyll::GalleryGenerator

Public Instance Methods

generate(site) click to toggle source
# File lib/jekyll-photo-gallery.rb, line 183
def generate(site)
  # Get configuration option.
  config = site.config["photo_gallery"] || {}
  path = config["path"] || "photos"
  original_dir = Dir.getwd
  # Change into the photo gallery directory.
  Dir.chdir(site.source)
  begin
    puts "Generating galleries ..."
    gallery = GalleryPage.new(site, site.source, path, path)
    site.pages << gallery
    iterate(site, path, gallery)
  rescue Exception => e
    puts "Error generating galleries: #{e}"
    puts e.backtrace
  end
  # Change back.
  Dir.chdir(original_dir)
end
is_empty(path) click to toggle source
# File lib/jekyll-photo-gallery.rb, line 154
def is_empty(path)
  Dir["#{path}/*"].empty?
end
iterate(site, basepath, parent) click to toggle source
# File lib/jekyll-photo-gallery.rb, line 158
def iterate(site, basepath, parent)
  galleries = []
  Dir.foreach(basepath) do |item|
    # Skip . and ..
    next if item == '.' or item == '..'
    # Complete path
    path = File.join(basepath, item)
    # Skip if not a directory
    next if !File.directory?(path)
    # Skip if directory is empty
    next if is_empty(path)
    # Create gallery
    puts "Generating gallery \"#{path}\" ..."
    gallery = GalleryPage.new(site, site.source, path, item, parent)
    site.pages << gallery
    galleries << gallery
    # Descend into the directory
    iterate(site, path, gallery)
  end
  if !parent.nil?
    parent.data["children"] = galleries
  end
  galleries
end