A sinatra plugin to specify a default charset for all responses (applied to the content_type header)
Ruby
Switch branches/tags
Nothing to show
Latest commit ab5d2a7 May 25, 2010 @raggi Some working tests
Allow no charset
Better defaults based on $kcode or Encoding.default_external
Docs for changes
Permalink
Failed to load latest commit information.
lib/sinatra Some working tests May 25, 2010
test/test_sinatra Some working tests May 25, 2010
.autotest Initial commit May 24, 2010
.gitignore Initial commit May 24, 2010
CHANGELOG.rdoc Some working tests May 25, 2010
Manifest.txt Some working tests May 25, 2010
README.rdoc Some working tests May 25, 2010
Rakefile Some working tests May 25, 2010

README.rdoc

sinatra-default_charset

DESCRIPTION:

Sets a default charset in the MIME headers. Defaults to Encoding.default_external on ruby 1.9, and to $kcode on ruby 1.8, or falls back to utf-8 when neither are available.

Provides a setting called default_charset that allows overriding the auto-discovered default.

To remove the transmitted charset for a single request, simply pass +:charset

> nil+ as your parameter to the content_type helper.

FEATURES/PROBLEMS:

  • Applies a default charset field to the Content-Type header of all responses

  • Allows for removal of the default-applied field

  • Allows for per-request overrides of the value

SYNOPSIS:

require 'sinatra/default_charset'
register Sinatra::DefaultCharset
set :default_charset, 'utf-8'

get '/' do
  "I'm utf-8"
end

get '/shift_jis' do 
  content_type :html, :charset => 'shift_jis'
  "I'm shift_jis"
end

get '/none' do
  content_type :html, :charset => nil
  "I have no charset in my headers"
end

REQUIREMENTS:

  • sinatra for runtime.

  • rack-test and minitest for testing.

INSTALL:

  • gem install sinatra-default_charset

LICENSE:

(The MIT License)

Copyright © 2010 James Tucker

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.