class Jekyll::GalleryIndex

Public Class Methods

new(site, base, dir, galleries) click to toggle source
# File lib/jekyll-gallery-generator.rb, line 89
def initialize(site, base, dir, galleries)
  @site = site
  @base = base
  @dir = dir.gsub("source/", "")
  @name = "index.html"
  config = site.config["gallery"] || {}

  self.process(@name)
  gallery_index = File.join(base, "_layouts", "gallery_index.html")
  unless File.exists?(gallery_index)
    gallery_index = File.join(File.dirname(__FILE__), "gallery_index.html")
  end
  self.read_yaml(File.dirname(gallery_index), File.basename(gallery_index))
  self.data["title"] = config["title"] || "Photos"
  self.data["galleries"] = []
  begin
    sort_field = config["sort_field"] || "date_time"
    galleries.sort! {|a,b|
      cmp = b.data[sort_field] <=> a.data[sort_field]
      # Tie goes to first alphabetically. The different order (a<=>b) is intentional.
      cmp == 0 ? a.data["name"] <=> b.data["name"] : cmp
    }
  rescue Exception => e
    puts "Error sorting galleries: #{e}"
    puts e.backtrace
  end
  if config["sort_reverse"]
    galleries.reverse!
  end
  galleries.each {|gallery|
    unless gallery.hidden
      self.data["galleries"].push(gallery.data)
    end
  }
end