|
1 | 1 | # Be sure to restart your server when you modify this file. |
2 | 2 |
|
3 | 3 | # Version of your assets, change this if you want to expire all your assets. |
4 | | -Rails.application.config.assets.version = '1.0' |
| 4 | +Rails.application.config.assets.version = '1.1' |
5 | 5 |
|
6 | 6 | Rails.application.config.tinymce.install = :copy |
7 | 7 |
|
| 8 | +# TinyMCE editor icons in development. |
| 9 | +# |
| 10 | +# sprockets-rails >= 3.5 registers `Sprockets::Rails::AssetUrlProcessor`, a `text/css` |
| 11 | +# post-processor that rewrites every relative `url(...)` reference to a digested asset |
| 12 | +# path. TinyMCE's bundled skin (`tinymce/skins/lightgray/skin.min.css`) references its |
| 13 | +# icon font with directory-relative urls such as `url('fonts/tinymce.woff')`. Sprockets |
| 14 | +# resolves `url()` paths against the asset load roots (not the referencing file's own |
| 15 | +# directory), so it cannot find `fonts/tinymce.woff` (its real logical path is |
| 16 | +# `tinymce/skins/lightgray/fonts/...`) and rewrites it to an invalid root path |
| 17 | +# (`/fonts/tinymce.woff`) which 404s, leaving the editor toolbar without icons. |
| 18 | +# |
| 19 | +# In production this never happens: `tinymce.install = :copy` ships the skin as raw static |
| 20 | +# files under `public/assets`, bypassing Sprockets (and this processor) entirely. The bug |
| 21 | +# only surfaces in environments that compile assets on the fly (development). |
| 22 | +# |
| 23 | +# We must NOT disable the processor globally: other stylesheets (e.g. Bootstrap, whose |
| 24 | +# glyphicon @font-face urls are relative) rely on it to produce resolvable digested paths. |
| 25 | +# Instead, swap it for a thin subclass that, for the TinyMCE skin only, first expands the |
| 26 | +# skin's directory-relative font urls into full logical asset paths (prefixing them with the |
| 27 | +# skin's own logical directory) before delegating to the original processor. The original |
| 28 | +# then resolves and digests them correctly. Every other stylesheet is processed unchanged. |
| 29 | +if defined?(Sprockets::Rails::AssetUrlProcessor) && Rails.application.config.assets.compile && |
| 30 | + Sprockets.respond_to?(:unregister_postprocessor) && Sprockets.respond_to?(:register_postprocessor) |
| 31 | + class TinymceSkinSafeAssetUrlProcessor < Sprockets::Rails::AssetUrlProcessor |
| 32 | + SKIN_MARKER = 'tinymce/skins/'.freeze |
| 33 | + # Directory-relative `url(...)` references that are not absolute/external/data urls. |
| 34 | + RELATIVE_URL = %r{url\(\s*["']?(?!(?:#|data|http|/))(?:\./)?(?<path>[^"'\s)]+)\s*["']?\)} |
| 35 | + |
| 36 | + def self.call(input) |
| 37 | + filename = input[:filename].to_s |
| 38 | + return super unless filename.include?(SKIN_MARKER) |
| 39 | + |
| 40 | + logical_dir = File.dirname(filename[filename.index('tinymce/')..]) |
| 41 | + rewritten = input[:data].gsub(RELATIVE_URL) do |
| 42 | + "url(#{logical_dir}/#{Regexp.last_match(:path)})" |
| 43 | + end |
| 44 | + super(input.merge(data: rewritten)) |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + Sprockets.unregister_postprocessor('text/css', Sprockets::Rails::AssetUrlProcessor) |
| 49 | + Sprockets.register_postprocessor('text/css', TinymceSkinSafeAssetUrlProcessor) |
| 50 | +end |
| 51 | + |
8 | 52 | # Add additional assets to the asset load path |
9 | 53 | Rails.application.config.assets.precompile += %w[camaleon_cms/*] |
10 | 54 | # Rails.application.config.assets.precompile += %w( themes/*/assets/* ) |
|
0 commit comments