当前位置: 首页>>代码示例>>Python>>正文


Python RstCloth.content方法代码示例

本文整理汇总了Python中utils.rstcloth.rstcloth.RstCloth.content方法的典型用法代码示例。如果您正苦于以下问题:Python RstCloth.content方法的具体用法?Python RstCloth.content怎么用?Python RstCloth.content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.rstcloth.rstcloth.RstCloth的用法示例。


在下文中一共展示了RstCloth.content方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render_step_file

# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import content [as 别名]
def render_step_file(input_fn, output_fn=None, conf=None):
    input_fn_base = os.path.basename(input_fn)
    logger.debug('generating step file for {0}'.format(input_fn_base))
    steps = Steps(input_fn)
    logger.debug('resolved step file input for {0}'.format(input_fn_base))

    r = RstCloth()

    web_output = WebStepsOutput(steps, conf=conf)
    web_output.render()
    r.content(web_output.rst.data, indent=0, wrap=False)
    logger.debug('generated web output for {0}'.format(input_fn_base))

    r.directive('only', 'latex')
    r.newline()
    print_output = PrintStepsOutput(steps, conf=conf)
    print_output.render()
    r.content(print_output.rst.data, indent=3, wrap=False)
    logger.debug('generated print output for {0}'.format(input_fn_base))

    if output_fn is None:
        output_fn = os.path.splitext(input_fn)[0] + '.rst'

    r.write(output_fn)
    logger.debug('wrote step include at {0}'.format(output_fn))
开发者ID:MarkTseng,项目名称:docs-tools,代码行数:27,代码来源:steps.py

示例2: generate_release_untar

# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import content [as 别名]
def generate_release_untar(builder, release):
    r = RstCloth()

    r.directive('code-block', 'sh', block='header')
    r.newline(block='header')

    r.content('tar -zxvf mongodb-{0}-{1}.tgz'.format(builder, release), 3, wrap=False, block='cmd')

    return r
开发者ID:RandomStuffs22,项目名称:docs-tools,代码行数:11,代码来源:releases.py

示例3: render_page

# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import content [as 别名]
def render_page(doc, conf): 
    r = RstCloth()
    out_fn = os.path.join(conf.paths.projectroot, conf.paths.source, doc.system_name + '.txt')

    r.title(doc.system_title)
    r.newline()
    r.content(doc.system_description)
    r.newline()

    r.write(out_fn)
开发者ID:sverch,项目名称:module_data,代码行数:12,代码来源:module_data.py

示例4: generate_release_copy

# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import content [as 别名]
def generate_release_copy(builder, release):
    r = RstCloth()

    r.directive('code-block', 'sh', block='header')
    r.newline(block='header')

    r.content('mkdir -p mongodb', 3, wrap=False, block='cmd')
    r.content('cp -R -n mongodb-{0}-{1}/ mongodb'.format(builder, release), 3, wrap=False, block='cmd')

    return r
开发者ID:RandomStuffs22,项目名称:docs-tools,代码行数:12,代码来源:releases.py

示例5: generate_params

# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import content [as 别名]
def generate_params(params, fn, conf):
    r = RstCloth()
    basename = os.path.basename(fn)

    params.sort(key=lambda p: p['position'])

    # Begin by generating the table for web output
    r.directive('only', '(html or singlehtml or dirhtml)', block='htm')
    r.newline(block='htm')

    # { filename: { $name: <param> } }
    ext_params = {}

    processed_params = []
    for param in params:
        if 'file' in param:
            pos = param['position']
            if param['file'] not in ext_params:

                fn, ext = populate_external_param(param['file'],
                                                  basename,
                                                  conf.paths.projectroot,
                                                  conf.paths.source)
                ext_params[fn] = ext

            param = ext_params[conf.paths.source + param['file']][param['name']]
            param['position'] = pos

        processed_params.append(param)

    r.content(generate_param_table(processed_params), indent=3, block='html')
    r.newline(block='htm')

    # Then generate old-style param fields for non-web output
    r.directive('only', '(texinfo or latex or epub)', block='tex')
    r.newline(block='tex')

    for param in processed_params:
        key, val = generate_param_fields(param)
        r.field(name=key, value=val, indent=3, wrap=False, block='tex')
        r.newline(block='tex')

    return r
