-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ccpgames/feature/meta-tag-to-cancel-rendering
Feature/meta tag to cancel rendering
- Loading branch information
Showing
16 changed files
with
144 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
__version__ = '0.3.0' | ||
__version__ = '0.4.0' | ||
|
||
__author__ = 'Thordur Matthiasson <[email protected]>' | ||
__license__ = 'MIT License' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from ._embed import * | ||
from ._skip_if import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
__all__ = [ | ||
'SkipIfExtension', | ||
] | ||
from jinja2 import nodes | ||
from jinja2.ext import Extension | ||
from ccpstencil.structs import * | ||
|
||
|
||
class SkipIfExtension(Extension): | ||
tags = {'skip_if'} | ||
|
||
def parse(self, parser): | ||
lineno = next(parser.stream).lineno | ||
# Parse the condition expression | ||
condition = parser.parse_expression() | ||
return nodes.CallBlock(self.call_method('_check_condition', [condition]), [], [], []).set_lineno(lineno) | ||
|
||
def _check_condition(self, condition, caller): | ||
if condition: | ||
raise CancelRendering("Rendering cancelled due to meta_only_render_if condition being False") | ||
return '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
mode: | ||
normal: | ||
adjective: Now | ||
positive: | ||
enabled: true | ||
adjective: Shiny | ||
negative: | ||
enabled: false | ||
adjective: Shitty | ||
number: 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{% skip_if not mode.negative.enabled %} | ||
The day is {{mode.negative.adjective}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The day is {{mode.normal.adjective}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{% skip_if not mode.positive.enabled %} | ||
The day is {{mode.positive.adjective}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{% skip_if number == 7 %} | ||
Seven! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{% skip_if number == 6 %} | ||
Six! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import unittest | ||
|
||
from ccpstencil.stencils import * | ||
|
||
import os | ||
import pathlib | ||
|
||
import logging | ||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
|
||
_HERE = pathlib.Path(__file__).parent.resolve() | ||
|
||
|
||
def fp(file_name: str) -> str: | ||
return str((_HERE / 'res/skipif/' / file_name).absolute()) | ||
|
||
|
||
class TestSkipIf(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
os.environ['STENCIL_TEMPLATE_PATH'] = str(_HERE / 'res/skipif/') | ||
|
||
def test_normal(self): | ||
res = render_stencil('template_normal.txt', fp('context.yaml')) | ||
self.assertEqual('The day is Now', res) | ||
|
||
def test_skipped(self): | ||
res = render_stencil('template_negative.txt', fp('context.yaml')) | ||
self.assertIsNone(res) | ||
|
||
def test_not_skipped(self): | ||
res = render_stencil('template_positive.txt', fp('context.yaml')) | ||
self.assertEqual('The day is Shiny', res) | ||
|
||
def test_numbers(self): | ||
# res = render_stencil('template_six.txt', fp('context.yaml')) | ||
# self.assertEqual('Six!', res) | ||
res = render_stencil('template_seven.txt', fp('context.yaml')) | ||
self.assertIsNone(res) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
if 'STENCIL_TEMPLATE_PATH' in os.environ: | ||
del os.environ['STENCIL_TEMPLATE_PATH'] |