lib/embeddable/view_helpers.rb in embeddable-0.0.7 vs lib/embeddable/view_helpers.rb in embeddable-0.0.8

- old
+ new

@@ -1,24 +1,32 @@ -module ViewHelpers - def embed_video(embeddable, width, height) - attributes = { id: embeddable.video_id, width: width, height: height } +module Embeddable::ViewHelpers + def embed_video(embeddable, width, height, options = {}) + if options[:name] && !embeddable.respond_to?("#{options[:name]}_id") + raise "Can't find embeddable name. Did you mean: \"#{embeddable.class.embeddables.last.inspect}\"?" + end + name = options[:name] || embeddable.class.embeddables.first + source = embeddable.send("#{name}_source") + render_embeddable_partial(embeddable, name, source, width, height) + end - if embeddable.video_on_youtube? + def render_embeddable_partial(embeddable, name, source, width, height) + attributes = { id: embeddable.send("#{name}_id"), width: width, height: height } + if embeddable.send("#{name}_on_youtube?") render 'embeddable/partials/youtube', attributes - elsif embeddable.video_on_vimeo? + elsif embeddable.send("#{name}_on_vimeo?") render 'embeddable/partials/vimeo', attributes - elsif embeddable.video_on_dailymotion? + elsif embeddable.send("#{name}_on_dailymotion?") render 'embeddable/partials/dailymotion', attributes - elsif embeddable.video_on_veoh? + elsif embeddable.send("#{name}_on_veoh?") render 'embeddable/partials/veoh', attributes - elsif embeddable.video_on_vippy? + elsif embeddable.send("#{name}_on_vippy?") render 'embeddable/partials/vippy', attributes - elsif embeddable.video_on_liveleak? + elsif embeddable.send("#{name}_on_liveleak?") # not supported - link_to embeddable.url, embeddable.url - elsif embeddable.video_on_brightcove? + link_to embeddable.send(source), embeddable.send(source) + elsif embeddable.send("#{name}_on_brightcove?") render 'embeddable/partials/brightcove', attributes else - link_to embeddable.url, embeddable.url + link_to embeddable.send(source), embeddable.send(source) end end end