Module: Ecm::PicturesHelper

Defined in:
app/helpers/ecm/pictures_helper.rb

Instance Method Summary collapse

Instance Method Details

helper method to build link options for images inside a gallery.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/helpers/ecm/pictures_helper.rb', line 49

def build_link_options_for_picture_in_gallery(gallery_identifier, picture)
  link_options = {}
  
  # Add gallery identifier for orange box
  link_options = { :rel => "lightbox[#{gallery_identifier}]" }
  
  # build the caption
  caption = ""
  caption << "<span class=\"caption-name\">#{picture.name}</span>" unless picture.name.blank?
  caption << "<span class=\"caption-description\">#{picture.description}</span>" unless picture.description.blank?   
  link_options[:"data-ob_caption"] = caption if caption.size > 0
  
  return link_options
end

#render_picture(name, options = {}) ⇒ Object

TODO: Implement this.



65
66
# File 'app/helpers/ecm/pictures_helper.rb', line 65

def render_picture(name, options = {})
end

renders picture galleries in your views

Usage

Assume you have created a picture gallery named “Holidays 2012”. You can render it in your view as follows:

<%= render_picture_gallery 'Holidays 2012' %>


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/ecm/pictures_helper.rb', line 10

def render_picture_gallery(name, options = {})
  begin  
    options = {:preview_style => :thumb}.merge(options)
    
    gallery = Ecm::Pictures::PictureGallery.where(:name => name.to_s).first
    gallery_identifier = gallery.to_param rescue 'missing'

    (:div, :class => 'picture-gallery', :id => "picture-gallery-#{gallery_identifier}") do
      if gallery.nil?
        (:span, :class => 'warning') do
          I18n.t('ecm.pictures.warnings.missing_gallery', :name => name.to_s)
        end      
      else
        (:h1, gallery.name) +
        (:p, gallery.description, {:class => 'picture-gallery-description'}) +
        (:ul, {:class => 'pictures'}) do
          gallery.pictures.collect do |picture|
           (:li, {:class => 'picture', :id => "picture-#{picture.to_param}"}) do
              concat((:h2, picture.name, :class => 'picture-name')) unless picture.name.blank?
              
              # Check if we should link images or not.
              if gallery.link_images
                link_options = build_link_options_for_picture_in_gallery(gallery_identifier, picture)
                concat(link_to(image_tag(picture.image.url(options[:preview_style]), :alt => picture.description), "#{picture.image.url}#{File.extname(picture.image_file_name)}", link_options))
              else 
                concat(image_tag(picture.image.url(options[:preview_style]), :alt => picture.description))
              end
              concat((:div, picture.description, :class => 'picture-description'))
            end
          end.join.html_safe
        end.html_safe
      end
    end.html_safe
  rescue Exception => e
    return e.message
  end  
end