Class: Occams::Content::Tag::Audio
- Inherits:
-
Occams::Content::Tag
- Object
- Occams::Content::Tag
- Occams::Content::Tag::Audio
- 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
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
Attributes inherited from Occams::Content::Tag
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize(context:, params: [], source: nil) ⇒ Audio
constructor
A new instance of Audio.
Methods inherited from Occams::Content::Tag
Constructor Details
#initialize(context:, params: [], source: nil) ⇒ Audio
Returns a new instance of Audio.
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. @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
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
18 19 20 |
# File 'lib/occams/content/tags/audio.rb', line 18 def locals @locals end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
18 19 20 |
# File 'lib/occams/content/tags/audio.rb', line 18 def path @path end |
#style ⇒ Object (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
#content ⇒ Object
32 33 34 |
# File 'lib/occams/content/tags/audio.rb', line 32 def content format("#{@style}<audio controls class=\"audioplayer\" src=#{@path}></audio>") end |