Merge pull request #4077 from jekyll/fix_render
Merge pull request 4077
This commit is contained in:
commit
528ec27df0
|
@ -5,6 +5,13 @@ Feature: Rendering
|
||||||
But I want to make it as simply as possible
|
But I want to make it as simply as possible
|
||||||
So render with Liquid and place in Layouts
|
So render with Liquid and place in Layouts
|
||||||
|
|
||||||
|
Scenario: When receiving bad Liquid
|
||||||
|
Given I have a "index.html" page with layout "simple" that contains "{% include invalid.html %}"
|
||||||
|
And I have a simple layout that contains "{{ content }}"
|
||||||
|
When I run jekyll build
|
||||||
|
Then I should get a non-zero exit-status
|
||||||
|
And I should see "Liquid Exception" in the build output
|
||||||
|
|
||||||
Scenario: Render Liquid and place in layout
|
Scenario: Render Liquid and place in layout
|
||||||
Given I have a "index.html" page with layout "simple" that contains "Hi there, Jekyll {{ jekyll.environment }}!"
|
Given I have a "index.html" page with layout "simple" that contains "Hi there, Jekyll {{ jekyll.environment }}!"
|
||||||
And I have a simple layout that contains "{{ content }}Ahoy, indeed!"
|
And I have a simple layout that contains "{{ content }}Ahoy, indeed!"
|
||||||
|
|
|
@ -24,6 +24,7 @@ end
|
||||||
After do
|
After do
|
||||||
FileUtils.rm_rf(TEST_DIR) if File.exist?(TEST_DIR)
|
FileUtils.rm_rf(TEST_DIR) if File.exist?(TEST_DIR)
|
||||||
FileUtils.rm(JEKYLL_COMMAND_OUTPUT_FILE) if File.exist?(JEKYLL_COMMAND_OUTPUT_FILE)
|
FileUtils.rm(JEKYLL_COMMAND_OUTPUT_FILE) if File.exist?(JEKYLL_COMMAND_OUTPUT_FILE)
|
||||||
|
FileUtils.rm(JEKYLL_COMMAND_STATUS_FILE) if File.exist?(JEKYLL_COMMAND_STATUS_FILE)
|
||||||
Dir.chdir(File.dirname(TEST_DIR))
|
Dir.chdir(File.dirname(TEST_DIR))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -227,3 +228,7 @@ end
|
||||||
Then /^I should see "(.*)" in the build output$/ do |text|
|
Then /^I should see "(.*)" in the build output$/ do |text|
|
||||||
assert_match Regexp.new(text), jekyll_run_output
|
assert_match Regexp.new(text), jekyll_run_output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Then /^I should get a non-zero exit(?:\-| )status$/ do
|
||||||
|
assert jekyll_run_status > 0
|
||||||
|
end
|
||||||
|
|
|
@ -16,6 +16,7 @@ JEKYLL_SOURCE_DIR = File.dirname(File.dirname(File.dirname(__FILE__)))
|
||||||
TEST_DIR = File.expand_path(File.join('..', '..', 'tmp', 'jekyll'), File.dirname(__FILE__))
|
TEST_DIR = File.expand_path(File.join('..', '..', 'tmp', 'jekyll'), File.dirname(__FILE__))
|
||||||
JEKYLL_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'jekyll'))
|
JEKYLL_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'jekyll'))
|
||||||
JEKYLL_COMMAND_OUTPUT_FILE = File.join(File.dirname(TEST_DIR), 'jekyll_output.txt')
|
JEKYLL_COMMAND_OUTPUT_FILE = File.join(File.dirname(TEST_DIR), 'jekyll_output.txt')
|
||||||
|
JEKYLL_COMMAND_STATUS_FILE = File.join(File.dirname(TEST_DIR), 'jekyll_status.txt')
|
||||||
|
|
||||||
def source_dir(*files)
|
def source_dir(*files)
|
||||||
File.join(TEST_DIR, *files)
|
File.join(TEST_DIR, *files)
|
||||||
|
@ -36,12 +37,20 @@ def jekyll_output_file
|
||||||
JEKYLL_COMMAND_OUTPUT_FILE
|
JEKYLL_COMMAND_OUTPUT_FILE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def jekyll_status_file
|
||||||
|
JEKYLL_COMMAND_STATUS_FILE
|
||||||
|
end
|
||||||
|
|
||||||
def jekyll_run_output
|
def jekyll_run_output
|
||||||
File.read(jekyll_output_file) if File.file?(jekyll_output_file)
|
File.read(jekyll_output_file) if File.file?(jekyll_output_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def jekyll_run_status
|
||||||
|
(File.read(jekyll_status_file) rescue 0).to_i
|
||||||
|
end
|
||||||
|
|
||||||
def run_bundle(args)
|
def run_bundle(args)
|
||||||
child = run_in_shell('bundle', *args.strip.split(' '))
|
run_in_shell('bundle', *args.strip.split(' '))
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_jekyll(args)
|
def run_jekyll(args)
|
||||||
|
@ -49,8 +58,21 @@ def run_jekyll(args)
|
||||||
child.status.exitstatus == 0
|
child.status.exitstatus == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# XXX: POSIX::Spawn::Child does not write output when the exit status is > 0
|
||||||
|
# for example when doing [:out, :err] => [file, "w"] it will skip
|
||||||
|
# writing the file entirely, we sould switch to Open.
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
def run_in_shell(*args)
|
def run_in_shell(*args)
|
||||||
POSIX::Spawn::Child.new *args, :out => [JEKYLL_COMMAND_OUTPUT_FILE, "w"]
|
spawned = POSIX::Spawn::Child.new(*args)
|
||||||
|
status = spawned.status.exitstatus
|
||||||
|
File.write(JEKYLL_COMMAND_STATUS_FILE, status)
|
||||||
|
File.open(JEKYLL_COMMAND_OUTPUT_FILE, "w+") do |file|
|
||||||
|
status == 0 ? file.write(spawned.out) : file.write(spawned.err)
|
||||||
|
end
|
||||||
|
|
||||||
|
spawned
|
||||||
end
|
end
|
||||||
|
|
||||||
def slug(title)
|
def slug(title)
|
||||||
|
|
|
@ -109,7 +109,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the converted content
|
# Returns the converted content
|
||||||
def render_liquid(content, payload, info, path)
|
def render_liquid(content, payload, info, path)
|
||||||
site.liquid_renderer.file(path).parse(content).render(payload, info)
|
site.liquid_renderer.file(path).parse(content).render!(payload, info)
|
||||||
rescue Tags::IncludeTagError => e
|
rescue Tags::IncludeTagError => e
|
||||||
Jekyll.logger.error "Liquid Exception:", "#{e.message} in #{e.path}, included in #{path || self.path}"
|
Jekyll.logger.error "Liquid Exception:", "#{e.message} in #{e.path}, included in #{path || self.path}"
|
||||||
raise e
|
raise e
|
||||||
|
|
Loading…
Reference in New Issue