Sha256: 8d4dd685cb96f7e2ddb294474304e1ab86dbfb0b2c8cc8484d646b1510e13f82

Contents?: true

Size: 1.22 KB

Versions: 49

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require 'active_support'

module CKEditor5::Rails::Cdn
  module UrlGenerator
    extend ActiveSupport::Concern

    CDN_THIRD_PARTY_GENERATORS = {
      jsdelivr: lambda { |bundle, version, path|
        base_url = "https://cdn.jsdelivr.net/npm/#{bundle}@#{version}/dist"
        "#{base_url}/#{path.start_with?('translations/') ? '' : 'browser/'}#{path}"
      },

      unpkg: lambda { |bundle, version, path|
        base_url = "https://unpkg.com/#{bundle}@#{version}/dist"
        "#{base_url}/#{path.start_with?('translations/') ? '' : 'browser/'}#{path}"
      }
    }.freeze

    CDN_COMMERCIAL_GENERATORS = {
      cloud: lambda { |bundle, version, path|
        "https://cdn.ckeditor.com/#{bundle}/#{version}/#{path}"
      },

      ckbox: lambda { |bundle, version, path|
        "https://cdn.ckbox.io/#{bundle}/#{version}/#{path}"
      }
    }.freeze

    included do
      attr_reader :cdn
    end

    def create_cdn_url(bundle, version, path)
      executor = CDN_THIRD_PARTY_GENERATORS[cdn] || CDN_COMMERCIAL_GENERATORS[cdn] || cdn

      raise ArgumentError, "Unknown provider: #{cdn}" if executor.blank? || !executor.respond_to?(:call)

      executor.call(bundle, version, path)
    end
  end
end

Version data entries

49 entries across 49 versions & 2 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/ckeditor5-1.24.9/lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.24.9 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.24.8 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.24.6 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.24.5 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.24.4 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.24.3 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.24.2 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.24.1 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.24.0 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.23.5 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.23.4 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.23.3 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.23.2 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.23.1 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.23.0 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.22.0 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.21.0 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.20.1 lib/ckeditor5/rails/cdn/url_generator.rb
ckeditor5-1.20.0 lib/ckeditor5/rails/cdn/url_generator.rb