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
@@ -1,12 +1,41 @@
|
|
1
1
|
module RGallery
|
2
2
|
class Photo
|
3
|
-
attr_reader :id, :options
|
3
|
+
attr_reader :id, :sizing, :sources, :options
|
4
4
|
|
5
5
|
def initialize id, options = {}
|
6
6
|
@id = id
|
7
|
+
self.sources = options.delete :sources
|
8
|
+
@sizing = options.delete :sizing
|
7
9
|
@options = options
|
8
10
|
end
|
9
11
|
|
12
|
+
# map [{src: 'banner-HD.jpeg', sizing: '2x'}, {src: 'banner-phone.jpeg', sizing: '100w'}]
|
13
|
+
# into -> "banner-HD.jpeg 2x, banner-phone.jpeg 100w
|
14
|
+
def srcset
|
15
|
+
return '' unless sources_photos.kind_of? Array
|
16
|
+
@srcset ||= source_photos.inject([]) do |res, photo|
|
17
|
+
res << [photo.id, photo.sizing].join(' ')
|
18
|
+
end.join(',')
|
19
|
+
end
|
20
|
+
|
21
|
+
def srcset?
|
22
|
+
!srcset.blank?
|
23
|
+
end
|
24
|
+
|
25
|
+
# A photo can contain a source set of other photos!
|
26
|
+
def source_photos
|
27
|
+
return [] unless sources.kind_of? Array
|
28
|
+
@source_photos ||= sources.map do |source|
|
29
|
+
RGallery::Photo.new source.src, options.merge(:sizing => source.sizing)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# make sure that sources are wrapped as Hashies to allow method access
|
34
|
+
def sources= sources = []
|
35
|
+
return unless sources.kind_of? Array
|
36
|
+
@sources = sources.map{|source| Hashie::Mash.new source }
|
37
|
+
end
|
38
|
+
|
10
39
|
def filename
|
11
40
|
id
|
12
41
|
end
|
@@ -1,7 +1,16 @@
|
|
1
1
|
module RailsGallery
|
2
|
+
class ConfigurationError < StandardError
|
3
|
+
end
|
4
|
+
|
2
5
|
module ViewHelper
|
6
|
+
include RailsGallery::PhotoValidation
|
7
|
+
|
3
8
|
def self.galleries
|
4
|
-
%w{galleria responsive slideshow}
|
9
|
+
%w{galleria responsive slideshow touch_touch}
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.version
|
13
|
+
'0.2.2'
|
5
14
|
end
|
6
15
|
|
7
16
|
# autoload all galleries when references
|
@@ -11,12 +20,22 @@ module RailsGallery
|
|
11
20
|
|
12
21
|
def gallery_image type, photo
|
13
22
|
meth_name = "#{type}_gallery_image"
|
23
|
+
validate_gallery_photo! photo
|
14
24
|
unless respond_to? meth_name
|
15
25
|
raise ArgumentError, "Gallery #{type} is not yet supported. Please add a View helper module for this gallery using the convention followed by the other galleries..."
|
16
26
|
end
|
17
27
|
send(meth_name, photo)
|
18
28
|
end
|
19
29
|
|
30
|
+
def gallery_imageset type, imageset
|
31
|
+
meth_name = "#{type}_gallery_imageset"
|
32
|
+
# validate_gallery_imageset! imageset
|
33
|
+
unless respond_to? meth_name
|
34
|
+
raise ArgumentError, "Gallery #{type} is not yet supported for imageset. Please add a View helper module for this gallery using the convention followed by the other galleries..."
|
35
|
+
end
|
36
|
+
send(meth_name, imageset)
|
37
|
+
end
|
38
|
+
|
20
39
|
protected
|
21
40
|
|
22
41
|
# include view helper modules for all galleries :)
|
@@ -1,11 +1,22 @@
|
|
1
1
|
module RailsGallery
|
2
2
|
module ViewHelper
|
3
3
|
module Galleria
|
4
|
-
def
|
5
|
-
content_tag :a, href:
|
6
|
-
|
4
|
+
def riagal_image photo, options = {}
|
5
|
+
content_tag :a, href: photo.path do
|
6
|
+
options.merge! :"data-title" => photo.title, :"data-description" => photo.description
|
7
|
+
image_tag photo.path, options
|
7
8
|
end
|
8
9
|
end
|
10
|
+
|
11
|
+
def riagal_imageset photo, options = {}
|
12
|
+
content_tag :a, href: photo.path do
|
13
|
+
options.merge! :"data-title" => photo.title, :"data-description" => photo.description
|
14
|
+
options.merge! :srcset => photo.srcset if photo.srcset?
|
15
|
+
image_tag photo.path, options
|
16
|
+
end
|
17
|
+
end
|
18
|
+
alias_method :galleria_gallery_image, :riagal_image
|
19
|
+
alias_method :galleria_gallery_imageset, :riagal_imageset
|
9
20
|
end
|
10
21
|
end
|
11
22
|
end
|
@@ -1,9 +1,32 @@
|
|
1
1
|
module RailsGallery
|
2
2
|
module ViewHelper
|
3
3
|
module Responsive
|
4
|
-
def
|
5
|
-
|
4
|
+
def respgal_image photo, options = {}
|
5
|
+
options.merge! :alt => photo.alt
|
6
|
+
options.merge! :"data-large" => photo.path, :"data-description" => photo.title
|
7
|
+
return image_tag photo.thumb, options unless options.delete :wrap
|
8
|
+
|
9
|
+
content_tag :li do
|
10
|
+
content_tag :a, href: '#' do
|
11
|
+
image_tag(photo.thumb, options)
|
12
|
+
end
|
13
|
+
end
|
6
14
|
end
|
15
|
+
|
16
|
+
def respgal_imageset photo, options = {}
|
17
|
+
options.merge! :alt => photo.alt
|
18
|
+
options.merge! :"data-large" => photo.path, :"data-description" => photo.title
|
19
|
+
options.merge! :srcset => srcset if photo.srcset?
|
20
|
+
return imageset_tag photo.thumb, options unless options.delete :wrap
|
21
|
+
|
22
|
+
content_tag :li do
|
23
|
+
content_tag :a, href: '#' do
|
24
|
+
imageset_tag(photo.thumb, options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
alias_method :responsive_gallery_image, :respgal_image
|
29
|
+
alias_method :responsive_gallery_imageset, :respgal_imageset
|
7
30
|
end
|
8
31
|
end
|
9
32
|
end
|
@@ -1,9 +1,19 @@
|
|
1
1
|
module RailsGallery
|
2
2
|
module ViewHelper
|
3
3
|
module Slideshow
|
4
|
-
def
|
5
|
-
|
4
|
+
def slidegal_image photo, options = {}
|
5
|
+
options.merge! alt: photo.path
|
6
|
+
image_tag photo.thumb, options
|
6
7
|
end
|
8
|
+
|
9
|
+
def slidegal_imageset photo, options = {}
|
10
|
+
options.merge! alt: photo.path
|
11
|
+
options.merge! :srcset => photo.srcset if photo.srcset?
|
12
|
+
imageset_tag photo.thumb, options
|
13
|
+
end
|
14
|
+
|
15
|
+
alias_method :slideshow_gallery_image, :slidegal_image
|
16
|
+
alias_method :slideshow_gallery_imageset, :slidegal_imageset
|
7
17
|
end
|
8
18
|
end
|
9
19
|
end
|
data/rails-gallery.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "rails-gallery"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-12-06"
|
13
13
|
s.description = "Adds popular javascript galleries to asset pipeline and includes a few Rails Gallery utils and helpers"
|
14
14
|
s.email = "kmandrup@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"config/locales/rails_gallery.yml",
|
33
33
|
"lib/rails-gallery.rb",
|
34
34
|
"lib/rails-gallery/engine.rb",
|
35
|
+
"lib/rails-gallery/photo_validation.rb",
|
35
36
|
"lib/rails-gallery/rgallery.rb",
|
36
37
|
"lib/rails-gallery/rgallery/page.rb",
|
37
38
|
"lib/rails-gallery/rgallery/pages.rb",
|
@@ -42,6 +43,7 @@ Gem::Specification.new do |s|
|
|
42
43
|
"lib/rails-gallery/view_helper/galleria.rb",
|
43
44
|
"lib/rails-gallery/view_helper/responsive.rb",
|
44
45
|
"lib/rails-gallery/view_helper/slideshow.rb",
|
46
|
+
"lib/rails-gallery/view_helper/touch_touch.rb",
|
45
47
|
"rails-gallery.gemspec",
|
46
48
|
"spec/galleria_snippet.html",
|
47
49
|
"spec/galleria_snippet.html.haml",
|
@@ -151,7 +153,9 @@ Gem::Specification.new do |s|
|
|
151
153
|
"spec/images/responsive-gallery/images/thumbs/7.jpg",
|
152
154
|
"spec/images/responsive-gallery/images/thumbs/8.jpg",
|
153
155
|
"spec/images/responsive-gallery/images/thumbs/9.jpg",
|
154
|
-
"spec/rails-
|
156
|
+
"spec/rails-gallery/view_helper_spec.rb",
|
157
|
+
"spec/rgallery/photos_spec.rb",
|
158
|
+
"spec/rgallery/property_photo.rb",
|
155
159
|
"spec/spec_helper.rb",
|
156
160
|
"vendor/assets/images/gallery/galleria/classic/loader.gif",
|
157
161
|
"vendor/assets/images/gallery/galleria/classic/map.png",
|
@@ -174,6 +178,7 @@ Gem::Specification.new do |s|
|
|
174
178
|
"vendor/assets/images/gallery/touch_touch/preloader.gif",
|
175
179
|
"vendor/assets/javascripts/gallery/galleria-1.2.8.js",
|
176
180
|
"vendor/assets/javascripts/gallery/galleria-1.2.8.min.js",
|
181
|
+
"vendor/assets/javascripts/gallery/galleria.js",
|
177
182
|
"vendor/assets/javascripts/gallery/galleria/classic.js",
|
178
183
|
"vendor/assets/javascripts/gallery/galleria/classic.min.js",
|
179
184
|
"vendor/assets/javascripts/gallery/responsive.js",
|
@@ -186,7 +191,7 @@ Gem::Specification.new do |s|
|
|
186
191
|
"vendor/assets/stylesheets/gallery/responsive.css",
|
187
192
|
"vendor/assets/stylesheets/gallery/responsive/elastislide.css",
|
188
193
|
"vendor/assets/stylesheets/gallery/slideshow.css",
|
189
|
-
"vendor/assets/stylesheets/touch_touch.css"
|
194
|
+
"vendor/assets/stylesheets/gallery/touch_touch.css"
|
190
195
|
]
|
191
196
|
s.homepage = "http://github.com/kristianmandrup/rails-gallery"
|
192
197
|
s.licenses = ["MIT"]
|
@@ -198,12 +203,16 @@ Gem::Specification.new do |s|
|
|
198
203
|
s.specification_version = 3
|
199
204
|
|
200
205
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
206
|
+
s.add_runtime_dependency(%q<rails>, [">= 0"])
|
207
|
+
s.add_runtime_dependency(%q<hashie>, ["~> 1.2.0"])
|
201
208
|
s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
|
202
209
|
s.add_development_dependency(%q<rdoc>, [">= 3.12"])
|
203
210
|
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
204
211
|
s.add_development_dependency(%q<jeweler>, [">= 1.8.4"])
|
205
212
|
s.add_development_dependency(%q<simplecov>, [">= 0.5"])
|
206
213
|
else
|
214
|
+
s.add_dependency(%q<rails>, [">= 0"])
|
215
|
+
s.add_dependency(%q<hashie>, ["~> 1.2.0"])
|
207
216
|
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
208
217
|
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
209
218
|
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
@@ -211,6 +220,8 @@ Gem::Specification.new do |s|
|
|
211
220
|
s.add_dependency(%q<simplecov>, [">= 0.5"])
|
212
221
|
end
|
213
222
|
else
|
223
|
+
s.add_dependency(%q<rails>, [">= 0"])
|
224
|
+
s.add_dependency(%q<hashie>, ["~> 1.2.0"])
|
214
225
|
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
215
226
|
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
216
227
|
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class NoPathPhoto < RGallery::Photo
|
4
|
+
def path
|
5
|
+
nil
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class BadFilenamePhoto < RGallery::Photo
|
10
|
+
def title
|
11
|
+
'my title'
|
12
|
+
end
|
13
|
+
|
14
|
+
# blip method unknown!
|
15
|
+
def filename
|
16
|
+
blip
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class NoTitlePhoto < RGallery::Photo
|
21
|
+
def path
|
22
|
+
'abc'
|
23
|
+
end
|
24
|
+
|
25
|
+
def title
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class ValidPhoto < RGallery::Photo
|
31
|
+
def path
|
32
|
+
'abc'
|
33
|
+
end
|
34
|
+
|
35
|
+
def title
|
36
|
+
'sdgds'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe RailsGallery::ConfigurationError do
|
41
|
+
specify { RailsGallery::ConfigurationError.new.should be_a StandardError }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe RailsGallery::ViewHelper do
|
45
|
+
include ControllerTestHelpers,
|
46
|
+
RailsGallery::ViewHelper
|
47
|
+
|
48
|
+
let(:no_path_photo) { NoPathPhoto.new 1 }
|
49
|
+
let(:no_title_photo) { NoTitlePhoto.new 2 }
|
50
|
+
let(:bad_filename_photo) { BadFilenamePhoto.new 2 }
|
51
|
+
let(:valid_photo) { ValidPhoto.new 2 }
|
52
|
+
|
53
|
+
describe 'validate_gallery_photo! photo' do
|
54
|
+
it 'should raise error on nil' do
|
55
|
+
expect { validate_gallery_photo!(nil) }.to raise_error(ArgumentError)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should raise error on no #path method' do
|
59
|
+
expect { validate_gallery_photo!(no_path_photo) }.to raise_error(ArgumentError)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should raise error on no #title method' do
|
63
|
+
expect { validate_gallery_photo!(no_title_photo) }.to raise_error(ArgumentError)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should raise error on bad filename method' do
|
67
|
+
expect { validate_gallery_photo!(bad_filename_photo) }.to raise_error(::RailsGallery::ConfigurationError)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'validate_gallery_photo photo' do
|
72
|
+
it 'should return nil error msg' do
|
73
|
+
validate_gallery_photo(nil).should == "Photo must be a kind of RGallery::Photo, was: "
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should return no path error msg' do
|
77
|
+
validate_gallery_photo(no_path_photo).should match /Photo must have a path:/
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should return no title error msg' do
|
81
|
+
validate_gallery_photo(no_title_photo).should match /Photo must have a title:/
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should return bad filename method error' do
|
85
|
+
validate_gallery_photo(bad_filename_photo).should match /filename or file_path could not be resolved for:/
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'gallery_image photo' do
|
90
|
+
it 'should raise error on nil' do
|
91
|
+
expect { gallery_image(nil) }.to raise_error(ArgumentError)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should return error if valid type but nil photo' do
|
95
|
+
expect { gallery_image(:galleria, nil) }.to raise_error(ArgumentError)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should return error if invalid type and valid photo' do
|
99
|
+
expect { gallery_image(:invalid, valid_photo) }.to raise_error(ArgumentError)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should no raise error for galleria image" do
|
103
|
+
expect { gallery_image(:galleria, valid_photo) }.to_not raise_error
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should render the image for galleria image" do
|
107
|
+
gallery_image(:galleria, valid_photo).should == "<a href=\"abc\"><img data-description=\"no description\" data-title=\"sdgds\" src=\"abc\"></img></a>"
|
108
|
+
end
|
109
|
+
|
110
|
+
%w{slideshow responsive}.each do |gallery_type|
|
111
|
+
it "should not raise error for type: #{gallery_type}" do
|
112
|
+
expect { gallery_image(gallery_type, valid_photo) }.to_not raise_error
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should render the image for galleria image" do
|
116
|
+
gallery_image(gallery_type, valid_photo).should match /img.*alt=.*src="\w+"/
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rgallery/property_photo'
|
3
|
+
|
4
|
+
describe RGallery::Photos do
|
5
|
+
context 'New empty RGallery::Photos collection' do
|
6
|
+
subject { RGallery::Photos.new }
|
7
|
+
|
8
|
+
its(:pages) { should be_empty }
|
9
|
+
its(:pages) { should be_a RGallery::Pages }
|
10
|
+
|
11
|
+
describe '.page :first' do
|
12
|
+
specify { subject.page(:first).should be_empty }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.page :remainder' do
|
16
|
+
specify { subject.pages.remainder.should be_empty }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'Photos with one page' do
|
21
|
+
subject { RGallery::Photos.new ['0'] }
|
22
|
+
|
23
|
+
its(:pages) { should_not be_empty }
|
24
|
+
its(:pages) { should be_a RGallery::Pages }
|
25
|
+
|
26
|
+
describe '.page' do
|
27
|
+
describe ':first' do
|
28
|
+
specify { subject.page(:first).should_not be_empty }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ':remainder' do
|
32
|
+
specify { subject.pages.remainder.should be_empty }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '.all' do
|
37
|
+
specify { subject.all.first.should be_a RGallery::Photo }
|
38
|
+
|
39
|
+
specify { subject.all.first.id.should == '0' }
|
40
|
+
|
41
|
+
specify { subject.all.first.path.should == '0.png' }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'configure with custom Photo class' do
|
46
|
+
subject { RGallery::Photos.new ['0'], photo_class: Property::Photo }
|
47
|
+
|
48
|
+
specify { subject.all.first.should be_a Property::Photo }
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Property
|
2
|
+
class Photo < RGallery::Photo
|
3
|
+
def path
|
4
|
+
File.join folder, super
|
5
|
+
end
|
6
|
+
|
7
|
+
# mogrify -path fullpathto/temp2 -resize 60x60% -quality 60 -format jpg *.png
|
8
|
+
|
9
|
+
# this will take all png files in your current directory (temp),
|
10
|
+
# resize to 60% (of largest dimension and keep aspect ratio),
|
11
|
+
# set jpg quality to 60 and convert to jpg.
|
12
|
+
def thumb
|
13
|
+
File.join folder, 'thumbs', file_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def folder
|
17
|
+
'responsive-gallery/images'
|
18
|
+
end
|
19
|
+
|
20
|
+
def title
|
21
|
+
'property title'
|
22
|
+
end
|
23
|
+
|
24
|
+
def alt
|
25
|
+
'property alt'
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.extension
|
29
|
+
:jpg
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|