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.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/ecm/pictures_helper.rb', line 28

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}]"

  # Add thumbnail class for twitter bootstrap
  link_options[:class] = 'thumbnail'

  # build the caption
  caption = ''
  caption << "<div class=\"caption-name\">#{picture.name}</div>" unless picture.name.blank?
  caption << "<div class=\"caption-description\">#{picture.description}</div>" unless picture.description.blank?
  link_options[:"data-ob_caption"] = caption if caption.size > 0

  link_options
end

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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/helpers/ecm/pictures_helper.rb', line 46

def render_picture(name, options = {})
  options.reverse_merge!(
    preview_style: :thumb,
    plain: false,
    img_css_class: nil
  )

  img_css_class = options.delete(:img_css_class)
  plain         = options.delete(:plain)

  picture = Ecm::Pictures::Picture.where(name: name.to_s).first

  if picture.nil?
    return (:div, class: 'warning missing picture') do
      (:p, I18n.t('ecm.pictures.picture.warnings.missing', name: name.to_s))
    end
  end

  if plain
    image_tag picture.image.url, class: img_css_class
  else
    render picture
  end

rescue Exception => e
  return e.message
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
# File 'app/helpers/ecm/pictures_helper.rb', line 10

def render_picture_gallery(name, options = {})
  options = { preview_style: :thumb }.merge(options)

  gallery = Ecm::Pictures::Gallery.where(name: name.to_s).first

  if gallery.nil?
    (:div, class: 'warning missing gallery') do
      (:p, I18n.t('ecm.pictures.gallery.warnings.missing', name: name.to_s))
    end
  else
    render gallery, { view: self }
  end

rescue Exception => e
  return e.message
end