Esempio n. 1
0
    def generate_help(self, target, inline=False, visibility=''):
        """Show documentation for named `target`.

        If `inline` is set, no header will be generated.
        For the `visibility` argument, see `PyDocMacro`.
        """
        try:
            if not target or target == 'index':
                if inline:
                    doc = ''
                else:
                    doc = html.h1('Python: Index of Modules')
                for dir in self.syspath:
                    if os.path.isdir(dir):
                        doc += Markup(self.doc.index(dir,
                                                     includes=self.includes,
                                                     excludes=self.excludes))
                return doc
            else:
                if inline:
                    doc = ''
                else:
                    doc = html.h1('Python: Documentation for ',
                                  Markup(self.doc._dotted_path_links(target)))
                return doc + Markup(to_unicode(self._makedoc(target,
                                                             visibility)))
        except ImportError:
            return "No Python documentation found for '%s'" % target
Esempio n. 2
0
    def generate_help(self, target, inline=False, visibility=''):
        """Show documentation for named `target`.

        If `inline` is set, no header will be generated.
        For the `visibility` argument, see `PyDocMacro`.
        """
        try:
            if not target or target == 'index':
                if inline:
                    doc = ''
                else:
                    doc = html.h1('Python: Index of Modules')
                for dir in self.syspath:
                    if os.path.isdir(dir):
                        doc += Markup(
                            self.doc.index(dir,
                                           includes=self.includes,
                                           excludes=self.excludes))
                return doc
            else:
                if inline:
                    doc = ''
                else:
                    doc = html.h1('Python: Documentation for ',
                                  Markup(self.doc._dotted_path_links(target)))
                return doc + Markup(
                    to_unicode(self._makedoc(target, visibility)))
        except ImportError:
            return "No Python documentation found for '%s'" % target
Esempio n. 3
0
    def expand_macro(self, formatter, name, content):
        """
        Execute / Render the macro. Return the content to caller.
        """
        if name not in self.macros:
            return None

        identifier = self.env.project_identifier
        project = Project.get(self.env)

        if project is None:
            return None

        if name == 'ProjectName':
            return project.project_name

        elif name == 'ProjectIdentifier':
            return identifier

        elif name == 'ProjectOwner':
            return project.author.username

        elif name == 'ProjectCreateDate':
            return project.created

        elif name == 'ProjectUrl':
            url = project.get_url()

            txt = content or identifier
            return html.a(txt, href=url)

        elif name == 'ProjectVersioncontrolUrl':
            url = project.get_repository_url()

            txt = content or url
            return html.a(txt, href=url)

        elif name == 'ProjectWebDavUrl':
            url = project.get_dav_url()

            txt = content or url
            return html.a(txt, href=url)

        elif name == 'WelcomeText':
            return html.h1("Welcome to " + project.project_name,
                           id="WelcomeToProject")
Esempio n. 4
0
    def expand_macro(self, formatter, name, content):
        """
        Execute / Render the macro. Return the content to caller.
        """
        if name not in self.macros:
            return None

        identifier = self.env.project_identifier
        project = Project.get(self.env)

        if project is None:
            return None

        if name == 'ProjectName':
            return project.project_name

        elif name == 'ProjectIdentifier':
            return identifier

        elif name == 'ProjectOwner':
            return project.author.username

        elif name == 'ProjectCreateDate':
            return project.created

        elif name == 'ProjectUrl':
            url = project.get_url()

            txt = content or identifier
            return html.a(txt, href = url)

        elif name == 'ProjectVersioncontrolUrl':
            url = project.get_repository_url()

            txt = content or url
            return html.a(txt, href = url)

        elif name == 'ProjectWebDavUrl':
            url = project.get_dav_url()

            txt = content or url
            return html.a(txt, href = url)

        elif name == 'WelcomeText':
            return html.h1("Welcome to " + project.project_name, id = "WelcomeToProject")
Esempio n. 5
0
    def _render_readme(self, req, stream, data):
        add_stylesheet(req, 'common/css/code.css')

        repos = data.get('repos') or self.env.get_repository()
        rev = req.args.get('rev', None)

        # Rendering all READMEs in a directory preview
        for entry in data['dir']['entries']:
            try:
                if not entry.isdir and entry.name.lower().startswith('readme'):
                    node = repos.get_node(entry.path, rev)
                    req.perm(data['context'].resource).require('FILE_VIEW')
                    mimeview = Mimeview(self.env)
                    content = node.get_content()
                    mimetype = node.content_type
                    divclass = 'searchable'
                    if entry.name.lower().endswith('.wiki'):
                        mimetype = 'text/x-trac-wiki'
                        divclass = 'searchable wiki'
                    elif entry.name.lower().endswith('.md'):
                        mimetype = 'text/x-markdown'
                        divclass = 'searchable markdown'
                    if not mimetype or mimetype == 'application/octet-stream':
                        mimetype = mimeview.get_mimetype(
                            node.name, content.read(4096)) or \
                            mimetype or 'text/plain'
                    del content
                    self.log.debug(
                        "ReadmeRenderer: rendering node %s@%s as %s",
                        node.name, rev, mimetype)
                    output = mimeview.preview_data(
                        data['context'],
                        node.get_content(),
                        node.get_content_length(),
                        mimetype,
                        node.created_path,
                        '',
                        annotations=[],
                        force_source=False)

                    if output:
                        if isinstance(output['rendered'], Stream):
                            content = output['rendered'].select('.')
                        else:
                            content = output['rendered']
                        insert = tag.div(
                            tag.h1(entry.name,
                                   tag.a(Markup(' ¶'),
                                         class_="anchor",
                                         href='#' + entry.name,
                                         title='Link to file'),
                                   id_=entry.name),
                            tag.div(content,
                                    class_=divclass,
                                    title=entry.name),
                            class_="readme",
                            style="padding-top: 1em;"
                        )
                        xpath = "//div[@id='content']/div[@id='help']"
                        stream |= Transformer(xpath).before(insert)
            except Exception, e:
                self.log.debug(to_unicode(e))