一种简单但功能强大的文本插值模板语言,灵感来自SAS宏。

sassylang的Python项目详细描述


时髦

一种简单但功能强大的文本插值模板语言,灵感来自SAS宏。

工作原理

sassy是一个解释输入宏标记的命令行程序。

%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: &param1.
%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);

在上述文本文件上运行sassy将输出以下内容…

$ 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

嵌套变量解析

%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&param1..
%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);

在上述文本文件上运行sassy将输出以下内容…

$ 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

循环

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;

在上述文本文件上运行sassy将输出以下内容…

$ 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

安装

以下是安装Sassy所需的操作:

Python3.6

sassy与python 3.6及更高版本兼容。

在unix系统上,通过包管理器(apt、rpm、yum、brew)安装python 3.6(或更高版本)。 或者,可以从official Python downloads page下载安装包。

虚拟环境

建议将所有项目依赖项放入其自己的虚拟 环境-这样我们就不会污染全局python安装。 为此,我们建议您使用virtualenvwrapper。按照说明操作 here 来安装这个。安装virtualenvwrapper后,创建 一个新的虚拟环境:

mkvirtualenv sassy
workon sassy

现在让我们安装sassy:

pip install sassylang

获得帮助或给予帮助

  • 打开一个新的 issue如果 你遇到了一个问题。
  • 欢迎拉取请求。你可以帮助语言功能!

许可证

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Intellij通过方法中的包查找用法   java中VS代码和打包命名的问题   将java CMS功能集成到具有高度动态内容的网站(Lucene/Mysql/Nosql)的策略   oracle的java类强制转换异常。jdbc。驾驶员OracleConnection   字节码向JVM添加上指令   如何在抽象类中执行java方法?   java是否可以在apache访问日志中排除指定的GET参数?(作者:W7开发环境)   java如何获取已安装音频播放器的列表?   尝试向HS学生展示如何使用Java访问MS数据库   使用正则表达式java对给定行中的特定字符串进行计数   java JOOQ Select查询中的Select计数   方法Java,如何从二维双精度数组中找到特定值?   获取图像URL的java正则表达式   java在切换到新的窗口驱动程序后找不到元素