Module: Embeddable::ViewHelpers

Defined in:
lib/embeddable/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#embed_video(embeddable, width, height, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/embeddable/view_helpers.rb', line 2

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

#render_embeddable_partial(embeddable, name, source, width, height) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/embeddable/view_helpers.rb', line 11

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.send("#{name}_on_vimeo?")
    render 'embeddable/partials/vimeo', attributes
  elsif embeddable.send("#{name}_on_dailymotion?")
    render 'embeddable/partials/dailymotion', attributes
  elsif embeddable.send("#{name}_on_veoh?")
    render 'embeddable/partials/veoh', attributes
  elsif embeddable.send("#{name}_on_vippy?")
    render 'embeddable/partials/vippy', attributes
  elsif embeddable.send("#{name}_on_liveleak?")
    # not supported
    link_to embeddable.send(source), embeddable.send(source)
  elsif embeddable.send("#{name}_on_brightcove?")
    render 'embeddable/partials/brightcove', attributes
  else
    link_to embeddable.send(source), embeddable.send(source)
  end
end