don't load local templates if no HOME is set

This commit is contained in:
Karl Freeman 2014-03-25 08:21:53 +00:00
parent ad14766278
commit 845d529a50

View file

@ -88,16 +88,19 @@ end
# Register all official templates # Register all official templates
Dir.glob(File.expand_path('../middleman-templates/*.rb', __FILE__), &method(:require)) Dir.glob(File.expand_path('../middleman-templates/*.rb', __FILE__), &method(:require))
# Iterate over directories in the templates path and register each one. # Sometimes HOME doesn't exist, in which case there's no point to local templates
Dir[File.join(Middleman::Templates::Local.source_root, '*')].each do |dir| if ENV['HOME']
next unless File.directory?(dir) # Iterate over directories in the templates path and register each one.
template_file = File.join(dir, 'template.rb') Dir[File.join(Middleman::Templates::Local.source_root, '*')].each do |dir|
next unless File.directory?(dir)
template_file = File.join(dir, 'template.rb')
# If a template.rb file is found require it (therefore registering the template) # If a template.rb file is found require it (therefore registering the template)
# else register the folder as a Local template (which when built, just copies the folder) # else register the folder as a Local template (which when built, just copies the folder)
if File.exists?(template_file) if File.exists?(template_file)
require template_file require template_file
else else
Middleman::Templates.register(File.basename(dir).to_sym, Middleman::Templates::Local) Middleman::Templates.register(File.basename(dir).to_sym, Middleman::Templates::Local)
end
end end
end end