Skip to content
Browse files

improve gallery model to be more flexible and update readme

  • Loading branch information...
1 parent 62167b4 commit c092a7417bafd9f0917cbfc5ad798c431dcae2ae @kristianmandrup committed Dec 6, 2012
Showing with 22 additions and 14 deletions.
  1. +8 −2 README.md
  2. +1 −1 VERSION
  3. +8 −8 lib/rails-gallery/rgallery/page.rb
  4. +5 −3 lib/rails-gallery/rgallery/photo.rb
View
10 README.md
@@ -183,6 +183,11 @@ Here is a rough example:
```ruby
class Property
class Photo < RGallery::Photo
+ def initialize property, options = {}
+ super
+ end
+ alias_method :property, :obj
+
def path
File.join folder, super
end
@@ -289,8 +294,9 @@ class PropertiesController < ApplicationController
def photos
@photos ||= RGallery::Photos.new nil, photo_class: Property::Photo
- 5.times do
- @photos.pages << 6.times.map {|n| (Kernel.rand(7) + 1).to_s }
+ 5.times do |n|
+ # using a paginator to get a page of properties
+ @photos.pages << Property.page(n)
end
@photos
end
View
2 VERSION
@@ -1 +1 @@
-0.3.0
+0.3.1
View
16 lib/rails-gallery/rgallery/page.rb
@@ -2,8 +2,8 @@ module RGallery
class Page < PhotoConfig
include Enumerable
- def initialize photo_ids = [], options = {}
- @photo_ids = photo_ids
+ def initialize photo_objs = [], options = {}
+ @photo_objs = photo_objs
super options
end
@@ -18,9 +18,9 @@ def self.from_source sources
end
end
- def << photo_ids
- @photo_ids ||= []
- @photo_ids += [photo_ids].flatten
+ def << photo_objs
+ @photo_objs ||= []
+ @photo_objs += [photo_objs].flatten
end
def add_photo_sources sources_hash
@@ -40,12 +40,12 @@ def add_photo_w_sources source
@photos << photo_class.new(key, options.merge(:sources => srclist))
end
- def photo_ids
- @photo_ids ||= []
+ def photo_objs
+ @photo_objs ||= []
end
def photos
- @photos ||= photo_ids.map {|id| photo_class.new id, options }
+ @photos ||= photo_objs.map {|obj| photo_class.new obj, options }
end
delegate :empty?, to: :photos
View
8 lib/rails-gallery/rgallery/photo.rb
@@ -1,14 +1,16 @@
module RGallery
class Photo
- attr_reader :id, :sizing, :sources, :options
+ attr_reader :obj, :sizing, :sources, :options
- def initialize id, options = {}
- @id = id
+ def initialize obj, options = {}
+ @obj = obj
self.sources = options.delete :sources
@sizing = options.delete :sizing
@options = options
end
+ alias_method :id, :obj
+
# map [{src: 'banner-HD.jpeg', sizing: '2x'}, {src: 'banner-phone.jpeg', sizing: '100w'}]
# into -> "banner-HD.jpeg 2x, banner-phone.jpeg 100w
def srcset

0 comments on commit c092a74

Please sign in to comment.
Something went wrong with that request. Please try again.