Sha256: 9526e6b9f142b0d9f515fa0f95db49edbd64ef914340d67cf88fe09c90a978c2

Contents?: true

Size: 1.74 KB

Versions: 22

Compression:

Stored size: 1.74 KB

Contents

module Cmor
  module Carousels
    # Usage:
    #
    #     # app/controllers/application_controller.rb
    #     class ApplicationController < ActionController::Base
    #       view_helper Cmor::Carousels::ApplicationViewHelper, as: :carousels_helper
    #     end
    #
    class ApplicationViewHelper < Rao::ViewHelper::Base
      # Example:
      #
      #     # This will render a bootstrap 4 compatible carousel
      #     = carousels_helper(self).render_carousel(:main, autostart: true, interval: 5.0, variant_options: { resize: "1920x1080" })
      #
      def render_carousel(identifier, options = {})
        options.reverse_merge!(autostart: true, interval: 5.0, keyboard: true, pause: :hover, ride: false, wrap: true, controls: true, indicators: true, video_html_options: {})
        carousel_options = options.slice(:autostart, :interval, :pause, :ride, :wrap)
        video_html_options = options.delete(:video_html_options).reverse_merge!(autoplay: true, muted: true)
        data_attributes = carousel_options_to_data_attributes(carousel_options)

        carousel = Cmor::Carousels::Carousel.where(identifier: identifier.to_s).for_locale(I18n.locale).first

        if carousel.nil?
          return I18n.t('cmor.carousels.carousel.warnings.not_found', identifier: identifier)
        else
          variant_options = options.delete(:variant_options) || carousel.variant_options
          render carousel: carousel, options: options, data_attributes: data_attributes, variant_options: variant_options, video_html_options: video_html_options
        end
      end

      private

      def carousel_options_to_data_attributes(carousel_options)
        carousel_options.collect { |k,v| "\"data-#{k.to_s.dasherize}\"=#{v}" }.join(" ")
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
cmor_carousels-0.0.60.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.59.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.58.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.57.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.56.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.55.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.54.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.53.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.52.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.51.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.50.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.49.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.48.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.45.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.44.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.43.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.42.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.41.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.40.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.39.pre app/view_helpers/cmor/carousels/application_view_helper.rb