开发者ID:MarkTseng,项目名称:docs-tools,代码行数:45,代码来源:param.py

示例6: render_step_file

# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import content [as 别名]
def render_step_file(input_fn, output_fn=None):
    steps = Steps(input_fn)
    r = RstCloth()

    web_output = WebStepsOutput(steps)
    web_output.render()
    r.content(web_output.rst.get_block(), indent=0, wrap=False)

    r.directive('only', 'latex')
    r.newline()
    print_output = PrintStepsOutput(steps)
    print_output.render()
    r.content(print_output.rst.get_block(), indent=3, wrap=False)

    if output_fn is None:
        output_fn = os.path.splitext(input_fn)[0] + '.rst'

    r.write(output_fn)
    print('[steps]: rendered step include at ' + output_fn)
开发者ID:TylerBrock,项目名称:docs-tools,代码行数:21,代码来源:steps.py

示例7: generate_release_output

# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import content [as 别名]
def generate_release_output(builder, platform, architecture, release):
    """ This is the contemporary version of the function used by the generate.py script"""

    r = RstCloth()

    r.directive('code-block', 'sh', block='header')
    r.newline(block='header')

    if architecture == 'core':
        r.content('curl -O http://downloads.mongodb.org/{0}/mongodb-{1}-{2}.tgz'.format(platform, builder, release), 3, wrap=False, block='cmd')
    else:
        r.content('curl -O http://downloads.10gen.com/linux/mongodb-{0}-subscription-{1}-{2}.tgz'.format(builder, architecture, release), 3, wrap=False, block='cmd')
        r.content('tar -zxvf mongodb-{0}-subscription-{1}-{2}.tgz'.format(builder, architecture, release), 3, wrap=False, block='cmd')
        r.content('cp -R -n mongodb-{0}-subscription-{1}-{2}/ mongodb'.format(builder, architecture, release), 3, wrap=False, block='cmd')

    r.newline(block='footer')

    return r
开发者ID:RandomStuffs22,项目名称:docs-tools,代码行数:20,代码来源:releases.py

示例8: generate_output

# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import content [as 别名]
def generate_output(builder, platform, version, release):
    """ This is the legacy version of the function used by the makefile and CLI infrastructure"""

    r = RstCloth()

    r.directive('code-block', 'sh', block='header')
    r.newline(block='header')

    if release == 'core':
        r.content('curl -O http://downloads.mongodb.org/{0}/mongodb-{1}-{2}.tgz'.format(platform, builder, version), 3, wrap=False, block='cmd')
    else:
        r.content('curl -O http://downloads.10gen.com/linux/mongodb-{0}-subscription-{1}-{2}.tgz'.format(builder, release, version), 3, wrap=False, block='cmd')
        r.content('tar -zxvf mongodb-{0}-subscription-{1}-{2}.tgz'.format(builder, release, version), 3, wrap=False, block='cmd')
        r.content('cp -R -n mongodb-{0}-subscription-{1}-{2}/ mongodb'.format(builder, release, version), 3, wrap=False, block='cmd')

    r.newline(block='footer')

    return r
开发者ID:RandomStuffs22,项目名称:docs-tools,代码行数:20,代码来源:releases.py

示例9: StepsOutput

# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import content [as 别名]
class StepsOutput(object):
    """
    Base class for rendered step form. The render() method generates the rst in
    the internal RstCloth object.
    """

    def __init__(self, steps, conf=None):
        if not isinstance(steps, Steps):
            raise TypeError
        else:
            self.steps = steps

        self.conf = lazy_conf(conf)
        self.current_step = 1
        self.rst = RstCloth()
        self.hook()

    def hook(self):
        self.indent = 3

    def edition_check(self, step):
        if 'edition' in step:
            if 'edition' in self.conf.project:
                if step['edition'] != self.conf.project.edition:
                    return False
        else:
            return True

    @staticmethod
    def annotate_optional(step):
        if 'optional' in step and step['optional'] is True:
            if isinstance(step['title'], dict):
                step['title']['text'] = 'Optional. ' + step['title']['text']
            else:
                if 'title' in step:
                    step['title'] = 'Optional. ' + step['title']
                elif 'heading' in step:
                    step['heading'] = 'Optional. ' + step['heading']

            del step['optional']
            return step
        else:
            return step

    def render(self):
        for step in self.steps.source_list:
            if self.edition_check(step) is False:
                continue

            step = self.annotate_optional(step)
            self.heading(step)
            self.pre(step)

            self.current_step = step['stepnum']

            if 'action' in step:
                if isinstance(step['action'], list):
                    for block in step['action']:
                        self.code_step(block)
                else:
                    self.code_step(step['action'])

            self.content(step)

            self.post(step)

    def content(self, doc):
        if 'content' in doc and doc['content'] is not None:
            self.rst.content(doc['content'], wrap=False, indent=self.indent)
            self.rst.newline()

    def pre(self, doc):
        if 'pre' in doc and doc['pre'] is not None:
            self.rst.content(doc['pre'], wrap=False, indent=self.indent)
            self.rst.newline()

    def post(self, doc, code_step=False):
        if 'post' in doc and doc['post'] is not None:
            self.rst.content(doc['post'], wrap=False, indent=self.indent)
            self.rst.newline()

        if code_step is False:
            self.post_step_hook()

    def post_step_hook(self):
        pass

    def _heading(self, block, override_char=None, indent=0):
        if 'heading' in block:
            if isinstance(block['heading'], dict):
                if 'character' in block['heading']:
                    pass
                else:
                    block['heading']['character'] = override_char
            else:
                block['heading'] = { 'text': block['heading'],
                                     'character': override_char }

            if block['heading']['text'] is None:
                logger.error('step in "{0}" is missing a heading'.format(os.path.basename(self.steps.source_fn)))
#.........这里部分代码省略.........
开发者ID:MarkTseng,项目名称:docs-tools,代码行数:103,代码来源:steps.py

示例10: build_page

# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import content [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
开发者ID:MarkTseng,项目名称:docs-tools,代码行数:93,代码来源:includes.py

示例11: CustomTocTree

# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import content [as 别名]
class CustomTocTree(object):
    def __init__(self, filename, conf=None, sort=False):
        self.spec = self._process_spec(filename, sort)

        self.conf = lazy_conf(conf)

        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)
#.........这里部分代码省略.........
开发者ID:TylerBrock,项目名称:docs-tools,代码行数:103,代码来源:toc.py

示例12: OptionRendered

# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import content [as 别名]
class OptionRendered(object):
    def __init__(self, option):
        if not isinstance(option, Option):
            raise TypeError
        else:
            self.option = option

        self.rst = RstCloth()

    def resolve_option_name(self):
        if self.option.directive == "option":
            if self.option.name.startswith("<"):
                prefix = ""
            else:
                prefix = "--"

            if hasattr(self.option, "aliases"):
                if hasattr(self.option, "arguments"):
                    return "{0}{1} {2}, {3}".format(
                        prefix,
                        self.option.name,
                        self.option.arguments,
                        "{0}, ".format(self.option.arguments).join(self.option.aliases),
                    )
                else:
                    return "{0}{1}, {2}".format(prefix, self.option.name, ", ".join(self.option.aliases))

            else:
                if hasattr(self.option, "arguments"):
                    return "{0}{1} {2}".format(prefix, self.option.name, self.option.arguments)
                else:
                    return "{0}{1}".format(prefix, self.option.name)
        else:
            return self.option.name

    def resolve_output_path(self, path):
        name_parts = self.option.name.split(",")

        if len(name_parts) > 1:
            clensed_name = name_parts[0]
        else:
            clensed_name = self.option.name

        fn = "-".join([self.option.directive, self.option.program, clensed_name]) + ".rst"
        return os.path.join(path, fn)

    def render(self, path):
        self.option.replace()

        self.rst.directive(self.option.directive, self.resolve_option_name())
        self.rst.newline()

        if self.option.default is not None:
            self.content("*Default*: {0}".format(self.option.default))
            self.rst.newline()

        if self.option.type is not None:
            self.content("*Type*: {0}".format(self.option.type))
            self.rst.newline()

        if self.option.pre is not None:
            self.rst.content(self.option.pre.split("\n"), indent=3, wrap=False)
            self.rst.newline()

        if self.option.description is not None:
            self.rst.content(self.option.description.split("\n"), indent=3, wrap=False)
            self.rst.newline()

        if self.option.post is not None:
            self.rst.content(self.option.post.split("\n"), indent=3, wrap=False)
            self.rst.newline()

        output_file = self.resolve_output_path(path)
        self.rst.write(output_file)
