Pure Python object oriented implementation of template language originally presented in drunk snail
- Easy syntax
- Separates logic and data
- Small codebase
- Secure by design
- Flexible object model
Row:
<tr>
<td><!-- (param)cell --></td>
</tr>
Table:
<table>
<!-- (ref)Row -->
</table>
Arguments:
{
"Row": [
{
"cell": [
"1",
"2"
]
},
{
"cell": [
"3",
"4"
]
}
]
}
Result:
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
pip install git+https://github.com/MentalBlood/ruiner
import ruiner
assert ruiner.Template(
'<table>\n'
' <!-- (ref)Row -->\n'
'</table>',
).rendered(
parameters = {
'Row': [
{'cell': ['1.1', '2.1', '3.1']},
{'cell': ['1.2', '2.2', '3.2']},
{'cell': ['1.3', '2.3', '3.3']}
]
},
templates = {
'Row': ruiner.Template(
'<tr>\n'
' <td><!-- (param)cell --></td>\n'
'</tr>'
)
}
) == (
'<table>\n'
' <tr>\n'
' <td>1.1</td>\n'
' <td>2.1</td>\n'
' <td>3.1</td>\n'
' </tr>\n'
' <tr>\n'
' <td>1.2</td>\n'
' <td>2.2</td>\n'
' <td>3.2</td>\n'
' </tr>\n'
' <tr>\n'
' <td>1.3</td>\n'
' <td>2.3</td>\n'
' <td>3.3</td>\n'
' </tr>\n'
'</table>'
)
Using pytest and pytest-benchmark:
pip install --upgrade git+https://codeberg.com/mentalblood/ruiner
git clone https://codeber.org/mentalblood/ruiner
cd ruiner
pytest