template.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:docs 作者: hasura 项目源码 文件源码
def create_template_factory(app):
    class TemplateDefinition(Directive):
        has_content = True
        required_arguments = 1
        optional_arguments = 1
        final_argument_whitespace = True
        option_spec = {'yaml': directives.flag}

        def run(self):
            name = self.arguments[0]
            defined_in = self.state.document.current_source
            source_path = self.state.document.get('source')

            # Register this directive as existing in the current document.
            if not source_path in REGISTERED:
                REGISTERED[source_path] = set()

            if not name in REGISTERED[source_path]:
                template = '\n'.join(self.content)
                is_yaml = 'yaml' in self.options
                directive = create_directive(name, template, defined_in, is_yaml)
                app.add_directive(name, directive)

                REGISTERED[source_path].add(name)

            return []

    return TemplateDefinition
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号