Module: Pageflow::AudioFilesHelper

Includes:
RevisionFileHelper
Included in:
Editor::FilesHelper
Defined in:
app/helpers/pageflow/audio_files_helper.rb

Instance Method Summary collapse

Methods included from RevisionFileHelper

#find_file_in_entry

Instance Method Details

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



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

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

  audio_file = find_file_in_entry(AudioFile, audio_file_perma_id)
  return unless audio_file
  (:audio, options) do
    audio_file_sources(audio_file, url_options).each do |source|
      concat(tag(:source, source.slice(:src, :type)))
    end
  end
end


28
29
30
31
32
# File 'app/helpers/pageflow/audio_files_helper.rb', line 28

def audio_file_non_js_link(entry, audio_file_perma_id)
  audio_file = find_file_in_entry(AudioFile, audio_file_perma_id)
  return unless audio_file
  link_to(t('pageflow.audio.open'), short_audio_file_path(entry, audio_file))
end

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



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

def audio_file_script_tag(audio_file_perma_id, options = {})
  audio_file = find_file_in_entry(AudioFile, audio_file_perma_id)
  return unless audio_file
  render('pageflow/audio_files/script_tag',
         audio_file: audio_file,
         audio_file_sources: audio_file_sources(audio_file, options))
end

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



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

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