从Yaml或JSON产生的HTML或XML

empugn的Python项目详细描述


empugn–从yaml或json生成html或xml

更多的是一个试验,而不是一个认真的尝试,使一个HTML模板引擎。但如果你打算使用它,你可能会发现它与Emrichen一起工作得很好。

empugn模板如下:

html:-head:-title:Empugn example-link:rel:stylesheethref:foo.css-script:|alert('Hello, World');-body:-h1:Sole text child may be specified as-is-p:-"Separatinglinksby"-a:href:https://google.comtarget:_blankchildren:space-"mayrequirequoting"

或使用emrichen:

!Defaultstitle:Empugn example with Emrichengreeting:Hello, Emrichen---html:-head:-title:!Vartitle-link:rel:stylesheethref:foo.css-script:!Format"alert({greeting!r});"-body:-h1:!Vartitle

安装

需要Python3.5+版本。python 2不受支持,也将不受支持。

可选依赖项:

安装empugn的推荐方法是

pip install empugn[emrichen]

普通的empugn只支持json。对于支持yaml但没有emrichen的empugn,请使用empugn[yaml]

cli

usage: empugn [-h] [--template-format {yaml,json}] [--output-file OUTPUT_FILE]
              [--indent INDENT] [--use-emrichen] [--var-file VAR_FILE]
              [--define VAR=VALUE] [--include-env]
              [template_file]

Generate HTML or XML from YAML or JSON

positional arguments:
  template_file         The YAML or JSON template to process. If unspecified,
                        the template is read from stdin.

optional arguments:
  -h, --help            show this help message and exit
  --template-format {yaml,json}
                        Template format. If unspecified, attempted to be
                        autodetected from the input filename (but defaults to
                        YAML).
  --output-file OUTPUT_FILE, -o OUTPUT_FILE
                        Output file. If unspecified, the HTML/XML output is
                        written into stdout.
  --indent INDENT, -i INDENT
                        Indent output. If integer, this many spaces will be
                        used. If string, will be used literally. To disable
                        indentation, pass in the empty string.
  --use-emrichen, -r    Use Emrichen to process tags, making Empugn a full
                        featured HTML template engine. Emrichen must be
                        installed.
  --var-file VAR_FILE, -f VAR_FILE
                        (Implies --use-emrichen) A YAML file containing an
                        object whose top-level keys will be defined as
                        variables. May be specified multiple times.
  --define VAR=VALUE, -D VAR=VALUE
                        (Implies --use-emrichen) Defines a single variable.
                        May be specified multiple times.
  --include-env, -e     (Implies --use-emrichen) Expose process environment
                        variables to the template.

python api

简单用法:

fromempugnimportempugn# In goes parsed JSON/YAML, out comes stringempugn({'html':[]})# -> '<html></html>'

与emrichen一起使用:

fromempugnimportempugnfromemrichenimportContext,Templatetemplate_yaml='…'template=Template.parse(template)# or Template(…)context=Context({'var':'value'})data,=Template.enrich(context)empugn(data)

为什么叫empugn?

empugn这个名字是emrichen,Pugimpugn的剧本。

许可证

The MIT License (MIT)

Copyright © 2018–2019 Santtu Pajukanta
Copyright © 2018–2019 Aarni Koskela

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

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

推荐PyPI第三方库


热门话题
java文件分块,获取长度字节   java嵌入式Tomcat不执行jsf页面   java我的数据库中有2个实体,但hibernate返回其中6个。   java如何基于逗号拆分字符串   java取消已经运行的CompletableFutures的预期模式是什么   java如何在informix中从另一个数据库复制表ddl和数据   为什么图片是黑色的?   java根据字符串数组中的单词筛选列表   Java8的集合。平行流有效吗?   Kotlin中的java静态内部类   java如何在GUI中生成一列字符串   javafx如何正确使用高对比度主题?   带空格的javascript Httpurlconnection参数   java如何设置GridBagLayout的约束   java如何在一个线程可能尚未初始化时关闭另一个线程   java将简单时间格式转换为特殊时间格式(hhmmt)   安卓/java阵列重复过滤器的问题   java在队列的链接实现下,入队和出队是如何工作的   java更新sql外键约束