Class: Occams::Content::Tag::Audio

Inherits:
Occams::Content::Tag show all
Defined in:
lib/occams/content/tags/audio.rb

Overview

Tag for injecting HTML5 audio player. Example tag:

{{ cms:audio "path/to/audio", style: "height: 22px; width: 80%" }}

This expands into:

<audio controls src="path/to/audio"></audio>

To customize your player style, add a ‘audioplayer’ class to your CSS, e.g .audioplayer

border-radius: 6px
height: 22px
width: 60%
margin: 2px 0 2px 8px
padding: 0

and/or pass in style overrides with the ‘style’ parameter

Instance Attribute Summary collapse

Attributes inherited from Occams::Content::Tag

#context, #params, #source

Instance Method Summary collapse

Methods inherited from Occams::Content::Tag

#allow_erb?, #nodes, #render

Constructor Details

#initialize(context:, params: [], source: nil) ⇒ Audio

Returns a new instance of Audio.

Raises:



19
20
21
22
23
24
25
26
27
28
# File 'lib/occams/content/tags/audio.rb', line 19

def initialize(context:, params: [], source: nil)
  super
  options = params.extract_options!
  @path   = params[0]
  @style  = options['style']

  return if @path.present?

  raise Error, 'Missing path for audio tag'
end

Instance Attribute Details

#localsObject (readonly)

Returns the value of attribute locals.



17
18
19
# File 'lib/occams/content/tags/audio.rb', line 17

def locals
  @locals
end

#pathObject (readonly)

Returns the value of attribute path.



17
18
19
# File 'lib/occams/content/tags/audio.rb', line 17

def path
  @path
end

Instance Method Details

#contentObject



30
31
32
33
34
35
36
# File 'lib/occams/content/tags/audio.rb', line 30

def content
  format(
    '<style>.audioplayer {%<style>s}</style><audio controls class="audioplayer" src=%<path>p></audio>',
    path: @path,
    style: @style
  )
end