diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index 21f950d0..44bd8b9a 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -20,6 +20,12 @@ module Jekyll self.content || '' end + # Returns merged optin hash for File.read of self.site (if exists) + # and a given param + def merged_file_read_opts(opts) + (self.site ? self.site.file_read_opts : {}).merge(opts) + end + # Read the YAML frontmatter. # # base - The String path to the dir containing the file. @@ -29,10 +35,8 @@ module Jekyll # Returns nothing. def read_yaml(base, name, opts = {}) begin - opts = (self.site ? self.site.file_read_opts : {}).merge(opts) - - self.content = File.read(File.join(base, name), opts) - + self.content = File.read_with_options(File.join(base, name), + merged_file_read_opts(opts)) if self.content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m self.content = $POSTMATCH self.data = YAML.safe_load($1) diff --git a/lib/jekyll/core_ext.rb b/lib/jekyll/core_ext.rb index 1a7b1816..54f7c9d5 100644 --- a/lib/jekyll/core_ext.rb +++ b/lib/jekyll/core_ext.rb @@ -69,3 +69,18 @@ module Enumerable any? { |exp| File.fnmatch?(exp, e) } end end + +# Ruby 1.8's File.read don't support option. +# read_with_options ignore optional parameter for 1.8, +# and act as alias for 1.9 or later. +class File + if RUBY_VERSION < '1.9' + def self.read_with_options(path, opts = {}) + self.read(path) + end + else + def self.read_with_options(path, opts = {}) + self.read(path, opts) + end + end +end diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index b8b54353..57095ce7 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -70,6 +70,11 @@ eos end end + # Grab file read opts in the context + def file_read_opts(context) + context.registers[:site].file_read_opts + end + def render(context) dir = File.join(context.registers[:site].source, INCLUDES_DIR) if error = validate_dir(dir, context.registers[:site].safe) @@ -81,7 +86,7 @@ eos return error end - partial = Liquid::Template.parse(source(file)) + partial = Liquid::Template.parse(source(file, context)) context.stack do context['include'] = parse_params(context) if @params @@ -108,8 +113,8 @@ eos end # This method allows to modify the file content by inheriting from the class. - def source(file) - File.read(file, context.registers[:site].file_read_opts) + def source(file, context) + File.read_with_options(file, file_read_opts(context)) end end end