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, as above

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:



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

def initialize(context:, params: [], source: nil)
  super
  @locals = params.extract_options!
  @path   = params[0]
  @style = ''
  @style = "<style>.audioplayer {#{@locals['style']}}</style>" if @locals['style']

  return if @path.present?

  raise Error, 'Missing path for audio tag'
end

Instance Attribute Details

#localsObject (readonly)

Returns the value of attribute locals.



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

def locals
  @locals
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#styleObject (readonly)

Returns the value of attribute style.



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

def style
  @style
end

Instance Method Details

#contentObject



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

def content
  format("#{@style}<audio controls class=\"audioplayer\" src=#{@path}></audio>")
end