Sha256: 31c2881545ff7472bd5ce74f9d4a38291c19890b7da8813c3bf1b2eb5d6d8d9c

Contents?: true

Size: 1.65 KB

Versions: 19

Compression:

Stored size: 1.65 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)
        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

19 entries across 19 versions & 1 rubygems

Version Path
cmor_carousels-0.0.32.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.31.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.30.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.29.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.28.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.27.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.26.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.25.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.24.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.22.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.21.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.20.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.19.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.18.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.17.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.15.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.14.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.13.pre app/view_helpers/cmor/carousels/application_view_helper.rb
cmor_carousels-0.0.12.pre app/view_helpers/cmor/carousels/application_view_helper.rb