class Jekyll::GalleryPhoto
Public Class Methods
new(site, base, basepath, name)
click to toggle source
# File lib/jekyll-photo-gallery.rb, line 13 def initialize(site, base, basepath, name) @site = site @base = base @name = name @basepath = basepath @path = File.join(basepath, name) # Create symlink in site destination. create_symlink # Read exif data. @exif = read_exif # Fetch date time field from exif data. @date_time = nil if !@exif.nil? @date_time = @exif[:date_time] end # Create thumbnail. @thumbnail = create_thumbnail end
Public Instance Methods
create_symlink()
click to toggle source
# File lib/jekyll-photo-gallery.rb, line 32 def create_symlink link_src = @site.in_source_dir(@path) link_dest = @site.in_dest_dir(@path) link_dest_basepath = @site.in_dest_dir(@basepath) # Delete existing static asset. @site.static_files.delete_if { |sf| sf.relative_path == "/#{@path}" } # Add new entry which prevents writing. @site.static_files << GalleryFile.new(@site, @base, @basepath, @name) # Create symlink in file system. if File.exists?(link_dest) # Correct link already exists. if File.readlink(link_dest) == link_src return end File.delete(link_dest) end puts "Creating symlink for #{@path}" # Create symlink FileUtils.mkdir_p(link_dest_basepath, :mode => 0755) File.symlink(link_src, link_dest) end
create_thumbnail()
click to toggle source
# File lib/jekyll-photo-gallery.rb, line 56 def create_thumbnail config = @site.config["photo_gallery"] || {} thumbnail_size = config["thumbnail_size"] || 256 # Compile thumbnail path thumb_dir = File.join(@site.dest, @basepath, "thumbs") thumb = File.join(thumb_dir, @name) thumb_name = File.join("thumbs", @name) # Add thumbnail to static assets @site.static_files << GalleryFile.new(@site, @base, thumb_dir, @name) # Create if it does not exist. FileUtils.mkdir_p(thumb_dir, :mode => 0755) if File.exists?(thumb) return thumb_name end begin puts "Creating thumbnail for #{@path}" # Read image. img = Magick::Image.read(@path).first # Resize Flickr style img = img.resize_to_fill(thumbnail_size, thumbnail_size) # Write thumbnail img.write(thumb) rescue Exception => e puts "Error generating thumbnail for #{@path}: #{e}" puts e.backtrace thumb_name = nil end thumb_name end
read_exif()
click to toggle source
# File lib/jekyll-photo-gallery.rb, line 86 def read_exif exif = nil begin exif = EXIFR::JPEG.new(@path).to_hash rescue EXIFR::MalformedJPEG puts "No EXIF data in #{@path}" rescue Exception => e puts "Error reading EXIF data for #{@path}: #{e}" end exif end
to_liquid()
click to toggle source
# File lib/jekyll-photo-gallery.rb, line 98 def to_liquid { 'name' => @name, 'date_time' => @date_time, 'thumbnail' => @thumbnail, 'exif' => @exif.nil? ? nil : @exif.collect{|k,v| [k.to_s, v]}.to_h } end
to_s()
click to toggle source
# File lib/jekyll-photo-gallery.rb, line 107 def to_s @path end