class Jekyll::Photoset
Attributes
cache_dir[RW]
cache_file[RW]
date_update[RW]
date_update_str[RW]
description[RW]
id[RW]
photos[RW]
photos_from_cache[RW]
photos_from_flickr[RW]
primary[RW]
slug[RW]
title[RW]
Public Class Methods
new(site, photoset)
click to toggle source
# File lib/badpixxel-jekyll-flickr/photoset.rb, line 20 def initialize(site, photoset) self.photos = Array.new self.photos_from_cache = 0 self.photos_from_flickr = 0 if photoset.is_a? String self.cache_load(site, photoset) else self.flickr_load(site, photoset) end self.photos.sort! {|left, right| left.position <=> right.position} end
Public Instance Methods
cache_load(site, file)
click to toggle source
Load Photoset
from Cache
# File lib/badpixxel-jekyll-flickr/photoset.rb, line 83 def cache_load(site, file) cached = YAML::load(File.read(file)) self.id = cached['id'] self.title = cached['title'] self.description = cached['description'] self.primary = cached['primary'] self.date_update = cached['date_update'] self.date_update_str = cached['date_update_str'] self.slug = cached['slug'] self.cache_dir = cached['cache_dir'] self.cache_file = cached['cache_file'] file_photos = Dir.glob(File.join(self.cache_dir, '*.yml')) file_photos.each_with_index do |file_photo, pos| self.photos << Photo.new(site, self, file_photo, pos) end end
cache_outdated(flickr_photoset)
click to toggle source
Check if Photoset
Cachge is Outdated
# File lib/badpixxel-jekyll-flickr/photoset.rb, line 68 def cache_outdated(flickr_photoset) # Check if Photoset is Already in Cache if !File.exists?(self.cache_file) return true end # Load Cached Values cached = YAML::load(File.read(cache_file)) if !cached["date_update"] or (cached["date_update"] != flickr_photoset.date_update) return true end return false end
cache_store()
click to toggle source
Store Photoset
in Cache
# File lib/badpixxel-jekyll-flickr/photoset.rb, line 102 def cache_store cached = Hash.new cached['id'] = self.id cached['title'] = self.title cached['description'] = self.description cached['primary'] = self.primary cached['date_update'] = self.date_update cached['date_update_str'] = self.date_update_str cached['slug'] = self.slug cached['cache_dir'] = self.cache_dir cached['cache_file'] = self.cache_file File.open(self.cache_file, 'w') {|f| f.print(YAML::dump(cached))} end
flickr_load(site, flickr_photoset)
click to toggle source
Load Photoset
from Flckr (if needed)
# File lib/badpixxel-jekyll-flickr/photoset.rb, line 33 def flickr_load(site, flickr_photoset) self.id = flickr_photoset.id self.title = flickr_photoset.title self.description = flickr_photoset.description self.primary = flickr_photoset.primary self.date_update = flickr_photoset.date_update self.date_update_str = DateTime.strptime(flickr_photoset.date_update, '%s').to_s self.slug = self.title.downcase.gsub(/ /, '-').gsub(/[^a-z\-]/, '') self.cache_dir = File.join(site.config['flickr']['cache_dir'], self.slug) self.cache_file = File.join(site.config['flickr']['cache_dir'], "#{self.slug}.yml") # write to cache if self.cache_outdated(flickr_photoset) self.cache_store end # create cache directory if !Dir.exists?(self.cache_dir) Dir.mkdir(self.cache_dir) end # photos flickr_photos = flickr.photosets.getPhotos(:photoset_id => self.id, :extras => "date_taken, last_update").photo flickr_photos.each_with_index do |flickr_photo, pos| photo = Photo.new(site, self, flickr_photo, pos) self.photos << photo if photo.from_cache self.photos_from_cache += 1 else self.photos_from_flickr += 1 end end end
gen_html()
click to toggle source
# File lib/badpixxel-jekyll-flickr/photoset.rb, line 213 def gen_html content = '' self.photos.each do |photo| content += photo.gen_thumb_html end return content end
gen_html_fancy()
click to toggle source
# File lib/badpixxel-jekyll-flickr/photoset.rb, line 221 def gen_html_fancy content = '' self.photos.each do |photo| content += photo.gen_thumb_html_fancy end return content end
get_photo(photo_id)
click to toggle source
get_photos_array(max = false)
click to toggle source
Get List of All Photoset
Photos
# File lib/badpixxel-jekyll-flickr/photoset.rb, line 176 def get_photos_array(max = false) # Build List of Photos [ "tag" => count ] if max != false photos = self.photos.first(max) else photos = self.photos end collection = [] photos.each do |photo| collection += photo.to_liquid end return collection end
get_primary_photo()
click to toggle source
to_liquid()
click to toggle source
Convert PhotoSet to liquid Format
# File lib/badpixxel-jekyll-flickr/photoset.rb, line 118 def to_liquid return [ 'id' => self.id, 'title' => self.title, 'description' => self.description, 'primary' => self.primary, 'slug' => self.slug, 'date_update' => self.date_update, ] end