Allow passing :strict_variables and :strict_filters options to Liquid's renderer (#6726)
Merge pull request 6726
This commit is contained in:
parent
86d86258a8
commit
51bdea1303
|
@ -684,7 +684,9 @@ verbose: false
|
|||
defaults: []
|
||||
|
||||
liquid:
|
||||
error_mode: warn
|
||||
error_mode: warn
|
||||
strict_filters: false
|
||||
strict_variables: false
|
||||
|
||||
# Markdown Processors
|
||||
rdiscount:
|
||||
|
@ -713,6 +715,14 @@ options are
|
|||
- `warn` --- Output a warning on the console for each error.
|
||||
- `strict` --- Output an error message and stop the build.
|
||||
|
||||
You can also configure Liquid's renderer to catch non-assigned variables and
|
||||
non-existing filters by setting `strict_variables` and / or `strict_filters`
|
||||
to `true` respectively. {% include docs_version_badge.html version="3.8.0" %}
|
||||
|
||||
Do note that while `error_mode` configures Liquid's parser, the `strict_variables`
|
||||
and `strict_filters` options configure Liquid's renderer and are consequently,
|
||||
mutually exclusive.
|
||||
|
||||
## Markdown Options
|
||||
|
||||
The various Markdown renderers supported by Jekyll sometimes have extra options
|
||||
|
|
|
@ -30,6 +30,50 @@ Feature: Rendering
|
|||
Then I should get a non-zero exit-status
|
||||
And I should see "Liquid Exception: Liquid error \(.+/_includes/invalid\.html line 1\): wrong number of arguments (\(given 1, expected 2\)|\(1 for 2\)) included in index\.html" in the build output
|
||||
|
||||
Scenario: Rendering a default site containing a file with rogue Liquid constructs
|
||||
Given I have a "index.html" page with title "Simple Test" that contains "{{ page.title | foobar }}\n\n{{ page.author }}"
|
||||
When I run jekyll build
|
||||
Then I should get a zero exit-status
|
||||
And I should not see "Liquid Exception:" in the build output
|
||||
|
||||
Scenario: Rendering a custom site containing a file with a non-existent Liquid variable
|
||||
Given I have a "index.html" file with content:
|
||||
"""
|
||||
---
|
||||
title: Simple Test
|
||||
---
|
||||
{{ page.title }}
|
||||
|
||||
{{ page.author }}
|
||||
"""
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
liquid:
|
||||
strict_variables: true
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then I should get a non-zero exit-status
|
||||
And I should see "Liquid error \(line 3\): undefined variable author in index.html" in the build output
|
||||
|
||||
Scenario: Rendering a custom site containing a file with a non-existent Liquid filter
|
||||
Given I have a "index.html" file with content:
|
||||
"""
|
||||
---
|
||||
author: John Doe
|
||||
---
|
||||
{{ page.title }}
|
||||
|
||||
{{ page.author | foobar }}
|
||||
"""
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
liquid:
|
||||
strict_filters: true
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then I should get a non-zero exit-status
|
||||
And I should see "Liquid error \(line 3\): undefined filter foobar in index.html" in the build output
|
||||
|
||||
Scenario: Render Liquid and place in layout
|
||||
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!"
|
||||
|
|
|
@ -61,7 +61,9 @@ module Jekyll
|
|||
"defaults" => [],
|
||||
|
||||
"liquid" => {
|
||||
"error_mode" => "warn",
|
||||
"error_mode" => "warn",
|
||||
"strict_filters" => false,
|
||||
"strict_variables" => false,
|
||||
},
|
||||
|
||||
"rdiscount" => {
|
||||
|
|
|
@ -68,8 +68,11 @@ module Jekyll
|
|||
# rubocop: disable AbcSize
|
||||
def render_document
|
||||
info = {
|
||||
:registers => { :site => site, :page => payload["page"] },
|
||||
:registers => { :site => site, :page => payload["page"] },
|
||||
:strict_filters => liquid_options["strict_filters"],
|
||||
:strict_variables => liquid_options["strict_variables"],
|
||||
}
|
||||
|
||||
output = document.content
|
||||
if document.render_with_liquid?
|
||||
Jekyll.logger.debug "Rendering Liquid:", document.relative_path
|
||||
|
@ -265,5 +268,10 @@ module Jekyll
|
|||
c.output_ext(document.extname)
|
||||
end.compact
|
||||
end
|
||||
|
||||
private
|
||||
def liquid_options
|
||||
@liquid_options ||= site.config["liquid"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue