Implement the :encoding setting which defaults to 'utf-8'

This commit is contained in:
Rico Sta. Cruz 2012-06-16 06:07:44 +08:00
parent f4feda8b93
commit 96c29181aa
3 changed files with 35 additions and 1 deletions

View file

@ -117,6 +117,10 @@ module Middleman
# @return [String]
set :http_prefix, "/"
# Default string encoding for templates and output.
# @return [String]
set :encoding, "utf-8"
# Whether to catch and display exceptions
# @return [Boolean]
set :show_exceptions, true
@ -128,6 +132,9 @@ module Middleman
# Activate custom features and extensions
include Middleman::CoreExtensions::Extensions
# Manage Ruby string encodings
include Middleman::CoreExtensions::RubyEncoding
# Basic Rack Request Handling
include Middleman::CoreExtensions::Request

View file

@ -27,4 +27,7 @@ require "middleman-core/core_extensions/rendering"
require "middleman-core/core_extensions/routing"
# Catch and show exceptions at the Rack level
require "middleman-core/core_extensions/show_exceptions"
require "middleman-core/core_extensions/show_exceptions"
# Manage Ruby string encodings
require "middleman-core/core_extensions/ruby_encoding"

View file

@ -0,0 +1,24 @@
# Simple extension to manage Ruby encodings
module Middleman::CoreExtensions::RubyEncoding
# Setup extension
class << self
# Once registerd
def registered(app)
app.send :include, InstanceMethods
end
end
module InstanceMethods
def initialize
if Object.const_defined?(:Encoding)
Encoding.default_internal = encoding
Encoding.default_external = encoding
end
super
end
end
end