sinatra-default_charset
-
docs: libraggi.rubyforge.org/sinatra-default_charset/README_rdoc.html
-
rubyforge: rubyforge.org/projects/libraggi
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.