Sha256: 163f4313996fe662b3ac4ffc2939105429c8f6eb0fb78db5b694383ba6a629f0

Contents?: true

Size: 1.5 KB

Versions: 6

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

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

      attr_reader :version, :translations, :import_name

      def initialize(version, import_name, cdn: Engine.base.default_cdn, translations: [])
        raise ArgumentError, 'version must be semver' unless version.is_a?(Semver)
        raise ArgumentError, 'import_name must be a string' unless import_name.is_a?(String)
        raise ArgumentError, 'translations must be an array' unless translations.is_a?(Array)

        super()

        @cdn = cdn
        @version = version
        @import_name = import_name
        @translations = translations
      end

      def scripts
        @scripts ||= [
          js_exports_meta,
          *translations_js_exports_meta
        ]
      end

      def stylesheets
        @stylesheets ||= [
          create_cdn_url(import_name, version, "#{import_name}.css")
        ]
      end

      private

      def js_exports_meta
        Assets::JSExportsMeta.new(
          create_cdn_url(import_name, version, "#{import_name}.js"),
          import_name: import_name
        )
      end

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

          Assets::JSExportsMeta.new(
            url,
            import_name: "#{import_name}/translations/#{lang}.js",
            translation: true
          )
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ckeditor5-1.0.5 lib/ckeditor5/rails/cdn/ckeditor_bundle.rb
ckeditor5-1.0.4 lib/ckeditor5/rails/cdn/ckeditor_bundle.rb
ckeditor5-1.0.3 lib/ckeditor5/rails/cdn/ckeditor_bundle.rb
ckeditor5-1.0.2 lib/ckeditor5/rails/cdn/ckeditor_bundle.rb
ckeditor5-1.0.1 lib/ckeditor5/rails/cdn/ckeditor_bundle.rb
ckeditor5-1.0.0 lib/ckeditor5/rails/cdn/ckeditor_bundle.rb