コード例 #1
0
ファイル: core.py プロジェクト: tamizhgeek/rejourn
    def __update_context(self, target_list = None):
        """Builds context from target_list"""

        entries = []
        context = {}
        for target in target_list:
            with open(os.path.join(self.config['indir'], target + '.txt'), 'r') as infh:
                raw_header, content = infh.read().split('\n---\n')
                header = util.parse_header(raw_header)
                title = header.get('title', 'No Title')
                extensions = ['codehilite', 'html_tidy']
                snip = header.get('snip', markdown(content, extensions)[:50] + ' ...')
                pubdate = header.get('pubdate', None)

                # Has a date it was published, isn't a draft and isn't a static page
                if pubdate and not (header.get('draft', None) or header.get('static', None)):
                    entries.append({'title': title,
                                    'permalink': header.get('permalink', util.build_slug(title)),
                                    'snip': snip,
                                    'pubdate': pubdate})
        entries.sort(cmp = (lambda x, y: -1 if x['pubdate'] > y['pubdate'] else 1))
        context['entries'] = entries
        context['permalink'] = 'index'
        context['title'] = 'Journal'
        return context
コード例 #2
0
ファイル: core.py プロジェクト: artagnon/rejourn
    def __update_context(self, context = None):
        """Post processing: Given certain values in context,
        calculates others"""

        if context is None:
            context = self.context
            
        # permalink might already be in header, in which case we don't
        # want to change it
        title = context.get('title', 'No Title')
        context['permalink'] = context.get('permalink',
                                           util.build_slug(self.config, title, self.inpath))
        context['draft'] = context.get('draft', None);
        
        # If pubdate is None, util.build_tiemstamp_h will return the
        # string "[Unpublished]"
        pubdate = context.get('pubdate', None)
        context['pubdate_h'] = util.build_timestamp_h(pubdate)
        return context
コード例 #3
0
ファイル: tests.py プロジェクト: artagnon/rejourn
 def test_init(self):
     title = """The hacker's dream journal engine"""
     assert self.jentry.context["title"] == title
     assert self.jentry.context["permalink"] == util.build_slug({}, title, None)
     assert self.jentry.context["tags"] == "foo, bar"
コード例 #4
0
ファイル: core.py プロジェクト: artagnon/rejourn
    def __update_context(self, target_list = None):
        """Builds context from target_list"""

        entries = []
        context = {}
        for target in target_list:
            with open(target + '.txt', 'r') as infh:
                raw_header, content = infh.read().split('\n' + self.config.get('separator', '---') + '\n', 1)
                header = util.parse_header(raw_header)
                title = header.get('title', 'No Title')
                extensions = ['codehilite', 'html_tidy']
                snip = header.get('snip', '')
                if not len(snip) and (not 'snips' in self.config or self.config['snips'] == True):
                    snip = util.htransform(content, self.config.get('htransform', None))[:50] + ' ...'
                if not self.rss:
                    html_content = util.htransform(content, self.config.get('htransform', None))
                else:
                    rss_content = saxutils.escape(util.htransform(content, self.config.get('htransform', None)))
                pubdate = header.get('pubdate', None)
                pubdate_h = util.build_timestamp_h(pubdate, rss=self.rss)

                # Has a date it was published, isn't a draft and isn't a static page
                if pubdate and not (header.get('draft', None) or header.get('static', None)):
                    entries.append({'title': title,
                                    'permalink': header.get('permalink', util.build_slug(self.config, title, infh.name)),
                                    'snip': snip,
                                    'pubdate': pubdate,
                                    'pubdate_h': pubdate_h})
                    if not self.rss:
                        entries[-1]['html_content'] = html_content
                    else:
                        entries[-1]['rss_content'] = rss_content
        entries.sort(cmp = (lambda x, y: -1 if x['pubdate'] > y['pubdate'] else 1))
        indexlen = int(self.config.get('indexlen', 10))
        rsslen = int(self.config.get('rsslen', 10))
        taglen = int(self.config.get('taglen', 0))
        if self.name == 'index' and indexlen > 0:
            context['entries'] = entries[:indexlen]
            if os.path.exists('tags'):
                with open('tags') as tagsfh:
                    context['tags'] = tagsfh.read()
            else:
                context['tags'] = ''
        elif self.name.endswith('.rss') and rsslen > 0:
            context['entries'] = entries[:rsslen]
        elif (not (self.name.endswith('.rss') or self.name == 'archive')) and taglen > 0:
            context['entries'] = entries[:taglen]
        else:
            context['entries'] = entries
        context['permalink'] = self.name
        if self.name.startswith('index') or self.name.startswith('archive'):
            context['title'] = self.config['title']
            self.tagprefix = ''
        else:
            if self.name.endswith('.rss'):
                context['title'] = saxutils.escape(self.config['title'] + ' - Tags: ' + self.name.replace('.rss', ''))
                self.tagprefix = ''
            else:
                context['title'] = self.config['title'] + ' - Tags: ' + self.name
        context['baseurl'] = self.config['baseurl']
        return context
コード例 #5
0
ファイル: tests.py プロジェクト: tamizhgeek/rejourn
 def test_init(self):
     title = """The hacker's dream journal engine"""
     assert self.jentry.context['title'] == title
     assert self.jentry.context['permalink'] == util.build_slug(title)