Skip to content

Commit

Permalink
upgrade to 0.0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
taojy123 committed Feb 19, 2020
1 parent bc0499c commit 386f909
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ test.html

best.html
best_zh.html
best1.html
best2.html
best3.html
best4.html
best5.html

example.html

Expand Down
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,16 @@ doc.add_api(
)


# 第6步,使用 build 方法构建生成文档,最后产出 html 文件
# 第6步,添加文档结尾,markdown 格式
doc.ending = """
This is the end of document, **thankyou**!
"""


# 第7步,使用 build 方法构建生成文档,最后产出 html 文件
doc.build('best.html')


```


Expand All @@ -138,6 +145,9 @@ python demo.py
# 指定 language 为 zh,构建中文文档
doc.build('best_zh.html', language='zh')

# 自定义文档模版
doc.template = 'eave/template.html'
doc.build('best1.html')

# 将文档对象导出为 json
json_data = doc.to_json()
Expand All @@ -147,26 +157,22 @@ doc2 = Doc(json_data)
doc2.title = 'My Second Api Document'
doc2.build('best2.html')


# 将文档对象导出为 yaml
yaml_data = doc.to_yaml()

# 导入 yaml 创建文档对象
doc3 = Doc(yaml_data)
doc3.build('best3.html')


# 使用 raml 创建文档对象(不完全支持 raml)
from eave.utils import raml2eave
doc = raml2eave('example.raml')
doc.build('example.html', 'zh')


# 通过 from_md 参数,引入单独编写的 markdown 文件作为文档内容
# 在添加 api 时,也通过 from_md 参数,引入单独编写的 markdown 文件作为文档内容
doc.add_api(
title="获取订单列表接口",
uri="/orders/list/",
from_md="orders.md",
)

```
22 changes: 19 additions & 3 deletions best_practice.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@
)


# 第6步,使用 build 方法构建生成文档,最后产出 html 文件
# 第6步,添加文档结尾,markdown 格式
doc.ending = """
This is the end of document, **thankyou**!
"""


# 第7步,使用 build 方法构建生成文档,最后产出 html 文件
doc.build('best.html')


Expand All @@ -87,6 +93,11 @@
# 指定 language 为 zh,构建中文文档
doc.build('best_zh.html', language='zh')

# 自定义文档模版
import os
print(os.getcwd())
doc.template = 'eave/template.html'
doc.build('best1.html')

# 将文档对象导出为 json
json_data = doc.to_json()
Expand All @@ -96,17 +107,22 @@
doc2.title = 'My Second Api Document'
doc2.build('best2.html')


# 将文档对象导出为 yaml
yaml_data = doc.to_yaml()

# 导入 yaml 创建文档对象
doc3 = Doc(yaml_data)
doc3.build('best3.html')


# 使用 raml 创建文档对象(不完全支持 raml)
from eave.utils import raml2eave
doc = raml2eave('example.raml')
doc.build('example.html', 'zh')

# 在添加 api 时,也通过 from_md 参数,引入单独编写的 markdown 文件作为文档内容
doc.add_api(
title="获取订单列表接口",
uri="/orders/list/",
from_md="orders.md",
)

10 changes: 8 additions & 2 deletions eave/eave.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ class Doc(Base):
description = ''
notes = None
apis = None
ending = ''
template = ''

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.notes = self.notes or []
self.apis = self.apis or []

def build(self, target=None, language='en'):
# language: zh, en ...
template = open(os.path.join(BASE_DIR, 'template.html'), encoding='utf8').read()
# language: zh / en ...
if not self.template:
self.template = os.path.join(BASE_DIR, 'template.html')
template = open(self.template, encoding='utf8').read()
html = Template(template, strip=False).expand(
doc=self, markdown=mistune.markdown, resource=RESOURCE, language=language)
if target:
Expand All @@ -96,6 +100,7 @@ def load_data(self, data):
self.version = data.get('version', self.version)
self.host = data.get('host', self.host)
self.description = data.get('description', self.description)
self.ending = data.get('ending', self.ending)

notes = data.get('notes')
apis = data.get('apis')
Expand All @@ -114,6 +119,7 @@ def to_dict(self):
'description': self.description,
'notes': [n.to_dict() for n in self.notes],
'apis': [a.to_dict() for a in self.apis],
'ending': self.ending,
}


Expand Down
5 changes: 4 additions & 1 deletion eave/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ <h1 id="{{api.id}}">{{api.title}}</h1>

%endfor


%if doc.ending:
<p>{{markdown(doc.ending, escape=False)}}</p>
<hr>
%endif

</div>

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

setup(
name='eave',
version='0.0.13',
version='0.0.14',
description='A Restful Api Document Builder For Pythonista',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 386f909

Please sign in to comment.