class RGallery::Photo
Attributes
extension[W]
id[R]
obj[R]
options[R]
sizing[R]
sources[R]
Public Class Methods
extension()
click to toggle source
# File lib/rails-gallery/rgallery/photo.rb, line 76 def extension @extension ||= :png end
new(obj, options = {})
click to toggle source
# File lib/rails-gallery/rgallery/photo.rb, line 5 def initialize obj, options = {} @obj = obj self.sources = options.delete :sources @sizing = options.delete :sizing @options = options end
Public Instance Methods
alt()
click to toggle source
# File lib/rails-gallery/rgallery/photo.rb, line 61 def alt 'no alt' end
description()
click to toggle source
# File lib/rails-gallery/rgallery/photo.rb, line 65 def description 'no description' end
extension()
click to toggle source
# File lib/rails-gallery/rgallery/photo.rb, line 69 def extension options[:extension] || self.class.extension end
file_path()
click to toggle source
# File lib/rails-gallery/rgallery/photo.rb, line 45 def file_path "#{filename}.#{extension}" end
filename()
click to toggle source
# File lib/rails-gallery/rgallery/photo.rb, line 41 def filename id end
path()
click to toggle source
# File lib/rails-gallery/rgallery/photo.rb, line 49 def path file_path end
source_photos()
click to toggle source
A photo can contain a source set of other photos!
# File lib/rails-gallery/rgallery/photo.rb, line 28 def source_photos return [] unless sources.kind_of? Array @source_photos ||= sources.map do |source| RGallery::Photo.new source.src, options.merge(:sizing => source.sizing) end end
sources=(sources = [])
click to toggle source
make sure that sources are wrapped as Hashies to allow method access
# File lib/rails-gallery/rgallery/photo.rb, line 36 def sources= sources = [] return unless sources.kind_of? Array @sources = sources.map{|source| Hashie::Mash.new source } end
srcset()
click to toggle source
map [{src: ‘banner-HD.jpeg’, sizing: ‘2x’}, {src: ‘banner-phone.jpeg’, sizing: ‘100w’}] into -> “banner-HD.jpeg 2x, banner-phone.jpeg 100w
# File lib/rails-gallery/rgallery/photo.rb, line 16 def srcset return '' unless sources_photos.kind_of? Array @srcset ||= source_photos.inject([]) do |res, photo| res << [photo.id, photo.sizing].join(' ') end.join(',') end
srcset?()
click to toggle source
# File lib/rails-gallery/rgallery/photo.rb, line 23 def srcset? !srcset.blank? end
thumb()
click to toggle source
# File lib/rails-gallery/rgallery/photo.rb, line 53 def thumb path end
title()
click to toggle source
# File lib/rails-gallery/rgallery/photo.rb, line 57 def title 'no title' end