From 8a28d806909b4ac15491faf81f29de4b05dfef52 Mon Sep 17 00:00:00 2001 From: MURAOKA Taro Date: Tue, 30 Jul 2013 22:21:09 +0900 Subject: [PATCH] add encoding for configuration --- lib/jekyll/configuration.rb | 1 + lib/jekyll/convertible.rb | 2 +- lib/jekyll/site.rb | 7 ++++++- lib/jekyll/tags/include.rb | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 05a097c7..75230bb8 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -11,6 +11,7 @@ module Jekyll 'plugins' => '_plugins', 'layouts' => '_layouts', 'keep_files' => ['.git','.svn'], + 'encoding' => nil, 'timezone' => nil, # use the local timezone diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index 5f493800..74125e7b 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -28,7 +28,7 @@ module Jekyll # Returns nothing. def read_yaml(base, name) begin - self.content = File.read(File.join(base, name)) + self.content = File.read(File.join(base, name), self.site.file_read_opts) if self.content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m self.content = $POSTMATCH diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index ef7be1fc..6aec1c19 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -3,7 +3,7 @@ module Jekyll attr_accessor :config, :layouts, :posts, :pages, :static_files, :categories, :exclude, :include, :source, :dest, :lsi, :pygments, :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts, - :show_drafts, :keep_files, :baseurl + :show_drafts, :keep_files, :baseurl, :file_read_opts attr_accessor :converters, :generators @@ -22,6 +22,11 @@ module Jekyll self.plugins = plugins_path self.permalink_style = config['permalink'].to_sym + self.file_read_opts = {} + if encoding = config['encoding'] + self.file_read_opts[:encoding] = Encoding.find(encoding) + end + self.reset self.setup end diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index 2b0d82b4..b8b54353 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -109,7 +109,7 @@ eos # This method allows to modify the file content by inheriting from the class. def source(file) - File.read(file) + File.read(file, context.registers[:site].file_read_opts) end end end