=====================
document-template
=====================
Python解析文档模版
=====================
.. image:: https://img.shields.io/pypi/v/document-template.svg
:target: https://pypi.org/project/document-template/
.. image:: https://img.shields.io/pypi/pyversions/document-template.svg
:target: https://pypi.org/project/document-template/
.. image:: https://img.shields.io/pypi/l/document-template.svg
:target: https://github.com/liying2008/document-template
.. image:: https://img.shields.io/pypi/wheel/document-template.svg
:target: https://pypi.org/project/document-template/#files
安装方法
---------
使用 **pip** 安装
::
pip install document-template
使用方法
---------
参考 test.py_ 和 test.html_ :
.. _test.py: https://github.com/liying2008/document-template/blob/master/test.py
.. _test.html: https://github.com/liying2008/document-template/blob/master/test.html
:test.html:
.. code-block:: html
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>#{title}</title>
</head>
<body>
<h1>#{head}</h1>
<a href="#{url}">#{url}</a>
<br>
<h1>网站标题</h1>
<hr>
<span style="font-size: larger;font-weight: bold">#{large_font}</span>
<br>
show_span 为真时显示:
#{bool:show_span}<span>show_span is True</span>#{bool:show_span}
show_span 为假时显示:
#{bool:!show_span}<span>show_span is False</span>#{bool:!show_span}
<br>
#{copy:start}渲染多行文本,并替换局部内容:#{contents} 和 #{another_contents}<br>
#{copy:end}
</body>
</html>
:test.py:
.. code-block:: python
import sys
from document_template import DocumentTemplate
__author__ = 'liying'
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf-8')
if __name__ == '__main__':
id_dict = {"title": "标题", "head": "正文标题", "url": "https://github.com/liying2008", "large_font": "大号字体"}
id_dict['show_span'] = True
# Multi-line copy supports string, list and tuple
# id_dict['contents'] = 'ABCDEFG'
# id_dict['another_contents'] = '1234567'
id_dict['contents'] = ('A', 'B', 'C', 'D', 'E', 'F', 'G')
id_dict['another_contents'] = ['1', '2', '3', '4', '5', '6', '7']
dt = DocumentTemplate()
dt.load("test.html", encoding='utf-8')
dt.set_identifier_dict(id_dict)
dt.save_document("new_test.html")
指令说明
---------
- **普通变量**:#{var} 定义普通模板变量;
- **bool指令**:#{bool:var}text#{bool:var} 通过变量 var 是否为 True 控制 text 是否显示,或者 #{bool:!var}text#{bool:!var} 通过变量 var 是否为 False 控制 text 是否显示;
- **copy指令**:#{copy:start}text#{collection_var}#{copy:end} 循环遍历 collection_var ,将其值填充到内容中。
注意事项
---------
- 不支持 **copy 指令** 内使用 **copy 指令** 或 **bool 指令** 。
LICENSE
---------
`MIT License <https://github.com/liying2008/document-template/blob/master/LICENSE>`_
Raw data
{
"_id": null,
"home_page": "https://github.com/liying2008/document-template",
"name": "document-template",
"maintainer": "liying",
"docs_url": null,
"requires_python": "",
"maintainer_email": "liruoer2008@yeah.net",
"keywords": "template document parser",
"author": "liying",
"author_email": "liruoer2008@yeah.net",
"download_url": "https://files.pythonhosted.org/packages/d8/33/56aa6c63a7912b8750f9a0db2a71e4c5b64288046596bbd43b611a4283a4/document-template-1.1.0.tar.gz",
"platform": null,
"description": "=====================\r\ndocument-template\r\n=====================\r\n\r\nPython\u89e3\u6790\u6587\u6863\u6a21\u7248\r\n=====================\r\n \r\n.. image:: https://img.shields.io/pypi/v/document-template.svg\r\n :target: https://pypi.org/project/document-template/\r\n.. image:: https://img.shields.io/pypi/pyversions/document-template.svg\r\n :target: https://pypi.org/project/document-template/\r\n.. image:: https://img.shields.io/pypi/l/document-template.svg\r\n :target: https://github.com/liying2008/document-template\r\n.. image:: https://img.shields.io/pypi/wheel/document-template.svg\r\n :target: https://pypi.org/project/document-template/#files\r\n\r\n\r\n\u5b89\u88c5\u65b9\u6cd5\r\n---------\r\n\u4f7f\u7528 **pip** \u5b89\u88c5\r\n::\r\n\r\n pip install document-template\r\n\r\n\u4f7f\u7528\u65b9\u6cd5\r\n---------\r\n\u53c2\u8003 test.py_ \u548c test.html_ :\r\n\r\n.. _test.py: https://github.com/liying2008/document-template/blob/master/test.py\r\n.. _test.html: https://github.com/liying2008/document-template/blob/master/test.html\r\n\r\n:test.html:\r\n\r\n.. code-block:: html\r\n\r\n <html>\r\n <head>\r\n <meta charset=\"UTF-8\">\r\n <meta name=\"viewport\"\r\n content=\"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0\">\r\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\r\n <title>#{title}</title>\r\n </head>\r\n <body>\r\n <h1>#{head}</h1>\r\n <a href=\"#{url}\">#{url}</a>\r\n <br>\r\n <h1>\u7f51\u7ad9\u6807\u9898</h1>\r\n <hr>\r\n <span style=\"font-size: larger;font-weight: bold\">#{large_font}</span>\r\n <br>\r\n show_span \u4e3a\u771f\u65f6\u663e\u793a:\r\n #{bool:show_span}<span>show_span is True</span>#{bool:show_span}\r\n show_span \u4e3a\u5047\u65f6\u663e\u793a:\r\n #{bool:!show_span}<span>show_span is False</span>#{bool:!show_span}\r\n <br>\r\n #{copy:start}\u6e32\u67d3\u591a\u884c\u6587\u672c\uff0c\u5e76\u66ff\u6362\u5c40\u90e8\u5185\u5bb9\uff1a#{contents} \u548c #{another_contents}<br>\r\n #{copy:end}\r\n </body>\r\n </html>\r\n\r\n:test.py:\r\n\r\n.. code-block:: python\r\n\r\n import sys\r\n\r\n from document_template import DocumentTemplate\r\n\r\n __author__ = 'liying'\r\n\r\n if sys.version_info < (3, 0):\r\n reload(sys)\r\n sys.setdefaultencoding('utf-8')\r\n\r\n if __name__ == '__main__':\r\n id_dict = {\"title\": \"\u6807\u9898\", \"head\": \"\u6b63\u6587\u6807\u9898\", \"url\": \"https://github.com/liying2008\", \"large_font\": \"\u5927\u53f7\u5b57\u4f53\"}\r\n id_dict['show_span'] = True\r\n\r\n # Multi-line copy supports string, list and tuple\r\n # id_dict['contents'] = 'ABCDEFG'\r\n # id_dict['another_contents'] = '1234567'\r\n id_dict['contents'] = ('A', 'B', 'C', 'D', 'E', 'F', 'G')\r\n id_dict['another_contents'] = ['1', '2', '3', '4', '5', '6', '7']\r\n dt = DocumentTemplate()\r\n dt.load(\"test.html\", encoding='utf-8')\r\n dt.set_identifier_dict(id_dict)\r\n dt.save_document(\"new_test.html\")\r\n\r\n\r\n\u6307\u4ee4\u8bf4\u660e\r\n---------\r\n- **\u666e\u901a\u53d8\u91cf**\uff1a#{var} \u5b9a\u4e49\u666e\u901a\u6a21\u677f\u53d8\u91cf\uff1b\r\n- **bool\u6307\u4ee4**\uff1a#{bool:var}text#{bool:var} \u901a\u8fc7\u53d8\u91cf var \u662f\u5426\u4e3a True \u63a7\u5236 text \u662f\u5426\u663e\u793a\uff0c\u6216\u8005 #{bool:!var}text#{bool:!var} \u901a\u8fc7\u53d8\u91cf var \u662f\u5426\u4e3a False \u63a7\u5236 text \u662f\u5426\u663e\u793a\uff1b\r\n- **copy\u6307\u4ee4**\uff1a#{copy:start}text#{collection_var}#{copy:end} \u5faa\u73af\u904d\u5386 collection_var \uff0c\u5c06\u5176\u503c\u586b\u5145\u5230\u5185\u5bb9\u4e2d\u3002\r\n\r\n\r\n\u6ce8\u610f\u4e8b\u9879\r\n---------\r\n- \u4e0d\u652f\u6301 **copy \u6307\u4ee4** \u5185\u4f7f\u7528 **copy \u6307\u4ee4** \u6216 **bool \u6307\u4ee4** \u3002\r\n\r\n\r\nLICENSE\r\n---------\r\n`MIT License <https://github.com/liying2008/document-template/blob/master/LICENSE>`_\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Generate documents from templates.",
"version": "1.1.0",
"split_keywords": [
"template",
"document",
"parser"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8a7ec0d50788e2c10c7fe85053bb7269b490a455605880c165ac2e723c63a5c5",
"md5": "2f847a249c2355d6bf8237560cd2fc54",
"sha256": "847bb699812903880cf00a80d621467f31e602198daa016fd655ec635e346686"
},
"downloads": -1,
"filename": "document_template-1.1.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "2f847a249c2355d6bf8237560cd2fc54",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 6919,
"upload_time": "2023-01-07T16:39:00",
"upload_time_iso_8601": "2023-01-07T16:39:00.147554Z",
"url": "https://files.pythonhosted.org/packages/8a/7e/c0d50788e2c10c7fe85053bb7269b490a455605880c165ac2e723c63a5c5/document_template-1.1.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d83356aa6c63a7912b8750f9a0db2a71e4c5b64288046596bbd43b611a4283a4",
"md5": "69ef782bb822581753c17ac2503c972f",
"sha256": "7a79dfc958bf3833b7d852ffa302fc7ec4e9b9bf1fc74a273cad2cc4dbffa9c6"
},
"downloads": -1,
"filename": "document-template-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "69ef782bb822581753c17ac2503c972f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7522,
"upload_time": "2023-01-07T16:39:02",
"upload_time_iso_8601": "2023-01-07T16:39:02.010769Z",
"url": "https://files.pythonhosted.org/packages/d8/33/56aa6c63a7912b8750f9a0db2a71e4c5b64288046596bbd43b611a4283a4/document-template-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-07 16:39:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "liying2008",
"github_project": "document-template",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "document-template"
}