Class: Jekyll::GalleryPage

Inherits:
Page
  • Object
show all
Defined in:
lib/jekyll-photo-gallery.rb

Instance Method Summary collapse

Constructor Details

#initialize(site, base, dir, name, parent = nil) ⇒ GalleryPage

Returns a new instance of GalleryPage.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/jekyll-photo-gallery.rb', line 126

def initialize(site, base, dir, name, parent=nil)
  @site = site
  @base = base
  @dir  = dir
  @name = 'index.html'

  self.process(@name)
  # Read template
  @path = File.realpath(File.join(File.dirname(__FILE__), "jekyll-photo-gallery.html"))
  self.read_yaml(File.dirname(@path), File.basename(@path))

  # Only display root page
  if parent.nil?
    name = "Photos"
    self.data["title"] = name
  end
  self.data["title_deferred"] = name
  self.data["parent"] = parent
  self.data["photos"] = discover
  self.data["children"] = []

  Jekyll::Hooks.trigger :pages, :post_init, self
end

Instance Method Details

#discoverObject



115
116
117
118
119
120
121
122
123
124
# File 'lib/jekyll-photo-gallery.rb', line 115

def discover 
  photos = []
  image_extensions = [".png", ".jpg", ".jpeg", ".gif"]
  Dir.foreach(@dir) do |item|
    # Skip files with wrong extension
    next unless item.downcase().end_with?(*image_extensions)
    photos << GalleryPhoto.new(@site, @base, @dir, item)
  end
  photos
end