How to use the hotdoc.core.formatter.Formatter function in hotdoc

To help you get started, we’ve selected a few hotdoc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hotdoc / hotdoc / hotdoc / core / extension.py View on Github external
def _make_formatter(self):
        return Formatter(self)
github hotdoc / hotdoc / hotdoc / extensions / gi / formatter.py View on Github external
if fund_link:
                link = Link(fund_link.ref, fund_link._title, gi_name)
            elif gi_name in ALL_GI_TYPES:
                ctype_name = ALL_GI_TYPES[gi_name]
                link = self.extension.app.link_resolver.get_named_link(ctype_name)

            if type_desc.nesting_depth:
                new_tokens.append('[' * type_desc.nesting_depth + ' ')
            if link:
                new_tokens.append(link)
            else: # Should not happen but let's be conservative
                new_tokens.append(type_desc.gi_name)
            if type_desc.nesting_depth:
                new_tokens.append(']' * type_desc.nesting_depth)

            return Formatter._format_type_tokens (self, symbol, new_tokens)

        return Formatter._format_type_tokens (self, symbol, type_tokens)
github hotdoc / hotdoc / hotdoc / core / formatter.py View on Github external
def __update_section_number(self, target, section_numbers):
        if not Formatter.number_headings or target.tag not in section_numbers:
            return None

        prev = section_numbers.get('prev')
        cur = int(target.tag[1])

        if cur < prev:
            for i in range(cur + 1, 6):
                section_numbers['h%d' % i] = 0

        section_numbers[target.tag] += 1
        section_numbers['prev'] = cur

        section_number = u''
        for i in range(section_numbers['first'], cur + 1):
            if section_number:
                section_number += '.'
github hotdoc / hotdoc / hotdoc / extensions / license / license_extension.py View on Github external
def license_content(self, page, license_, designation):
        template = Formatter.engine.get_template('license.html')
        if license_.logo_path:
            logo_path = os.path.join(
                'assets', os.path.basename(license_.logo_path))
        else:
            logo_path = None

        formatted = template.render(
            {'license': license_,
             'logo_path': logo_path,
             'content_designation': designation})
        page.output_attrs['html']['extra_footer_html'].insert(0, formatted)

        LicenseExtension.installed_assets.add(license_.plain_text_path)
        if license_.logo_path:
            LicenseExtension.installed_assets.add(license_.logo_path)
github hotdoc / hotdoc / hotdoc / extensions / gst / gst_extension.py View on Github external
def _format_prototype(self, function, is_pointer, title):
        c_proto = Formatter._format_prototype(self, function, is_pointer, title)
        template = self.get_template('python_prototype.html')
        python_proto = template.render(
            {'function_name': title,
             'parameters': function.parameters,
             'throws': False,
             'comment': "python callback for the '%s' signal" % function.make_name(),
             'is_method': False})
        template = self.get_template('javascript_prototype.html')
        for param in function.parameters:
            param.extension_contents['type-link'] = self._format_linked_symbol(
                param)
        js_proto = template.render(
            {'function_name': title,
             'parameters': function.parameters,
             'throws': False,
             'comment': "javascript callback for the '%s' signal" % function.make_name(),
github hotdoc / hotdoc / hotdoc / extensions / gi / formatter.py View on Github external
def _format_struct (self, struct):
        language = struct.get_extension_attribute(self.extension.extension_name, 'language')
        if language == 'c':
            return Formatter._format_struct (self, struct)

        members_list = self._format_members_list (struct.members, 'Attributes', struct)

        template = self.engine.get_template ("python_compound.html")
        out = template.render ({"symbol": struct,
                                "members_list": members_list})
        return out
github hotdoc / hotdoc / hotdoc / core / formatter.py View on Github external
def _get_extra_files(self):
        res = []

        if Formatter.theme_path:
            res.extend(self.__get_theme_files(Formatter.theme_path))
        if Formatter.extra_theme_path:
            res.extend(self.__get_theme_files(Formatter.extra_theme_path))

        for script_path in Formatter.all_scripts:
            dest = os.path.join('js', os.path.basename(script_path))
            res.append((script_path, dest))

        for stylesheet_path in Formatter.all_stylesheets:
            dest = os.path.join('css', os.path.basename(stylesheet_path))
            res.append((stylesheet_path, dest))

        return res
github hotdoc / hotdoc / hotdoc / extensions / gst / gst_extension.py View on Github external
self.caps = None
        self.object_type = None
        Symbol.__init__(self, **kwargs)

    def get_children_symbols(self):
        return [self.qtype, self.object_type] + super().get_children_symbols()

    # pylint: disable=no-self-use
    def get_type_name(self):
        """
        Banana banana
        """
        return "GstPadTemplate"


class GstFormatter(Formatter):
    engine = None

    def __init__(self, extension):
        self.__tmpdir = TemporaryDirectory()
        with open(os.path.join(self.__tmpdir.name, "padtemplate.html"), "w") as _:
            _.write(GstPadTemplateSymbol.TEMPLATE)
        with open(os.path.join(self.__tmpdir.name, "enumtemplate.html"), "w") as _:
            _.write(GstNamedConstantValue.TEMPLATE)
        with open(os.path.join(self.__tmpdir.name, "plugins.html"), "w") as _:
            _.write(GstPluginsSymbol.TEMPLATE)
        with open(os.path.join(self.__tmpdir.name, "plugin.html"), "w") as _:
            _.write(GstPluginSymbol.TEMPLATE)
        with open(os.path.join(self.__tmpdir.name, "element.html"), "w") as _:
            _.write(GstElementSymbol.TEMPLATE)
        Formatter.__init__(self, extension)
        self._order_by_parent = True
github hotdoc / hotdoc / hotdoc / extensions / license / license_extension.py View on Github external
def setup(self):
        super(LicenseExtension, self).setup()
        for ext in self.project.extensions.values():
            ext.formatter.formatting_page_signal.connect(
                self.__formatting_page_cb)

        if not LicenseExtension.connected:
            Formatter.get_extra_files_signal.connect(
                self.__get_extra_files_cb)
            LicenseExtension.connected = True
github hotdoc / hotdoc / hotdoc / core / formatter.py View on Github external
def copy_assets(self, assets_path):
        """Banana banana
        """
        if not os.path.exists(assets_path):
            os.mkdir(assets_path)

        extra_files = self._get_extra_files()

        for ex_files in Formatter.get_extra_files_signal(self):
            extra_files.extend(ex_files)

        for src, dest in extra_files:
            dest = os.path.join(assets_path, dest)

            destdir = os.path.dirname(dest)
            if not os.path.exists(destdir):
                os.makedirs(destdir)
            if os.path.isfile(src):
                shutil.copy(src, dest)
            elif os.path.isdir(src):
                recursive_overwrite(src, dest)