Class: Ckeditor::Rails::AssetUrlProcessor
- Inherits:
-
Object
- Object
- Ckeditor::Rails::AssetUrlProcessor
- Defined in:
- lib/ckeditor-rails/asset_url_processor.rb
Overview
Rewrites urls in CSS files with the digested paths
Constant Summary collapse
- REGEX =
/url\(\s*["']?(?!(?:\#|data|http))([^"'\s)]+)\s*["']?\)/
Class Method Summary collapse
Class Method Details
.assets_base_path(context = nil) ⇒ Object
11 12 13 14 15 |
# File 'lib/ckeditor-rails/asset_url_processor.rb', line 11 def self.assets_base_path(context = nil) return ::Ckeditor::Rails.assets_base_path unless context "#{context.assets_prefix}/ckeditor" end |
.call(input) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ckeditor-rails/asset_url_processor.rb', line 17 def self.call(input) return { data: input[:data] } unless stylesheet_files.include?(input[:filename]) context = input[:environment].context_class.new(input) path_prefix = assets_base_path() matched_folders = input[:filename].match(/\/ckeditor\/(plugins|skins)\/([\w-]+)\//) data = input[:data].gsub(REGEX) { |_match| raw_asset_path = context.asset_path($1) if raw_asset_path.starts_with?(path_prefix) "url(#{raw_asset_path})" elsif matched_folders "url(#{path_prefix}/#{matched_folders[1]}/#{matched_folders[2]}#{raw_asset_path.gsub('/..', '')})" else "url(#{path_prefix}#{raw_asset_path})" end } { data: data } end |
.stylesheet_files ⇒ Object
7 8 9 |
# File 'lib/ckeditor-rails/asset_url_processor.rb', line 7 def self.stylesheet_files @stylesheet_files ||= ::Ckeditor::Rails::Asset.new.stylesheet_files end |