Permalink
Browse files

lot of nice updates - tested ok in real app

  • Loading branch information...
1 parent 3164e42 commit dddd46f9d20846bf3d30597140b30c0b27204311 @kristianmandrup committed Aug 22, 2012
View
@@ -192,17 +192,45 @@ See the `lib/rails-gallery/rgallery/photos.rb
Then in your `properties/show.html.haml`:
+*Responsive Gallery*
+
+```haml
+= render partial: 'gallery/template/responsive'
+= render partial: 'gallery/responsive', locals: { photos: @property.photos }
+```
+
+Note :Currently only the *responsive* gallery uses a template, and thus requires rendering an extra partial.
+
+*Slideshow Gallery*
+
+```haml
+= render partial: 'gallery/slideshow', locals: { photos: @property.photos }
+```
+
+*Galleria*
+
```haml
-render partial: 'gallery/responsive', locals: { photos: @property.photos }
+= render partial: 'gallery/galleria', locals: { photos: @property.photos }
```
-And so on...
+All galleries should follow this convention (or as close as possible)
+
+## Labels
+
+Note that all gallery labels are rendered using Rails I18n `I18n.t`.
+You should include appropriate translations for the following keys under 'rgallery':
+
+* previous
+* next
+* photos_loading
+
+The engine includes a `config/locales/rails_gallery.yml` file, currently only with english translation mappings. Include a `config/locales/rails_gallery.yml` file in your Rails app and override or supply you additional translation mappings ;)
## View helpers
There are also some view helpers included in `rails-gallery/view_helper.rb`
-`gallery_image type, photo`
+`= gallery_image type, photo`
Simple example:
@@ -239,6 +267,16 @@ Iterate photos, first page visible, then remaining pages invisible.
Enjoy!
+## Adding more galleries
+
+Simply follow the existing conventions (see the code).
+
+*ViewHelpers*
+
+ Add the gallery name to the `#galleries` class method of the `ViewHelper` and create a module for that gallery with a `[name]_gallery_image(photo)` method.
+
+Then add gallery client-side pieces to the assets folder following conventions and make sure that your css files (and possible js files) references the icons used (and any other asset) correctly using `/assets/` in the path ;)
+
## TODO
Would perhaps be nice to allow pages/albums to have info assigned, such as title and/or description, tags etc. ?
View
@@ -1 +1 @@
-0.1.0
+0.2.0
@@ -4,27 +4,12 @@
.es-carousel-wrapper
.es-nav
%span.es-nav-prev
- Previous
+ = t('rgallery.previous')
%span.es-nav-next
- Next
+ = t('rgallery.next')
.es-carousel
%ul
- photos.all.each do |photo|
%li
%a{href:"#"}
- = image_tag photo.thumb, :"data-large" => "/assets/#{photo.path}", :alt => photo.alt, :"data-description" => photo.title
-
-%script#img-wrapper-tmpl{style: "display:none;"}
- .rg-image-wrapper
- = "{{if itemsCount > 1}}"
- .rg-image-nav
- %a.rg-image-nav-prev{href: "#"}
- Previous
- %a.rg-image-nav-next{href: "#"}
- Next
- = "{{/if}}"
- .rg-image
- .rg-loading
- .rg-caption-wrapper
- .rg-caption{style: "display:none;"}
- %p
+ = image_tag photo.thumb, :"data-large" => "/assets/#{photo.path}", :alt => photo.alt, :"data-description" => photo.title
@@ -23,4 +23,4 @@
%a#msg_thumb_prev.msg_thumb_prev{href: '#'}
%a#msg_thumb_close.msg_thumb_close{href: '#'}
%span.msg_loading
- Loading images...
+ = t('rgallery.photos_loading')
@@ -0,0 +1,14 @@
+%script#img-wrapper-tmpl{style: "display:none;"}
+ .rg-image-wrapper
+ {{if itemsCount > 1}}
+ .rg-image-nav
+ %a.rg-image-nav-prev{href: "#"}
+ = t('rgallery.previous')
+ %a.rg-image-nav-next{href: "#"}
+ = t('rgallery.next')
+ {{/if}}
+ .rg-image
+ .rg-loading
+ .rg-caption-wrapper
+ .rg-caption{style: "display:none;"}
+ %p
@@ -0,0 +1,5 @@
+en:
+ rgallery:
+ previous: Previous
+ next: Next
+ photos_loading: Loading photos...
View
@@ -1 +1,3 @@
-require 'rails-gallery/rgallery'
+require 'rails-gallery/rgallery'
+require 'rails-gallery/view_helper'
+require 'rails-gallery/engine' if defined?(::Rails::Engine)
@@ -1,23 +1,27 @@
module RailsGallery
module ViewHelper
- def gallery_image type, photo
- send("#{type}_gallery_image", photo)
+ def self.galleries
+ %w{galleria responsive slideshow}
end
- protected
-
- def responsive_gallery_image photo
- image_tag photo.thumb, :"data-large" => "/assets/#{photo.path}", :alt => photo.alt, :"data-description" => photo.title
+ # autoload all galleries when references
+ galleries.each do |gallery|
+ autoload gallery.camelize.to_sym, "rails-gallery/view_helper/#{gallery}"
end
- def slideshow_gallery_image photo
- image_tag photo.thumb, alt: "/assets/#{photo.path}"
+ def gallery_image type, photo
+ meth_name = "#{type}_gallery_image"
+ unless respond_to? meth_name
+ 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..."
+ end
+ send(meth_name, photo)
end
- def glleria_gallery_image photo
- content_tag :a, href: "/assets/#{photo.path}" do
- image_tag photo.path, :"data-title" => photo.title, :"data-description" => photo.description
- end
+ protected
+
+ # include view helper modules for all galleries :)
+ galleries.each do |gallery|
+ include "RailsGallery::ViewHelper::#{gallery.camelize}".constantize
end
end
end
@@ -0,0 +1,11 @@
+module RailsGallery
+ module ViewHelper
+ module Galleria
+ def galleria_gallery_image photo
+ content_tag :a, href: "/assets/#{photo.path}" do
+ image_tag photo.path, :"data-title" => photo.title, :"data-description" => photo.description
+ end
+ end
+ end
+ end
+end
@@ -1,7 +1,9 @@
module RailsGallery
module ViewHelper
module Responsive
- # TODO
+ def responsive_gallery_image photo
+ image_tag photo.thumb, :"data-large" => "/assets/#{photo.path}", :alt => photo.alt, :"data-description" => photo.title
+ end
end
end
end
@@ -1,7 +1,9 @@
module RailsGallery
module ViewHelper
module Slideshow
- # TODO
+ def slideshow_gallery_image photo
+ image_tag photo.thumb, alt: "/assets/#{photo.path}"
+ end
end
end
end
View
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = "rails-gallery"
- s.version = "0.1.0"
+ s.version = "0.1.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Kristian Mandrup"]

0 comments on commit dddd46f

Please sign in to comment.