Module: LightboxRails::LightboxHelper

Defined in:
lib/lightbox-rails/lightbox_helper.rb

Instance Method Summary collapse

Instance Method Details

Takes the photo gallery at dir, with the name name, and creates a Lightbox 2 group from them. Within dir there may be a directory named thumbs containing the respective thumbnails for each image.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lightbox-rails/lightbox_helper.rb', line 6

def lightbox_group(name, dir)
  images = Dir[File.join(dir, "*.{jpg,JPG,png,PNG,gif,GIF}")].
           sort { |a, b| image_name(a).to_i <=> image_name(b).to_i }

  singles = images.each_with_index.map do |f, i|
    filename = File.join("/", "assets", f.split(File::SEPARATOR)[-3..-1])
    thumbname = File.exists?(thumbs_path f) \
                ? thumbs_path(filename)
                : filename

    title = "#{i + 1} of #{images.size}"
    cls = "single#{{0 => " first", images.size - 1 => " last"}[i] || ""}"

    (:div, :class => cls) do
      (:a,
                  rel: "lightbox[#{name.downcase.gsub(" ", "-")}]",
                  href: filename) do
        image_tag thumbname, alt: title, size: "100x100"
      end
    end
  end

  lightbox_set singles
end