Class: Jekyll::GalleryIndex

Inherits:
ReadYamlPage show all
Defined in:
lib/jekyll-gallery-generator.rb

Instance Method Summary collapse

Methods inherited from ReadYamlPage

#read_yaml

Constructor Details

#initialize(site, base, dir, galleries) ⇒ GalleryIndex

Returns a new instance of GalleryIndex.



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/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