Sha256: 19a3e6af4abf46165fb14d632eb8c486e8c0d52727d6c460d2efafab3413af07

Contents?: true

Size: 1.45 KB

Versions: 4

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'),
            window_name: 'CKBox'
          ),
          *translations_js_exports_meta
        ]
      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

4 entries across 4 versions & 1 rubygems

Version Path
ckeditor5-1.16.1 lib/ckeditor5/rails/cdn/ckbox_bundle.rb
ckeditor5-1.16.0 lib/ckeditor5/rails/cdn/ckbox_bundle.rb
ckeditor5-1.15.10 lib/ckeditor5/rails/cdn/ckbox_bundle.rb
ckeditor5-1.15.9 lib/ckeditor5/rails/cdn/ckbox_bundle.rb