-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: David Krause (enthus1ast) <[email protected]>
- Loading branch information
David Krause (enthus1ast)
committed
Sep 15, 2024
1 parent
d9b56f6
commit d9b7682
Showing
4 changed files
with
93 additions
and
11 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
header | ||
{% block title %}title to replace{% endblock %} | ||
{% block content %}content to replace{% endblock %} | ||
footer |
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,5 @@ | ||
{% extends fragments/base.nimja %} | ||
{% block title %}title from index{% endblock %} | ||
{% block content %}content from index{% endblock %} | ||
|
||
|
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,61 @@ | ||
discard """ | ||
joinable: false | ||
""" | ||
import ../../src/nimja | ||
import unittest | ||
|
||
suite "fragments": | ||
|
||
test "compileTemplateStr simple": | ||
proc foo(blockToRender: static string): string = | ||
compileTemplateStr(""" | ||
BUG | ||
{% block first %}first block{% endblock %} | ||
{% block second %}second block{% endblock %} | ||
BUG | ||
""", blockToRender = blockToRender) | ||
|
||
check "first block" == foo("first") | ||
check "second block" == foo("second") | ||
|
||
|
||
|
||
test "compileTemplateStr simple with self": | ||
proc foo(blockToRender: static string): string = | ||
compileTemplateStr(""" | ||
BUG | ||
{% block first %}first{{self.inner}}block{% endblock %} | ||
{% block second %}second{{self.inner}}block{% endblock %} | ||
{% block inner %} inner {% endblock %} | ||
BUG | ||
""", blockToRender = blockToRender) | ||
|
||
check "first inner block" == foo("first") | ||
check "second inner block" == foo("second") | ||
|
||
|
||
test "compileTemplateStr simple with var": | ||
proc foo(ii: int, blockToRender: static string): string = | ||
compileTemplateStr(""" | ||
BUG | ||
{% block first %}first{{self.inner}}block{% endblock %} | ||
{% block second %}second{{self.inner}}block{% endblock %} | ||
{% block inner %} {{ii}} {% endblock %} | ||
BUG | ||
""", blockToRender = blockToRender) | ||
|
||
check "first 1337 block" == foo(1337, "first") | ||
check "second 1337 block" == foo(1337, "second") | ||
|
||
|
||
|
||
|
||
test "compileTemplateFile simple": | ||
proc foo(fileToRender: static string, blockToRender: static string): string = | ||
compileTemplateFile(fileToRender, blockToRender = blockToRender, baseDir = getScriptDir()) | ||
check "title from index" == foo("fragments/index.nimja", "title") ## TODO test this error message! | ||
check "content from index" == foo("fragments/index.nimja", "content") ## TODO test this error message! | ||
|
||
check "title to replace" == foo("fragments/base.nimja", "title") ## TODO test this error message! | ||
check "content to replace" == foo("fragments/base.nimja", "content") ## TODO test this error message! | ||
|