Module: Pageflow::AudioFilesHelper

Defined in:
app/helpers/pageflow/audio_files_helper.rb

Instance Method Summary collapse

Instance Method Details

#audio_file_audio_tag(audio_file_id, options = {}) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/pageflow/audio_files_helper.rb', line 3

def audio_file_audio_tag(audio_file_id, options = {})
  options.merge!(class: ['audio-js', options.delete(:class)].compact * ' ',
                 controls: true,
                 preload: 'none')
  url_options = {unique_id: options.delete(:unique_id)}

  if (audio_file = AudioFile.find_by_id(audio_file_id))
    (:audio, options) do
      audio_file_sources(audio_file, url_options).each do |source|
        concat(tag(:source, source.slice(:src, :type)))
      end
    end
  end
end

26
27
28
29
30
# File 'app/helpers/pageflow/audio_files_helper.rb', line 26

def audio_file_non_js_link(audio_file_id)
  if (audio_file = AudioFile.find_by_id(audio_file_id))
    link_to(t('pageflow.audio.open'), short_audio_file_path(audio_file.entry, audio_file))
  end
end

#audio_file_script_tag(audio_file_id, options = {}) ⇒ Object


18
19
20
21
22
23
24
# File 'app/helpers/pageflow/audio_files_helper.rb', line 18

def audio_file_script_tag(audio_file_id, options = {})
  if (audio_file = AudioFile.find_by_id(audio_file_id))
    render('pageflow/audio_files/script_tag',
           audio_file: audio_file,
           audio_file_sources: audio_file_sources(audio_file, options))
  end
end

#audio_file_sources(audio_file, options = {}) ⇒ Object


32
33
34
35
36
37
38
# File 'app/helpers/pageflow/audio_files_helper.rb', line 32

def audio_file_sources(audio_file, options = {})
  [
    {type: 'audio/ogg', src: audio_file.ogg.url(options)},
    {type: 'audio/mp4', src: audio_file.m4a.url(options)},
    {type: 'audio/mpeg', src: audio_file.mp3.url(options)}
  ]
end