Skip to content

MentalBlood/ruiner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔫 ruiner

safe and clean template engine

Lint Status Typing Status Complexity Status Tests Status Coverage Status Code style: black Python version: >=3.7

Pure Python object oriented implementation of template language originally presented in drunk snail

Why this language?

  • Easy syntax
  • Separates logic and data

Why better then drunk snail?

  • Small codebase
  • Secure by design
  • Flexible object model

Example

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>

Installation

pip install git+https://github.com/MentalBlood/ruiner

Usage

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>'
)

Testing/Benchmarking

Using pytest and pytest-benchmark:

pip install --upgrade git+https://github.com/MentalBlood/ruiner
git clone https://github.com/MentalBlood/ruiner
cd ruiner
pytest

About

Safe and clean template engine

Resources

License

Stars

Watchers

Forks

Languages