#... module Sprockets # Internal: HTTP transport encoding and charset detecting related functions. # Mixed into Environment. module EncodingUtils extend self #... # Public: Detect charset from HTML document. Defaults to ISO-8859-1. # # str - String. # # Returns a encoded String. def detect_html(str) str = detect_unicode_bom(str) # Attempt Charlock detection if str.encoding == Encoding::BINARY charlock_detect(str) end # Fallback to ISO-8859-1 if str.encoding == Encoding::BINARY str.force_encoding(Encoding::ISO_8859_1) end str end CHARSET_DETECT[:html] = method(:detect_html) end end
Rails.application.assets.register_mime_type('text/html', extensions: '.html', charset: :default)
Source: https://habr.com/ru/post/256523/
All Articles