本文整理汇总了Python中utils.rstcloth.rstcloth.RstCloth.role方法的典型用法代码示例。如果您正苦于以下问题:Python RstCloth.role方法的具体用法?Python RstCloth.role怎么用?Python RstCloth.role使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.rstcloth.rstcloth.RstCloth
的用法示例。
在下文中一共展示了RstCloth.role方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CustomTocTree
# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import role [as 别名]
#.........这里部分代码省略.........
if "ref-toc" in filename:
self._is_ref = True
else:
self._is_ref = False
self.table = None
self.contents = None
self.dfn = None
self.final = False
def build_table(self):
self.table = TableData()
self.table.add_header(['Name', 'Description'])
def build_dfn(self):
self.dfn = RstCloth()
self.dfn.directive('class', 'toc')
self.dfn.newline()
def build_contents(self):
self.contents = RstCloth()
self.contents.directive('class', 'hidden')
self.contents.newline()
self.contents.directive('toctree', fields=[('titlesonly', '')], indent=3)
self.contents.newline()
def _process_spec(self, spec, sort=False):
o = []
with open(spec, 'r') as f:
data = yaml.safe_load_all(f)
for datum in data:
if 'description' not in datum or datum['description'] is None:
datum['description'] = ''
if sort is False:
pass
elif 'name' not in datum:
sort = False
o.append(datum)
if sort is True:
o.sort(key=lambda o: o['name'])
return o
def finalize(self):
if not self.final:
for ref in self.spec:
if 'edition' in ref:
if 'edition' in self.conf.project:
if ref['edition'] != self.conf.project.edition:
continue
if self.table is not None:
if 'text' in ref:
if ref['name'] is None:
self.table.add_row( [ '', ref['text'] ] )
else:
self.table.add_row( [ ref['name'], ref['text'] ])
if 'name' in ref:
self.table.add_row([ ref['name'], ref['description'] ])
else:
self.table = None
if self.contents is not None and 'file' in ref:
if 'name' in ref and self._is_ref is False:
self.contents.content("{0} <{1}>".format(ref['name'], ref['file']), 6, wrap=False, block='toc')
else:
self.contents.content(ref['file'], 6, wrap=False, block='toc')
if self.dfn is not None:
if 'name' in ref:
text = ref['name']
else:
text = None
if 'level' in ref:
idnt = 3 * ref['level']
else:
idnt = 3
if 'class' in ref:
self.dfn.directive(name='class', arg=ref['class'], indent=idnt)
idnt += 3
if 'text' in ref:
if ref['name'] is None:
self.dfn.content(ref['text'], idnt)
else:
self.dfn.definition(ref['name'], ref['text'], indent=idnt, bold=False, wrap=False)
else:
link = self.dfn.role('doc', ref['file'], text)
self.dfn.definition(link, ref['description'], indent=idnt, bold=False, wrap=False)
self.dfn.newline()
示例2: build_page
# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import role [as 别名]
def build_page(data, conf):
fn = os.path.join(conf.paths.projectroot,
conf.paths.includes,
'metadata.yaml')
if not os.path.exists(fn):
return None
else:
iconf = BuildConfiguration(fn)
r = RstCloth()
r.title(iconf.title)
r.newline()
r.directive('default-domain', iconf.domain)
r.newline()
if 'introduction' in iconf:
r.content(iconf.introduction)
r.newline()
r.directive(name='contents', arg='Included Files',
fields=[ ('backlinks', 'none'),
('class', 'long-toc'),
('depth', 1),
('local', ''),
])
r.newline()
data = data.items()
data.sort()
for _, record in data:
page_name = r.pre(record['name'])
r.heading(text=page_name, char='-', indent=0)
r.newline()
r.heading('Meta', char='~', indent=0)
r.newline()
if record['num_clients'] == 0:
r.content('{0} is not included in any files.'.format(page_name))
r.newline()
add_content(r, record)
elif record['num_clients'] == 1:
if record['yaml_only']:
r.content('{0} is only included in yaml files.'.format(page_name))
r.newline()
else:
link = r.role('doc', record['clients'][0])
r.content('{0} is only included in {1}.'.format(page_name, link))
r.newline()
add_meta(r, page_name, record)
add_content(r, record)
else:
r.content('{0} is included in **{1}** files.'.format(page_name, record['num_clients']),
wrap=False)
r.newline()
add_meta(r, page_name, record)
if record['yaml_only'] is False:
clients = [ p for p in
record['clients']
if not p.startswith('/includes')
]
if len(clients) == 1:
client_link = r.role('doc', clients[0])
inc_str = '{0} is the only file that includes {1} that is not also an include.'
r.content(inc_str.format(client_link, page_name))
r.newline()
else:
r.heading('Client Pages', char='~', indent=0)
r.newline()
for pg in clients:
client_link = r.role('doc', pg)
r.li(client_link, wrap=False)
r.newline()
add_include_example(r, page_name, record['path'])
add_content(r, record)
return r
示例3: build_page
# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import role [as 别名]
def build_page(data, conf):
fn = os.path.join(conf.paths.projectroot, conf.paths.includes, "metadata.yaml")
if not os.path.exists(fn):
return None
else:
iconf = BuildConfiguration(fn)
r = RstCloth()
r.title(iconf.title)
r.newline()
r.directive("default-domain", iconf.domain)
r.newline()
if "introduction" in iconf:
r.content(iconf.introduction)
r.newline()
r.directive(
name="contents",
arg="Included Files",
fields=[("backlinks", "none"), ("class", "long-toc"), ("depth", 1), ("local", "")],
)
r.newline()
data = data.items()
data.sort()
for _, record in data:
page_name = r.pre(record["name"])
r.heading(text=page_name, char="-", indent=0)
r.newline()
r.heading("Meta", char="~", indent=0)
r.newline()
if record["num_clients"] == 0:
r.content("{0} is not included in any files.".format(page_name))
r.newline()
add_content(r, record)
elif record["num_clients"] == 1:
if record["yaml_only"]:
r.content("{0} is only included in yaml files.".format(page_name))
r.newline()
else:
link = r.role("doc", record["clients"][0])
r.content("{0} is only included in {1}.".format(page_name, link))
r.newline()
add_meta(r, page_name, record)
add_content(r, record)
else:
r.content("{0} is included in **{1}** files.".format(page_name, record["num_clients"]), wrap=False)
r.newline()
add_meta(r, page_name, record)
if record["yaml_only"] is False:
clients = [p for p in record["clients"] if not p.startswith("/includes")]
if len(clients) == 1:
client_link = r.role("doc", clients[0])
inc_str = "{0} is the only file that includes {1} that is not also an include."
r.content(inc_str.format(client_link, page_name))
r.newline()
else:
r.heading("Client Pages", char="~", indent=0)
r.newline()
for pg in clients:
client_link = r.role("doc", pg)
r.li(client_link, wrap=False)
r.newline()
add_include_example(r, page_name, record["path"])
add_content(r, record)
return r