raise exceptions in include tag
This commit is contained in:
parent
72c3bba56a
commit
9409a3d034
|
@ -72,14 +72,10 @@ eos
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
dir = File.join(context.registers[:site].source, INCLUDES_DIR)
|
dir = File.join(context.registers[:site].source, INCLUDES_DIR)
|
||||||
if error = validate_dir(dir, context.registers[:site].safe)
|
validate_dir(dir, context.registers[:site].safe)
|
||||||
return error
|
|
||||||
end
|
|
||||||
|
|
||||||
file = File.join(dir, @file)
|
file = File.join(dir, @file)
|
||||||
if error = validate_file(dir, context.registers[:site].safe)
|
validate_file(file, context.registers[:site].safe)
|
||||||
return error
|
|
||||||
end
|
|
||||||
|
|
||||||
partial = Liquid::Template.parse(source(file))
|
partial = Liquid::Template.parse(source(file))
|
||||||
|
|
||||||
|
@ -91,15 +87,15 @@ eos
|
||||||
|
|
||||||
def validate_dir(dir, safe)
|
def validate_dir(dir, safe)
|
||||||
if File.symlink?(dir) && safe
|
if File.symlink?(dir) && safe
|
||||||
"Includes directory '#{dir}' cannot be a symlink"
|
raise IOError.new "Includes directory '#{dir}' cannot be a symlink"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_file(file, safe)
|
def validate_file(file, safe)
|
||||||
if !File.exists?(file)
|
if !File.exists?(file)
|
||||||
"Included file '#{@file}' not found in '#{INCLUDES_DIR}' directory"
|
raise IOError.new "Included file '#{@file}' not found in '#{INCLUDES_DIR}' directory"
|
||||||
elsif File.symlink?(file) && safe
|
elsif File.symlink?(file) && safe
|
||||||
"The included file '#{INCLUDES_DIR}/#{@file}' should not be a symlink"
|
raise IOError.new "The included file '#{INCLUDES_DIR}/#{@file}' should not be a symlink"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue