Esempio n. 1
0
    def run(self):
        node_list = nodes.bullet_list()

        token = os.getenv('GITHUB_TOKEN')
        if token:
            g = Github(token)
            repo = g.get_repo(self.arguments[0])
            folder = '' if not self.options['folder'] else self.options[
                'folder']
            contents = repo.get_contents(folder, ref="gh-pages")

            for line in list(reversed(contents)):

                if '.md' in line.path:
                    uri = 'https://github.com/' + self.arguments[
                        0] + '/blob/gh-pages/' + line.path
                    version = line.path.split('.md')[0]
                else:
                    uri = self.docs_url + self.arguments[0].split(
                        '/')[1] + '/' + line.path
                    version = line.path.split('/')[-1]

                if not any(excluded_file_name in version
                           for excluded_file_name in self.excluded_file_names):
                    item = nodes.list_item()
                    item_p = nodes.paragraph()
                    item_p += nodes.reference(text=version, refuri=uri)
                    item += item_p
                    node_list += item

        return [node_list]
Esempio n. 2
0
    def run(self):
        node_list = nodes.bullet_list()

        token = os.getenv('GITHUB_ACCESS_TOKEN')
        if token:
            g = Github(token)
            repo = g.get_repo(self.arguments[0])
            folder = '' if not self.options['folder'] else self.options['folder']
            contents = repo.get_contents(folder, ref="gh-pages")
            clean_contents = [content for content in contents if not any(excluded_name in content.path for excluded_name in self.excluded_file_names)]
            sorted_contents = sorted(clean_contents, key=lambda x: LooseVersion(x.path.split('v')[-1]), reverse=True)
            count = 1
            for line in sorted_contents:

                if '.md' in line.path:
                    uri = 'https://github.com/' + self.arguments[0] + '/blob/gh-pages/' + line.path
                    version = line.path.split('.md')[0]
                else:
                    uri = self.docs_url + self.arguments[0].split('/')[1] + '/' + line.path
                    version = line.path.split('/')[-1]

                if count == 1:
                    version += ' (next)'
                if count == 2:
                    version += ' (latest)'

                item = nodes.list_item()
                item_p = nodes.paragraph()
                item_p += nodes.reference(text=version, refuri=uri)
                item += item_p
                node_list += item

                count += 1

        return [node_list]
 def run(self):
     # ugly code is ugly! :P
     rv = [nodes.raw('', '<blockquote>\n', format='html')]
     rv.extend(LineBlock.run(self))
     if 'author' in self.options:
         author = nodes.raw(self.options['author'],
                            u'<span class="author">— ' +
                            self.options['author'] + '</span>',
                            format='html')
         rv.append(nodes.paragraph('', '', author))
         rv.append(nodes.raw('', '<div class="clear"></div>\n',
                             format='html'))
     rv.append(nodes.raw('', '</blockquote>\n', format='html'))
     return rv
def reference_field(key, value, value_text=None):
    field_name = nodes.field_name(key, key)
    field_body_ref = nodes.reference(value, value_text or value, refuri=value)
    field_body_p = nodes.paragraph('', '', field_body_ref)
    field_body = nodes.field_body('', field_body_p)
    return nodes.field('', field_name, field_body)
def text_field(key, value):
    field_name = nodes.field_name(key, key)
    field_body_p = nodes.paragraph(value, value)
    field_body = nodes.field_body('', field_body_p)
    return nodes.field('', field_name, field_body)
            rv.append(nodes.image(data['title'] or '', uri=data['url'],
                                  alt=data['title'] or '',
                                  width=str(data['width']),
                                  height=str(data['height'])))
            rv.append(nodes.raw('', '</div>', format='html'))
        elif data['type'] == 'rich':
            rv.append(nodes.raw('', data['html'], format='html',
                                classes=['oembed', 'oembed-rich']))
        elif data['type'] == 'video':
            rv.append(nodes.raw('', data['html'], format='html',
                                classes=['oembed', 'oembed-video']))
        elif data['type'] == 'link':
            uri = directives.uri(self.arguments[0])
            label = nodes.strong('Link: ', 'Link: ')
            link = nodes.reference(uri, data.get('title', uri), refuri=uri)
            rv.append(nodes.paragraph('', '', label, link))
            return rv

        if 'hide-metadata' in self.options:
            return rv

        rvl = []

        # always use title, if possible.
        if 'title' in data and data['title']:
            rvl.append(text_field('Title', data['title']))

        # description isn't part of the spec. but should be used if provided.
        if 'description' in data:
            rvl.append(text_field('Description', data['description']))