A simple but powerful templating language for text interpolation inspired by sas macros.
Project description
sassy
A simple but powerful templating language for text interpolation inspired by sas macros.
How it works
Sassy is a command-line program that interprets input macro tags.
Macros
%let var1 = some value; %let var2 = some other value; %macro testMacro(param1); this text will show whenever the macro is called. variables can be referenced like this: &var1. we can reference macro parameters just like variables: ¶m1. %mend; here's how you call a macro: %exec testMacro(1); here's a call to the same macro with a different parameter: %exec testMacro(2);
Running sassy on the above text file will output the following…
$ sassy test.txt here's how you call a macro: this text will show whenever the macro is called. variables can be referenced like this: somevalue we can reference macro parameters just like variables: 1 here's a call to the same macro with a different parameter: this text will show whenever the macro is called. variables can be referenced like this: somevalue we can reference macro parameters just like variables: 2
Nested variable resolution
%let var1 = some value; %let var2 = some other value; %let varNum = 1; %macro testMacro(param1); variables can be nested to form references to other variables: &var&varNum.. ...and also nest parameters as with variables: &var¶m1.. %mend; here's how you call a macro: %exec testMacro(1); here's a call to the same macro with a different parameter: %exec testMacro(2);
Running sassy on the above text file will output the following…
$ sassy test.txt here's how you call a macro: variables can be nested to form references to other variables: somevalue ...and also nest parameters as with variables: somevalue here's a call to the same macro with a different parameter: variables can be nested to form references to other variables: somevalue ...and also nest parameters as with variables: someothervalue
Loops
this is how you execute a loop: %procloop (3) loopCounter; this loop will execute &loopCounter. times. %pend; ...you can also use a variable to set the number of iterations: %let loopVar0 = first loop; %let loopVar1 = second loop; %let loopVar2 = third loop; %let loopVar3 = fourth loop; %let numLoops = 4; %procloop (&numLoops.) counterVar; this other loop will execute &counterVar. times, and references a different variable each time: &loopVar&counterVar.. %pend;
Running sassy on the above text file will output the following…
$ sassy test.txt this is how you execute a loop: this loop will execute 0 times. this loop will execute 1 times. this loop will execute 2 times. ...you can also use a variable to set the number of iterations: this other loop will execute 0 times, and references a different variable each time: firstloop this other loop will execute 1 times, and references a different variable each time: secondloop this other loop will execute 2 times, and references a different variable each time: thirdloop this other loop will execute 3 times, and references a different variable each time: fourthloop
Installation
Here’s what you need to do to install sassy:
Python 3.6
Sassy is compatible with Python 3.6 and later.
On Unix systems, install Python 3.6 (or later) via your package manager (apt, rpm, yum, brew). Alternatively, you can download an installation package from the official Python downloads page.
Virtual Environment
It is recommended to put all project dependencies into its own virtual environment - this way we don’t pollute the global Python installation. For this we recommend you use virtualenvwrapper. Follow the instructions here to get this installed. Once you have virtualenvwrapper install, create a new virtual environment with:
mkvirtualenv sassy workon sassy
Now let’s install sassy:
pip install sassylang
Get help or give help
Open a new issue if you encounter a problem.
Pull requests welcome. You can help with language features!
License
sassy is Free Software and licensed under the GPLv3.
Main author is @jmsmistral
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sassylang-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7678b876f3ec75e0becf82e1f9f30c631d9d073d8f97f68660b39f5748b8fa3 |
|
MD5 | 9a482701e878b5df6ea4a73277b64255 |
|
BLAKE2b-256 | 9751eee7140c42d4a9cc9cb41414ee5ee7d2f3115f785cc52a5d447925a45d78 |