Sha256: 551adb37a0787ebe5acab05f6cd51fc232fee85a9248a8bc75a64b0683af5377

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

module Podlove
  module Web
    module Player
      module Rails
        module ViewHelpers
          def podloveaudio(options = {})
            podlove("audio", options)
          end

          def podlovevideo(options = {})
            podlove("video", options)
          end

          private

          def podlove(type, options = {})
            html = "<#{type} id='player'>"
            html << "<source src='#{options[:src]}'"\
                    "" + (options[:type] ? " type='#{options[:type]}'" : "") + "></source>"      if options[:src]
            html << "<source src='#{options[:mp4]}' type='#{type}/mp4'></source>"                if options[:mp4]
            html << "<source src='#{options[:mp3]}' type='#{type}/mpeg'></source>"               if options[:mp3]
            html << "<source src='#{options[:ogg]}' type='#{type}/ogg; codecs=vorbis'></source>" if options[:ogg]
            html << "<source src='#{options[:opus]}' type='#{type}/ogg; codecs=opus'></source>"  if options[:opus]
            html << "<source src='#{options[:opus]}' type='#{type}/webm'></source>"              if options[:webm]
            html << "</#{type}>"

            [:src, :type, :mp4, :mp3, :ogg, :opus, :webm].each{ |key| options.delete(key) }

            script = "$('#player').podlovewebplayer(#{options.to_json});"

            return raw html + "\n" + javascript_tag(script)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
podlove-web-player-rails-0.2.0 lib/podlove-web-player-rails/view_helpers.rb