Sha256: bad2a4804fc26d44dc1193b0f12830604e34ea8f8559e99e99661b2ff63fb86f

Contents?: true

Size: 1.63 KB

Versions: 5

Compression:

Stored size: 1.63 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)
        carousel_options = options.slice(:autostart, :interval, :pause, :ride, :wrap)
        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
          return c.render partial: 'cmor/carousels/application_view_helper/render', locals: { carousel: carousel, options: options, data_attributes: data_attributes, variant_options: variant_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

5 entries across 5 versions & 1 rubygems

Version Path
cmor_carousels-0.0.11.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.10.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.9.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.8.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.7.pre app/view_helpers/cmor/carousels/application_view_helper.rb