Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
lib/jekyll/rendering.rb (include_file): Allow inclusion of files from…
Browse files Browse the repository at this point in the history
… *current* directory.
  • Loading branch information
blackwinter committed Oct 1, 2010
1 parent e48ce57 commit 7e72026
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/jekyll/rendering.rb
Expand Up @@ -153,18 +153,22 @@ module Helpers

# call-seq:
# include_file file => aString
# include_file file, binding => aString
#
# Includes file +file+ from <tt>_includes</tt> directory rendered
# as ERB template. Uses optional +binding+ if provided.
def include_file(file, binding = binding)
Dir.chdir(File.join(site.source, '_includes')) {
@choices ||= Dir['**/*'].reject { |x| File.symlink?(x) }

if @choices.include?(file = file.strip)
# Includes file +file+ from <tt>_includes</tt> directory, or current
# directory if +current+ is true, rendered as ERB template. Uses
# optional +binding+ if provided.
def include_file(file, current = false, binding = binding)
dir = current ? File.dirname(page.url) : '_includes'

Dir.chdir(File.join(site.source, dir)) {
@choices ||= Hash.new { |h, k|
h[k] = Dir['**/*'].reject { |x| File.symlink?(x) }
}

if @choices[dir].include?(file = file.strip)
render(File.read(file), binding)
else
"Included file '#{file}' not found in _includes directory"
"[Included file `#{file}' not found in `#{dir}'.]"
end
}
end
Expand Down

0 comments on commit 7e72026

Please sign in to comment.