spohlenz / tinymce-rails

Integration of TinyMCE with the Rails asset pipeline
Other
813 stars 256 forks source link

Allow for relative paths in content_css configuration #245

Closed codealchemy closed 5 years ago

codealchemy commented 6 years ago

TinyMCE allows for relative urls for content_css, however the current transformer first checks with ActionController::Base to find the path for the given file, which can raise an error when the path given starts with . or .. (seen on Rails 4.2.10 - though the error itself gets raised further down in sprockets).

> ActionController::Base.helpers.stylesheet_path('content_css')
=> "/stylesheets/content_css.css"
> ActionController::Base.helpers.stylesheet_path('/content_css')
=> "/content_css.css"
> ActionController::Base.helpers.stylesheet_path('./content_css')
NoMethodError: undefined method `start_with?' for nil:NilClass
> ActionController::Base.helpers.stylesheet_path('../content_css')
NoMethodError: undefined method `start_with?' for nil:NilClass

This adds an additional check the transformer for paths starting with /, ., and .., and passes that through to the tinymce configuration before going through the rails/sprockets pipeline. This mirrors how other configurations (ex. image_list or images_upload_url) pass a given path to TinyMCE.

This would allow an app to configure the editor to retrieve css from an endpoint relative to where the editor itself loads - such as stylesheets managed by users for a CMS, for example.

spohlenz commented 5 years ago

Looks good, thank you. šŸ‘ Sorry for taking so long to review and merge.