コード例 #1
0
ファイル: blog.py プロジェクト: mahmoud/PythonDoesBlog
    def render_feeds(self):
        posts = [p for p in self.posts[::-1] if p.is_pub]
        with open(os.path.join(OUTPUT_DIR, 'feed', 'atom.xml'), 'w') as a_file:
            a_file.write(render_to('atom.mako', posts=posts))

        with open(os.path.join(OUTPUT_DIR, 'feed', 'rss.xml'), 'w') as a_file:
            a_file.write(render_to('rss.mako', posts=posts))
コード例 #2
0
ファイル: blog.py プロジェクト: mahmoud/PythonDoesBlog
    def render_posts(self):
        with open(os.path.join(OUTPUT_DIR,'post_list.html'),'w') as pl_file:
            pl_file.write(render_to('post_list.html', posts=self.posts))

        for post in self.posts:
            with open(os.path.join(OUTPUT_DIR, 'posts', post.slug+'.html'), 'w') as p_html:
                p_html.write(render_to('post_single.html', post=post))
            with open(os.path.join(OUTPUT_DIR, 'posts', post.slug+'.rst'), 'w') as p_rst:
                p_rst.write(render_to('post_single.rst', post=post))
コード例 #3
0
ファイル: blog.py プロジェクト: mahmoud/PythonDoesBlog
    def render_tag_pages(self):
        tag_dict = self.tag_dict
        for tag, posts in tag_dict.items():
            tag_slug = slugify(unicode(tag))
            with open(os.path.join(OUTPUT_DIR, 'tag', tag_slug+'.html'), 'w') as t_file:
                t_file.write(render_to('post_list.html', 
                                       posts=posts, 
                                       list_desc="Posts tagged <em>"+tag+"</em>"))

        with open(os.path.join(OUTPUT_DIR, 'tag', 'tag_cloud.html'), 'w') as t_file:
            t_file.write(render_to('tag_cloud.html', tag_dict=tag_dict))
コード例 #4
0
ファイル: blog.py プロジェクト: mahmoud/PythonDoesBlog
 def render_author_pages(self):
     author_dict = self.author_dict
     for author, posts in author_dict.items():
         author_slug = slugify(unicode(author))
         with open(os.path.join(OUTPUT_DIR, 'author', author_slug+'.html'), 'w') as a_file:
             a_file.write(render_to('post_list.html', 
                                    posts=posts, 
                                    list_desc="Posts by "+author+""))
コード例 #5
0
ファイル: post.py プロジェクト: mahmoud/PythonDoesBlog
    def get_html(self, body_only=True, content_only=False, noclasses=False):
        import sys
        import pygments_rest
        from docutils.core import Publisher
        from docutils.io import StringInput, StringOutput
        from cStringIO import StringIO

        settings = {
            'doctitle_xform': 1,
            'pep_references': 1,
            'rfc_references': 1,
            'footnote_references': 'superscript',
            'output_encoding': 'unicode',
            'report_level':
            2,  # 2=show warnings, 3=show only errors, 5=off (docutils.utils
        }

        if content_only:
            post_rst = self.get_rst(noclasses=noclasses)
        else:
            post_rst = render_to('post_single.rst',
                                 post=self,
                                 noclasses=noclasses)

        pub = Publisher(reader=None,
                        parser=None,
                        writer=None,
                        settings=None,
                        source_class=StringInput,
                        destination_class=StringOutput)

        pub.set_components(reader_name='standalone',
                           parser_name='restructuredtext',
                           writer_name='html')
        pub.process_programmatic_settings(settings_spec=None,
                                          settings_overrides=settings,
                                          config_section=None)
        pub.set_source(post_rst, source_path=self.module_path)
        pub.set_destination(None, None)

        errors_io = StringIO()
        real_stderr = sys.stderr
        sys.stderr = errors_io
        try:
            html_full = pub.publish(enable_exit_status=False)
            html_body = ''.join(pub.writer.html_body)
        finally:
            sys.stderr = real_stderr
        errors = errors_io.getvalue()
        self._process_rest_errors(errors)

        errors_io.close()

        return html_body if body_only else html_full
コード例 #6
0
ファイル: post.py プロジェクト: mahmoud/PythonDoesBlog
    def get_html(self, body_only=True, content_only=False, noclasses=False):
        import sys
        import pygments_rest
        from docutils.core import Publisher
        from docutils.io import StringInput, StringOutput
        from cStringIO import StringIO
        
        settings = {'doctitle_xform'     : 1,
                    'pep_references'     : 1,
                    'rfc_references'     : 1,
                    'footnote_references': 'superscript',
                    'output_encoding'    : 'unicode',
                    'report_level'       : 2, # 2=show warnings, 3=show only errors, 5=off (docutils.utils
                    }

        if content_only:
            post_rst = self.get_rst(noclasses=noclasses)
        else:
            post_rst = render_to('post_single.rst', 
                                 post=self, 
                                 noclasses=noclasses)
                             
        pub = Publisher(reader=None, 
                        parser=None, 
                        writer=None, 
                        settings=None,
                        source_class=StringInput,
                        destination_class=StringOutput)

        pub.set_components(reader_name='standalone',
                           parser_name='restructuredtext',
                           writer_name='html')
        pub.process_programmatic_settings(settings_spec=None,
                                          settings_overrides=settings,
                                          config_section=None)
        pub.set_source(post_rst,source_path=self.module_path)
        pub.set_destination(None, None)

        errors_io = StringIO()
        real_stderr = sys.stderr
        sys.stderr = errors_io
        try:
            html_full = pub.publish(enable_exit_status=False)
            html_body = ''.join(pub.writer.html_body)
        finally:
            sys.stderr = real_stderr
        errors = errors_io.getvalue()
        self._process_rest_errors(errors)

        errors_io.close()

        return html_body if body_only else html_full
コード例 #7
0
ファイル: blog.py プロジェクト: mahmoud/PythonDoesBlog
    def render_home(self):
        from settings import POSTS_PER_PAGE as ppp
        
        posts = [ p for p in self.posts[::-1] if p.is_pub ]

        groups = group_posts(posts, ppp)

        last_page = len(groups)
        for cur_page, group in enumerate(groups, start=1):
            filename = str(cur_page)+'.html'

            with open(os.path.join(OUTPUT_DIR, filename), 'w') as p_file:
                p_file.write(render_to('post_list.html', 
                                       posts=group, 
                                       cur_page=cur_page, 
                                       last_page=last_page))

        if last_page:
            shutil.copyfile(os.path.join(OUTPUT_DIR, '1.html'),
                            os.path.join(OUTPUT_DIR, 'index.html'))