diff options
author | Lars Henrik Mai <lars.mai@kontinui.de> | 2014-04-06 20:58:02 +0200 |
---|---|---|
committer | Lars Henrik Mai <lars.mai@kontinui.de> | 2014-04-06 20:58:02 +0200 |
commit | 4852a7c95b13901bc8e88f7785dde4bab8de20c7 (patch) | |
tree | a021b5b66cf6d1055053688ffeb28d268417988d /helpers | |
parent | fd54b48b54acde2098067d66da380d39d58a3a36 (diff) |
added helper for images with thumbnails and captions
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/extra_image_helpers.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/helpers/extra_image_helpers.rb b/helpers/extra_image_helpers.rb new file mode 100644 index 0000000..9c92d3c --- /dev/null +++ b/helpers/extra_image_helpers.rb @@ -0,0 +1,27 @@ +module ExtraImageHelpers + + # creates a div with image link, thumbnail and caption + # TODO make this work for non-image assets (pdf on 'verein' page) + def image_with_thumb(name, options={}) + caption = options.delete(:caption) + full_path = "/img/#{name}" + + thumb_name = options.delete(:thumbnail) || default_thumbnail_for(name) + thumb_path = "/img/#{thumb_name}" + + # oh boy, padrino-helpers has problems with nested content_for... FIXME + thumb_tag = image_tag(thumb_path, options) + image_link = content_tag(:a, thumb_tag, href: full_path) + caption_tag = content_tag(:p, caption) + + content_tag :div, [image_link, caption_tag].join("\n") + end + + private + + def default_thumbnail_for(image_name_with_ext) + name, ext = image_name_with_ext.split(".") + "#{name}_klein.#{ext}" + end + +end |