开发者ID:RandomStuffs22,项目名称:docs-tools,代码行数:76,代码来源:options.py

示例13: OptionRendered

# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import content [as 别名]
class OptionRendered(object):
    def __init__(self, option):
        if not isinstance(option, Option):
            raise TypeError
        else:
            self.option = option

        self.rst = RstCloth()

    def resolve_option_name(self):
        if self.option.directive == 'option':
            if self.option.name.startswith('<'):
                prefix = ''
            else:
                prefix = '--'

            if hasattr(self.option, 'aliases'):
                if hasattr(self.option, 'arguments'):
                    return '{0}{1} {2}, {3}'.format(prefix, self.option.name,
                                                    self.option.arguments,
                                                    '{0}, '.format(self.option.arguments).join(self.option.aliases))
                else:
                    return '{0}{1}, {2}'.format(prefix, self.option.name,
                                                ', '.join(self.option.aliases))

            else:
                if hasattr(self.option, 'arguments'):
                    return '{0}{1} {2}'.format(prefix, self.option.name,
                                               self.option.arguments)
                else:
                    return '{0}{1}'.format(prefix, self.option.name)
        else:
            return self.option.name

    def resolve_output_path(self, path):
        name_parts = self.option.name.split(',')

        if len(name_parts) > 1:
            clensed_name = name_parts[0]
        else:
            clensed_name = self.option.name

        fn = '-'.join([ self.option.directive, self.option.program, clensed_name ]) + '.rst'
        return os.path.join(path, fn)

    def render(self, path):
        self.option.replace()

        self.rst.directive(self.option.directive, self.resolve_option_name())
        self.rst.newline()

        if self.option.type is not None:
            self.rst.content('*Type*: {0}'.format(self.option.type), indent=3)
            self.rst.newline()

        if self.option.default is not None:
            self.rst.content('*Default*: {0}'.format(self.option.default), indent=3)
            self.rst.newline()

        if self.option.pre is not None:
            self.rst.content(self.option.pre.split('\n'), indent=3, wrap=False)
            self.rst.newline()

        if self.option.description is not None:
            self.rst.content(self.option.description.split('\n'), indent=3, wrap=False)
            self.rst.newline()

        if self.option.post is not None:
            self.rst.content(self.option.post.split('\n'), indent=3, wrap=False)
            self.rst.newline()

        output_file = self.resolve_output_path(path)

        self.rst.write(output_file)

        logger.debug('wrote option to file {0}'.format(output_file))
开发者ID:MarkTseng,项目名称:docs-tools,代码行数:78,代码来源:options.py

示例14: build_page

# 需要导入模块: from utils.rstcloth.rstcloth import RstCloth [as 别名]
# 或者: from utils.rstcloth.rstcloth.RstCloth import content [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
开发者ID:RandomStuffs22,项目名称:docs-tools,代码行数:86,代码来源:includes.py


注:本文中的utils.rstcloth.rstcloth.RstCloth.content方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。