lib/trestle/engine.rb in trestle-0.10.0.pre vs lib/trestle/engine.rb in trestle-0.10.0.pre2

- old
+ new

@@ -1,5 +1,7 @@ +require "turbo-rails" + module Trestle class Engine < ::Rails::Engine isolate_namespace Trestle self.routes.default_scope = {} @@ -28,33 +30,33 @@ if defined?(Draper) Draper::CollectionDecorator.delegate :current_page, :total_pages, :limit_value, :entry_name, :total_count, :offset_value, :last_page? end end - initializer "turbo.mimetype" do - Mime::Type.register "text/vnd.turbo-stream.html", :turbo_stream unless Mime[:turbo_stream] - end - - initializer "turbo.renderer" do - ActiveSupport.on_load(:action_controller) do - # Compatibility fix for Rails 5.2 - delegate :media_type, to: "@_response" unless instance_methods.include?(:media_type) - - ActionController::Renderers.add :turbo_stream do |turbo_streams_html, options| - self.content_type = Mime[:turbo_stream] if media_type.nil? - turbo_streams_html - end - end - end - config.to_prepare do Engine.reset_helpers! end config.after_initialize do |app| reloader = Trestle::Reloader.new(*app.watchable_args) reloader.install(app) unless app.config.eager_load end + + # For compatibility with the `sassc-rails`` gem, register a custom compressor that excludes the + # Trestle admin stylesheets as a) they are already minimized and b) libsass is not compatible with + # some of the newer CSS syntax that is used. + # + # To avoid this being necessary, it is recommended that either + # 1) `sassc-rails` is removed from the Gemfile (if not required), + # 2) the `sassc-embedded` gem is added to the Gemfile, or + # 3) `sassc-rails` is replaced with `dartsass-sprockets` + config.assets.configure do |env| + if original_compressor = config.assets.css_compressor + require "trestle/sprockets_compressor" + original_compressor = Sprockets.compressors['text/css'][original_compressor] if original_compressor.is_a?(Symbol) + config.assets.css_compressor = Trestle::SprocketsCompressor.new(original_compressor) + end + end if defined?(SassC::Rails) def reset_helpers! @helpers = nil end end