rails-gallery 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +74 -0
- data/README.md +84 -14
- data/VERSION +1 -1
- data/app/views/gallery/_galleria.html.haml +2 -3
- data/app/views/gallery/_responsive.html.haml +2 -3
- data/app/views/gallery/_slideshow.html.haml +2 -2
- data/lib/rails-gallery.rb +1 -0
- data/lib/rails-gallery/engine.rb +2 -0
- data/lib/rails-gallery/photo_validation.rb +37 -0
- data/lib/rails-gallery/rgallery/page.rb +33 -0
- data/lib/rails-gallery/rgallery/pages.rb +15 -0
- data/lib/rails-gallery/rgallery/photo.rb +30 -1
- data/lib/rails-gallery/rgallery/photo_config.rb +1 -1
- data/lib/rails-gallery/view_helper.rb +20 -1
- data/lib/rails-gallery/view_helper/galleria.rb +14 -3
- data/lib/rails-gallery/view_helper/responsive.rb +25 -2
- data/lib/rails-gallery/view_helper/slideshow.rb +12 -2
- data/lib/rails-gallery/view_helper/touch_touch.rb +10 -0
- data/rails-gallery.gemspec +15 -4
- data/spec/rails-gallery/view_helper_spec.rb +120 -0
- data/spec/rgallery/photos_spec.rb +50 -0
- data/spec/rgallery/property_photo.rb +32 -0
- data/spec/spec_helper.rb +40 -4
- data/vendor/assets/javascripts/gallery/galleria.js +5926 -0
- data/vendor/assets/javascripts/gallery/responsive.js +5 -1
- data/vendor/assets/stylesheets/{touch_touch.css → gallery/touch_touch.css} +0 -0
- metadata +42 -5
- data/spec/rails-gallery_spec.rb +0 -7
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,15 +1,77 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
actionmailer (3.2.8)
|
5
|
+
actionpack (= 3.2.8)
|
6
|
+
mail (~> 2.4.4)
|
7
|
+
actionpack (3.2.8)
|
8
|
+
activemodel (= 3.2.8)
|
9
|
+
activesupport (= 3.2.8)
|
10
|
+
builder (~> 3.0.0)
|
11
|
+
erubis (~> 2.7.0)
|
12
|
+
journey (~> 1.0.4)
|
13
|
+
rack (~> 1.4.0)
|
14
|
+
rack-cache (~> 1.2)
|
15
|
+
rack-test (~> 0.6.1)
|
16
|
+
sprockets (~> 2.1.3)
|
17
|
+
activemodel (3.2.8)
|
18
|
+
activesupport (= 3.2.8)
|
19
|
+
builder (~> 3.0.0)
|
20
|
+
activerecord (3.2.8)
|
21
|
+
activemodel (= 3.2.8)
|
22
|
+
activesupport (= 3.2.8)
|
23
|
+
arel (~> 3.0.2)
|
24
|
+
tzinfo (~> 0.3.29)
|
25
|
+
activeresource (3.2.8)
|
26
|
+
activemodel (= 3.2.8)
|
27
|
+
activesupport (= 3.2.8)
|
28
|
+
activesupport (3.2.8)
|
29
|
+
i18n (~> 0.6)
|
30
|
+
multi_json (~> 1.0)
|
31
|
+
arel (3.0.2)
|
32
|
+
builder (3.0.0)
|
4
33
|
diff-lcs (1.1.3)
|
34
|
+
erubis (2.7.0)
|
5
35
|
git (1.2.5)
|
36
|
+
hashie (1.2.0)
|
37
|
+
hike (1.2.1)
|
38
|
+
i18n (0.6.0)
|
6
39
|
jeweler (1.8.4)
|
7
40
|
bundler (~> 1.0)
|
8
41
|
git (>= 1.2.5)
|
9
42
|
rake
|
10
43
|
rdoc
|
44
|
+
journey (1.0.4)
|
11
45
|
json (1.7.5)
|
46
|
+
mail (2.4.4)
|
47
|
+
i18n (>= 0.4.0)
|
48
|
+
mime-types (~> 1.16)
|
49
|
+
treetop (~> 1.4.8)
|
50
|
+
mime-types (1.19)
|
12
51
|
multi_json (1.3.6)
|
52
|
+
polyglot (0.3.3)
|
53
|
+
rack (1.4.1)
|
54
|
+
rack-cache (1.2)
|
55
|
+
rack (>= 0.4)
|
56
|
+
rack-ssl (1.3.2)
|
57
|
+
rack
|
58
|
+
rack-test (0.6.1)
|
59
|
+
rack (>= 1.0)
|
60
|
+
rails (3.2.8)
|
61
|
+
actionmailer (= 3.2.8)
|
62
|
+
actionpack (= 3.2.8)
|
63
|
+
activerecord (= 3.2.8)
|
64
|
+
activeresource (= 3.2.8)
|
65
|
+
activesupport (= 3.2.8)
|
66
|
+
bundler (~> 1.0)
|
67
|
+
railties (= 3.2.8)
|
68
|
+
railties (3.2.8)
|
69
|
+
actionpack (= 3.2.8)
|
70
|
+
activesupport (= 3.2.8)
|
71
|
+
rack-ssl (~> 1.3.2)
|
72
|
+
rake (>= 0.8.7)
|
73
|
+
rdoc (~> 3.4)
|
74
|
+
thor (>= 0.14.6, < 2.0)
|
13
75
|
rake (0.9.2.2)
|
14
76
|
rdoc (3.12)
|
15
77
|
json (~> 1.4)
|
@@ -25,13 +87,25 @@ GEM
|
|
25
87
|
multi_json (~> 1.0)
|
26
88
|
simplecov-html (~> 0.5.3)
|
27
89
|
simplecov-html (0.5.3)
|
90
|
+
sprockets (2.1.3)
|
91
|
+
hike (~> 1.2)
|
92
|
+
rack (~> 1.0)
|
93
|
+
tilt (~> 1.1, != 1.3.0)
|
94
|
+
thor (0.16.0)
|
95
|
+
tilt (1.3.3)
|
96
|
+
treetop (1.4.10)
|
97
|
+
polyglot
|
98
|
+
polyglot (>= 0.3.1)
|
99
|
+
tzinfo (0.3.33)
|
28
100
|
|
29
101
|
PLATFORMS
|
30
102
|
ruby
|
31
103
|
|
32
104
|
DEPENDENCIES
|
33
105
|
bundler (>= 1.0.0)
|
106
|
+
hashie (~> 1.2.0)
|
34
107
|
jeweler (>= 1.8.4)
|
108
|
+
rails
|
35
109
|
rdoc (>= 3.12)
|
36
110
|
rspec (>= 2.8.0)
|
37
111
|
simplecov (>= 0.5)
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Popular Javascript Photo galleries/carousels ready to use with Rails 3+.
|
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
-
`gem 'rails-gallery'
|
7
|
+
`gem 'rails-gallery'`
|
8
8
|
|
9
9
|
## Galleries included
|
10
10
|
|
@@ -21,12 +21,11 @@ In `application.css` manifest file:
|
|
21
21
|
|
22
22
|
```css
|
23
23
|
/*
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
* require gallery/touch_touch
|
24
|
+
*= require gallery/responsive/elastislide
|
25
|
+
*= require gallery/responsive
|
26
|
+
*= require gallery/slideshow
|
27
|
+
*= require gallery/galleria/classic
|
28
|
+
*= require gallery/touch_touch
|
30
29
|
*/
|
31
30
|
```
|
32
31
|
|
@@ -36,7 +35,7 @@ Using Compass, f.ex in `application.css.scss`
|
|
36
35
|
@import 'gallery/responsive/elastislide';
|
37
36
|
@import 'gallery/responsive';
|
38
37
|
@import 'gallery/slideshow';
|
39
|
-
@import 'gallery/galleria';
|
38
|
+
@import 'gallery/galleria/classic';
|
40
39
|
@import 'gallery/touch_touch';
|
41
40
|
```
|
42
41
|
|
@@ -46,6 +45,7 @@ In `application.js` manifest file:
|
|
46
45
|
//= require gallery/responsive
|
47
46
|
//= require gallery/slideshow
|
48
47
|
//= require gallery/galleria
|
48
|
+
//= require gallery/galleria/classic
|
49
49
|
//= require gallery/touch_touch
|
50
50
|
|
51
51
|
//= require jquery/jquery.easing-1.3
|
@@ -66,6 +66,10 @@ $(function(){
|
|
66
66
|
|
67
67
|
See [TouchTouch](http://tutorialzine.com/2012/04/mobile-touch-gallery/) and [github repo](https://github.com/martinaglv/touchTouch)
|
68
68
|
|
69
|
+
```haml
|
70
|
+
= touchgal_image photo
|
71
|
+
```
|
72
|
+
|
69
73
|
## Minimalistic Slideshow gallery
|
70
74
|
|
71
75
|
See [minimalistic-slideshow-gallery](http://tympanus.net/codrops/2010/07/05/minimalistic-slideshow-gallery/) for more info.
|
@@ -188,12 +192,29 @@ class PropertiesController < ApplicationController
|
|
188
192
|
end
|
189
193
|
```
|
190
194
|
|
195
|
+
The RGallery should now also support multiple photo sources for responsive galleries:
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
@photos.pages.add_photo_w_sources 'banner' => [{src: 'banner-HD', sizing: '2x'}, {src: 'banner-phone', sizing: '100w'}]
|
199
|
+
|
200
|
+
Note: See module `RGallery::Pages` class.
|
201
|
+
|
202
|
+
# OR
|
203
|
+
|
204
|
+
@photos.pages.add_photo_sources 'banner' => [{src: 'banner-HD', sizing: '2x'}], 'logo' => [{src: 'logo-HD', sizing: '2x'}
|
205
|
+
|
206
|
+
OR on individual pages
|
207
|
+
|
208
|
+
@photos.page(:first).add_photo_sources 'banner' => [{src: 'banner-HD', sizing: '2x'}], 'logo' => [{src: 'logo-HD', sizing: '2x'}
|
209
|
+
|
210
|
+
```
|
211
|
+
|
191
212
|
This engine comes with a RGallery::Photos` model which can encapsulate your photos for display and allows you to group photos in multiple pages.
|
192
213
|
The `RGallery::Photo` class is a base class for describing a photo.
|
193
214
|
|
194
215
|
You should create your own Photo class that inherits from `RGallery::Photo` (or implements the API), which knows how to render and describe your photos.
|
195
216
|
|
196
|
-
Here a rough example:
|
217
|
+
Here is a rough example:
|
197
218
|
|
198
219
|
```ruby
|
199
220
|
class Property
|
@@ -215,6 +236,13 @@ class Property
|
|
215
236
|
'responsive-gallery/images'
|
216
237
|
end
|
217
238
|
|
239
|
+
# The filename of the picture.
|
240
|
+
# Here it assumes that the id assigned is a Property object, which has a
|
241
|
+
# method 'picture' which returns the picture id.
|
242
|
+
def filename
|
243
|
+
"property-#{id.picture}"
|
244
|
+
end
|
245
|
+
|
218
246
|
def title
|
219
247
|
'property title'
|
220
248
|
end
|
@@ -230,7 +258,18 @@ class Property
|
|
230
258
|
end
|
231
259
|
```
|
232
260
|
|
233
|
-
See the `lib/rails-gallery/rgallery/photos.rb
|
261
|
+
See the `lib/rails-gallery/rgallery/photos.rb` for details on how to extend this class appropriately to fit your scenario.
|
262
|
+
|
263
|
+
*debugging*
|
264
|
+
|
265
|
+
In order to help debug the configuration of the photo class, you can use the view_helper methods:
|
266
|
+
|
267
|
+
```ruby
|
268
|
+
= validate_gallery_photo photo # prints error msg if invalid
|
269
|
+
- validate_gallery_photo! photo # raise error if invalid
|
270
|
+
```
|
271
|
+
|
272
|
+
Or you can include the `RailsGallery::PhotoValidation` module anywhere you want to leverage these methods!
|
234
273
|
|
235
274
|
Then in your `properties/show.html.haml`:
|
236
275
|
|
@@ -274,7 +313,7 @@ There are also some view helpers included in `rails-gallery/view_helper.rb`
|
|
274
313
|
|
275
314
|
`= gallery_image type, photo`
|
276
315
|
|
277
|
-
Simple example
|
316
|
+
*Simple example:*
|
278
317
|
|
279
318
|
Iterate all photos as a "single page".
|
280
319
|
|
@@ -283,7 +322,7 @@ Iterate all photos as a "single page".
|
|
283
322
|
= gallery_image :responsive, photo`
|
284
323
|
```
|
285
324
|
|
286
|
-
Pages example
|
325
|
+
*Pages example:*
|
287
326
|
|
288
327
|
Iterate photos, one page at a time.
|
289
328
|
|
@@ -292,7 +331,7 @@ Iterate photos, one page at a time.
|
|
292
331
|
= gallery_image :responsive, photo`
|
293
332
|
```
|
294
333
|
|
295
|
-
Advanced example
|
334
|
+
*Advanced example:*
|
296
335
|
|
297
336
|
Iterate photos, first page visible, then remaining pages invisible.
|
298
337
|
|
@@ -307,6 +346,37 @@ Iterate photos, first page visible, then remaining pages invisible.
|
|
307
346
|
= gallery_image :responsive, photo`
|
308
347
|
```
|
309
348
|
|
349
|
+
### Shortcuts for view helpers
|
350
|
+
|
351
|
+
```haml
|
352
|
+
# galleria
|
353
|
+
= riagal_image photo
|
354
|
+
= riagal_imageset photo
|
355
|
+
|
356
|
+
# slideshow
|
357
|
+
= slidegal_image photo
|
358
|
+
= slidegal_imageset photo
|
359
|
+
|
360
|
+
# responsive
|
361
|
+
= respgal_image photo
|
362
|
+
= respgal_imageset photo
|
363
|
+
|
364
|
+
# touchtouch
|
365
|
+
= touchgal_image photo
|
366
|
+
= touchgal_imageset photo
|
367
|
+
```
|
368
|
+
|
369
|
+
## Responsive images via "image srcset"
|
370
|
+
|
371
|
+
The View Helpers also includes tag helpers to create image tags with [srcset](https://github.com/borismus/srcset-polyfill). This can be installed and used with [picturefill-rails](https://github.com/kristianmandrup/picturefill-rails)
|
372
|
+
|
373
|
+
Example:
|
374
|
+
|
375
|
+
```haml
|
376
|
+
- photos.pages.each do |photo|
|
377
|
+
= gallery_imageset :responsive, photo`
|
378
|
+
```
|
379
|
+
|
310
380
|
Enjoy!
|
311
381
|
|
312
382
|
## Adding more galleries
|
@@ -321,7 +391,7 @@ Then add gallery client-side pieces to the assets folder following conventions a
|
|
321
391
|
|
322
392
|
## TODO
|
323
393
|
|
324
|
-
Would
|
394
|
+
Would be nice to allow pages/albums to have info assigned, such as title and/or description, tags etc.
|
325
395
|
|
326
396
|
## Contributing to rails-gallery
|
327
397
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -13,12 +13,12 @@
|
|
13
13
|
.msg_thumb_wrapper
|
14
14
|
- photos.page(:first).photos.each do |photo|
|
15
15
|
%a{href: "#"}
|
16
|
-
=
|
16
|
+
= gallery_image :slideshow photo
|
17
17
|
- photos.pages.remainder.each do |page|
|
18
18
|
.msg_thumb_wrapper{style: 'display:none'}
|
19
19
|
- page.photos.each do |photo|
|
20
20
|
%a{href: "#"}
|
21
|
-
=
|
21
|
+
= gallery_image :slideshow, photo
|
22
22
|
%a#msg_thumb_next.msg_thumb_next{href: '#'}
|
23
23
|
%a#msg_thumb_prev.msg_thumb_prev{href: '#'}
|
24
24
|
%a#msg_thumb_close.msg_thumb_close{href: '#'}
|
data/lib/rails-gallery.rb
CHANGED
data/lib/rails-gallery/engine.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
module RailsGallery
|
2
|
+
module PhotoValidation
|
3
|
+
def validate_gallery_photo photo
|
4
|
+
return "Photo must be a kind of RGallery::Photo, was: #{photo}" unless photo.kind_of?(RGallery::Photo)
|
5
|
+
return 'Photo must have a #path method' unless photo.respond_to? :path
|
6
|
+
return 'Photo must have a #title method' unless photo.respond_to? :title
|
7
|
+
|
8
|
+
begin
|
9
|
+
photo.filename
|
10
|
+
photo.file_path
|
11
|
+
rescue Exception => e
|
12
|
+
return "filename or file_path could not be resolved for: #{photo}, cause: #{e}"
|
13
|
+
end
|
14
|
+
|
15
|
+
return "Photo must have a path: #{photo}" if photo.path.blank?
|
16
|
+
return "Photo must have a title: #{photo}" if photo.title.blank?
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_gallery_photo! photo
|
21
|
+
raise ArgumentError, "Photo must be a kind of RGallery::Photo, was: #{photo}" unless photo.kind_of?(RGallery::Photo)
|
22
|
+
raise ArgumentError, 'Photo must have a #path method' unless photo.respond_to? :path
|
23
|
+
raise ArgumentError, 'Photo must have a #title method' unless photo.respond_to? :title
|
24
|
+
|
25
|
+
begin
|
26
|
+
photo.filename
|
27
|
+
photo.file_path
|
28
|
+
rescue Exception => e
|
29
|
+
raise ::RailsGallery::ConfigurationError, "filename or file_path could not be resolved for: #{photo}, cause: #{e}"
|
30
|
+
end
|
31
|
+
|
32
|
+
raise ArgumentError, "Photo must have a path: #{photo}" if photo.path.blank?
|
33
|
+
raise ArgumentError, "Photo must have a title: #{photo}" if photo.title.blank?
|
34
|
+
true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -7,6 +7,39 @@ module RGallery
|
|
7
7
|
super options
|
8
8
|
end
|
9
9
|
|
10
|
+
# a source is a hash of the form:
|
11
|
+
# 'banner' => [{src: 'banner-HD', sizing: '2x'}, {src: 'banner-phone', sizing: '100w'}]
|
12
|
+
# see: add_photo_sources
|
13
|
+
def self.from_source sources
|
14
|
+
page = self.create sources.keys, options
|
15
|
+
|
16
|
+
@photos ||= sources.map do |key, srclist|
|
17
|
+
photo_class.new key, options.merge(:sources => srclist)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def << photo_ids
|
22
|
+
@photo_ids ||= []
|
23
|
+
@photo_ids += [photo_ids].flatten
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_photo_sources sources_hash
|
27
|
+
sources_hash.each do |source|
|
28
|
+
add_photo_w_sources source
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_photo_w_sources source
|
33
|
+
raise ArgumentError, "Must be a hash, was: #{source}" unless source.kind_of? Hash
|
34
|
+
key = source.keys.first
|
35
|
+
srclist = source.values.first
|
36
|
+
raise ArgumentError, "Hash value must be an Array, was: #{srclist}" unless srclist.kind_of? Array
|
37
|
+
|
38
|
+
self.send :<<, key
|
39
|
+
@photos ||= []
|
40
|
+
@photos << photo_class.new(key, options.merge(:sources => srclist))
|
41
|
+
end
|
42
|
+
|
10
43
|
def photo_ids
|
11
44
|
@photo_ids ||= []
|
12
45
|
end
|
@@ -23,6 +23,21 @@ module RGallery
|
|
23
23
|
pages << RGallery::Page.new(photo_list, options)
|
24
24
|
end
|
25
25
|
|
26
|
+
# a source is a hash of the form:
|
27
|
+
# 'banner' => [{src: 'banner-HD', sizing: '2x'}, {src: 'banner-phone', sizing: '100w'}]
|
28
|
+
def add_photo_w_sources source
|
29
|
+
pages << RGallery::Page.from_source(source, options)
|
30
|
+
end
|
31
|
+
|
32
|
+
# a Hash where each element is a source of the form:
|
33
|
+
# 'banner' => [{src: 'banner-HD', sizing: '2x'}, {src: 'banner-phone', sizing: '100w'}]
|
34
|
+
def add_photo_sources sources_hash
|
35
|
+
sources_hash.each do |source|
|
36
|
+
pages.add_photo_w_sources source
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
26
41
|
delegate :empty?, to: :pages
|
27
42
|
|
28
43
|
protected
|