Sha256: ccd3174de638c83fa14bf349128831dbb94d855432440d0f14f49d776b173d45

Contents?: true

Size: 1.21 KB

Versions: 157

Compression:

Stored size: 1.21 KB

Contents

require 'tilt'

module Sprockets
  # Some browsers have issues with stylesheets that contain multiple
  # `@charset` definitions. The issue surfaces while using Sass since
  # it inserts a `@charset` at the top of each file. Then Sprockets
  # concatenates them together.
  #
  # The `CharsetNormalizer` processor strips out multiple `@charset`
  # definitions.
  #
  # The current implementation is naive. It picks the first `@charset`
  # it sees and strips the others. This works for most people because
  # the other definitions are usually `UTF-8`. A more sophisticated
  # approach would be to re-encode stylesheets with mixed encodings.
  #
  # This behavior can be disabled with:
  #
  #     environment.unregister_bundle_processor 'text/css', Sprockets::CharsetNormalizer
  #
  class CharsetNormalizer < Tilt::Template
    def prepare
    end

    def evaluate(context, locals, &block)
      charset = nil

      # Find and strip out any `@charset` definitions
      filtered_data = data.gsub(/^@charset "([^"]+)";$/) {
        charset ||= $1; ""
      }

      if charset
        # If there was a charset, move it to the top
        "@charset \"#{charset}\";#{filtered_data}"
      else
        data
      end
    end
  end
end

Version data entries

157 entries across 132 versions & 22 rubygems

Version Path
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2/lib/sprockets/charset_normalizer.rb
challah-0.9.0 vendor/bundle/gems/sprockets-2.2.2/lib/sprockets/charset_normalizer.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/sprockets-2.2.2/lib/sprockets/charset_normalizer.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/sprockets-2.2.2/lib/sprockets/charset_normalizer.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/sprockets-2.2.2/lib/sprockets/charset_normalizer.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/sprockets-2.2.2/lib/sprockets/charset_normalizer.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/sprockets-2.2.2/lib/sprockets/charset_normalizer.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/sprockets-2.2.2/lib/sprockets/charset_normalizer.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/sprockets-2.2.2/lib/sprockets/charset_normalizer.rb
jquery_regex-0.0.3 vendor/bundle/gems/sprockets-2.2.2/lib/sprockets/charset_normalizer.rb
jquery_regex-0.0.1 vendor/bundle/gems/sprockets-2.2.2/lib/sprockets/charset_normalizer.rb
sprockets-2.8.2 lib/sprockets/charset_normalizer.rb
sprockets-2.2.2 lib/sprockets/charset_normalizer.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/sprockets-2.2.1/lib/sprockets/charset_normalizer.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/sprockets-2.1.3/lib/sprockets/charset_normalizer.rb
challah-rolls-0.2.0 vendor/bundle/gems/sprockets-2.2.1/lib/sprockets/charset_normalizer.rb
challah-rolls-0.2.0 vendor/bundle/gems/sprockets-2.1.3/lib/sprockets/charset_normalizer.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/sprockets-2.1.3/lib/sprockets/charset_normalizer.rb
challah-0.8.3 vendor/bundle/gems/sprockets-2.2.1/lib/sprockets/charset_normalizer.rb
challah-0.8.3 vendor/bundle/gems/sprockets-2.1.3/lib/sprockets/charset_normalizer.rb