Resolve conflict
This commit is contained in:
parent
79f50b0568
commit
081b974114
|
@ -4,6 +4,8 @@ module Jekyll
|
||||||
|
|
||||||
MATCHER = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/
|
MATCHER = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/
|
||||||
|
|
||||||
|
INCLUDES_DIR = '_includes'
|
||||||
|
|
||||||
def initialize(tag_name, markup, tokens)
|
def initialize(tag_name, markup, tokens)
|
||||||
super
|
super
|
||||||
@file, @params = markup.strip.split(' ', 2);
|
@file, @params = markup.strip.split(' ', 2);
|
||||||
|
@ -49,14 +51,13 @@ eos
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
includes_dir = File.join(context.registers[:site].source, '_includes')
|
dir = includes_dir(context)
|
||||||
|
|
||||||
if error = validate_file(includes_dir)
|
if error = validate_file(dir)
|
||||||
return error
|
return error
|
||||||
end
|
end
|
||||||
|
|
||||||
source = read_file(File.join(includes_dir, @file))
|
partial = Liquid::Template.parse(source(dir))
|
||||||
partial = Liquid::Template.parse(source)
|
|
||||||
|
|
||||||
context.stack do
|
context.stack do
|
||||||
context['include'] = parse_params(context) if @params
|
context['include'] = parse_params(context) if @params
|
||||||
|
@ -64,20 +65,20 @@ eos
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_file(includes_dir)
|
def validate_file(dir)
|
||||||
if File.symlink?(includes_dir)
|
if File.symlink?(dir)
|
||||||
return "Includes directory '#{includes_dir}' cannot be a symlink"
|
return "Includes directory '#{dir}' cannot be a symlink"
|
||||||
end
|
end
|
||||||
|
|
||||||
if @file !~ /^[a-zA-Z0-9_\/\.-]+$/ || @file =~ /\.\// || @file =~ /\/\./
|
if @file !~ /^[a-zA-Z0-9_\/\.-]+$/ || @file =~ /\.\// || @file =~ /\/\./
|
||||||
return "Include file '#{@file}' contains invalid characters or sequences"
|
return "Include file '#{@file}' contains invalid characters or sequences"
|
||||||
end
|
end
|
||||||
|
|
||||||
file = File.join(includes_dir, @file)
|
file = File.join(dir, @file)
|
||||||
if !File.exists?(file)
|
if !File.exists?(file)
|
||||||
return "Included file #{@file} not found in _includes directory"
|
return "Included file #{@file} not found in #{INCLUDES_DIR} directory"
|
||||||
elsif File.symlink?(file)
|
elsif File.symlink?(file)
|
||||||
return "The included file '_includes/#{file}' should not be a symlink"
|
return "The included file '#{INCLUDES_DIR}/#{@file}' should not be a symlink"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -85,8 +86,14 @@ eos
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_file(file)
|
# This method allows to modify the file content by inheriting from the class.
|
||||||
return File.read(file)
|
# Don’t refactor it.
|
||||||
|
def source(dir)
|
||||||
|
File.read(File.join(dir, @file))
|
||||||
|
end
|
||||||
|
|
||||||
|
def includes_dir(context)
|
||||||
|
File.join(context.registers[:site].source, INCLUDES_DIR)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue