Sha256: 88ca340356a1dfa2c96d7343b109c5f07f513eecfae93faf0837b9fb467a39e3

Contents?: true

Size: 1.45 KB

Versions: 10

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

module CKEditor5::Rails
  module Cdn
    class CKBoxBundle < Assets::AssetsBundle
      include Cdn::UrlGenerator

      attr_reader :cdn, :version, :theme, :translations

      def initialize(version, theme: :lark, cdn: Engine.default_preset.cdn, translations: [])
        super()

        @cdn = cdn
        @version = version
        @theme = theme
        @translations = translations

        validate!
      end

      def scripts
        @scripts ||= [
          Assets::JSExportsMeta.new(
            create_cdn_url('ckbox', version, 'ckbox.js'),
            *translations_js_exports_meta,
            window_name: 'CKBox'
          )
        ]
      end

      def stylesheets
        @stylesheets ||= [
          create_cdn_url('ckbox', version, "styles/themes/#{theme}.css")
        ]
      end

      private

      def validate!
        raise ArgumentError, 'version must be semver' unless version.is_a?(Semver)
        raise ArgumentError, 'translations must be an array' unless translations.is_a?(Array)

        return if theme.is_a?(String) || theme.is_a?(Symbol)

        raise ArgumentError,
              'theme must be a string or symbol'
      end

      def translations_js_exports_meta
        translations.map do |lang|
          url = create_cdn_url('ckbox', version, "translations/#{lang}.js")

          Assets::JSExportsMeta.new(url, window_name: 'CKBOX_TRANSLATIONS', translation: true)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ckeditor5-1.15.8 lib/ckeditor5/rails/cdn/ckbox_bundle.rb
ckeditor5-1.15.7 lib/ckeditor5/rails/cdn/ckbox_bundle.rb
ckeditor5-1.15.2 lib/ckeditor5/rails/cdn/ckbox_bundle.rb
ckeditor5-1.15.1 lib/ckeditor5/rails/cdn/ckbox_bundle.rb
ckeditor5-1.15.0 lib/ckeditor5/rails/cdn/ckbox_bundle.rb
ckeditor5-1.14.1 lib/ckeditor5/rails/cdn/ckbox_bundle.rb
ckeditor5-1.14.0 lib/ckeditor5/rails/cdn/ckbox_bundle.rb
ckeditor5-1.12.0 lib/ckeditor5/rails/cdn/ckbox_bundle.rb
ckeditor5-1.11.1 lib/ckeditor5/rails/cdn/ckbox_bundle.rb
ckeditor5-1.11.0 lib/ckeditor5/rails/cdn/ckbox_bundle.rb