Guest User

Untitled

a guest
May 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. module Cms::ContentBucketHelper
  2.  
  3. def display_content(content_item, *args)
  4. case content_item.content_type.to_sym
  5. when :image
  6. display_content_image(content_item, *args)
  7. when :video
  8. content_tag(:p, "Video has not been implemented.")
  9. when :audio
  10. content_tag(:p, "Audio has not been implemented.")
  11. else
  12. raise "Don't know how to display content type '#{content_item.content_type}'!"
  13. end
  14. end
  15.  
  16. def display_content_image(content_item)
  17. src = content_image_url(content_item)
  18. "<img id='content_item_img_#{((content_item.is_a? Integer)? content_item: content_item.id)}' src='#{src}' alt='Error displaying content'/>"
  19. end
  20.  
  21. def content_thumbnail_url(content_item, width = nil, height = nil, only_path = true)
  22. content_image_url(content_item, width, height, "thumbnail", only_path)
  23. end
  24.  
  25. def content_image_url(content_item, width = nil, height = nil, action = "image", only_path = true)
  26. if content_item.nil?
  27. elsif content_item.is_a?(Integer)
  28. content_item_id = content_item
  29. else
  30. content_item_id = content_item.id
  31. end
  32.  
  33. parameters = {:controller => "cms/content_bucket",
  34. :action => action,
  35. :app_code => params[:app_code],
  36. :id => content_item_id,
  37. :only_path => true}
  38. parameters[:width] = width if !width.nil?
  39. parameters[:height] = height if !height.nil?
  40. url_for(parameters)
  41. end
  42.  
  43. end
Add Comment
Please, Sign In to add comment