rstacruz / sinatra-assetpack

Package your assets transparently in Sinatra.
http://ricostacruz.com/sinatra-assetpack/
MIT License
542 stars 97 forks source link

Css packaging not working in production mode with Padrino #173

Open sashee opened 10 years ago

sashee commented 10 years ago

I have a Padrino app (I don't know if it's important) and I added a css asset. When running in development mode, everything is fine, when running in production, it gives an error:

ArgumentError - unknown encoding name - TEXT/CSS:
        /home/sashee/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.3.2/lib/sinatra/assetpack/package.rb:112:in `force_encoding'
        /home/sashee/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.3.2/lib/sinatra/assetpack/package.rb:112:in `block in combined'
        /home/sashee/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.3.2/lib/sinatra/assetpack/package.rb:108:in `map'
        /home/sashee/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.3.2/lib/sinatra/assetpack/package.rb:108:in `combined'
        /home/sashee/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.3.2/lib/sinatra/assetpack/package.rb:94:in `minify'
        /home/sashee/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.3.2/lib/sinatra/assetpack/class_methods.rb:32:in `block (3 levels) in add_compressed_routes!'
...

I've traced down the error till this: https://github.com/rstacruz/sinatra-assetpack/blob/master/lib/sinatra/assetpack/package.rb#L112 . Here, the response_encoding is TEXT/CSS, and result.content_type is text/css . I think it should have a charset, and for the javascript files it indeed has.

The workaround I use is to set the utf-8 encoding to every css files:

        app.after do
          if request.url.end_with?('css')
            headers "Content-Type" => "text/css;charset=utf-8"
          end
        end

It's bit of a hack, but it's working this way.