AlchemyCMS/alchemy_cms

View on GitHub
app/components/alchemy/ingredients/audio_view.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
module Alchemy
  module Ingredients
    class AudioView < BaseView
      def call
        content_tag(:audio, **html_options) do
          tag(:source, src: src, type: type)
        end.html_safe
      end

      def render?
        !!ingredient.attachment
      end

      private

      def src
        alchemy.show_attachment_path(
          ingredient.attachment,
          format: ingredient.attachment.suffix
        )
      end

      def type
        ingredient.attachment.file_mime_type
      end

      def html_options
        {
          controls: ingredient.controls,
          autoplay: ingredient.autoplay,
          loop: ingredient.loop,
          muted: ingredient.muted
        }
      end
    end
  end
end