Commits

f kunze committed 939b299 Draft

Modified or added files to support articletagline and articletype: aggregator.py blog.py metadata.py articletagline.py articletype.py

  • Participants
  • Parent commits eeb0118

Comments (0)

Files changed (5)

tinkerer/ext/aggregator.py

 import copy
 from tinkerer.ext.uistr import UIStr
 
-
+# add code 
+#from tinkerer.ext.metadata import myinterrogate
+# end add code
 
 def make_aggregated_pages(app):
     '''
         for post in posts:
             # deepcopy metadata for each post
             metadata = copy.deepcopy(env.blog_metadata[post])
+            #added code
+            #testmeta = copy.deepcopy(metadata)
+            #print "from aggregator: post follows"
+            #print(post)
+            #print "from aggregator: metadata.articletagline follows"
+            #print(metadata.articletagline)
+            #print "from aggregator: myinterrogate(metadata) follows"
+            #myinterrogate(metadata)
+            #print "from aggregator: metadata follows"
+            #print(metadata)
+            #print "from aggregator: myinterrogate(testmeta) follows"
+            #myinterrogate(testmeta)
+            #print "from aggregator: testmeta follows"
+            #print(testmeta)
+            #print "from aggregator: testmeta.articletagline follows"
+            #print(testmeta.articletagline)
+            #end added code
             context["posts"].append(metadata)
 
 

tinkerer/ext/articletagline.py

+'''
+    articletagline
+    ~~~~~~~~~~~~~~
+
+    Post articletagline extension.
+
+    :copyright: Copyright 2011-2012 by fkunze and contributors (see
+    CONTRIBUTORS file)
+    :license: FreeBSD, see LICENSE file
+'''
+from sphinx.util.compat import Directive
+import tinkerer.utils
+
+
+
+class ArticleTaglineDirective(Directive):
+    '''
+    articletagline directive. The directive is not rendered, just stored in the 
+    metadata and passed to the templating engine.
+    '''
+    required_arguments = 0
+    optional_arguments = 100
+    has_content = False
+
+    def run(self):
+        '''
+        Called when parsing the document.
+        '''
+        env = self.state.document.settings.env
+
+        # store articletagline in metadata
+        articletagline = " ".join(self.arguments)
+        if articletagline == "default":
+            articletagline = env.config.articletagline 
+        
+        env.blog_metadata[env.docname].articletagline = articletagline
+
+        return []
+
+

tinkerer/ext/articletype.py

+'''
+    articletype
+    ~~~~~~~~~~~
+
+    Post articletype extension.
+
+    :copyright: Copyright 2011-2013 by fkunze and contributors (see
+    CONTRIBUTORS file)
+    :license: FreeBSD, see LICENSE file
+'''
+from sphinx.util.compat import Directive
+import tinkerer.utils
+
+
+
+class ArticleTypeDirective(Directive):
+    '''
+    articletype directive. The directive is not rendered, just stored in the 
+    metadata and passed to the templating engine.
+    '''
+    required_arguments = 0
+    optional_arguments = 100
+    has_content = False
+
+    def run(self):
+        '''
+        Called when parsing the document.
+        '''
+        env = self.state.document.settings.env
+
+        # store articletype in metadata
+        articletype = " ".join(self.arguments)
+        if articletype == "default":
+            articletype = env.config.articletype 
+        
+        env.blog_metadata[env.docname].articletype = articletype
+
+        return []
+
+

tinkerer/ext/blog.py

     CONTRIBUTORS file)
     :license: FreeBSD, see LICENSE file
 '''
-from tinkerer.ext import aggregator, author, filing, html5, metadata, patch, \
+from tinkerer.ext import aggregator, author, articletagline, articletype, filing, html5, metadata, patch, \
                          readmore, rss, uistr
 import gettext
 
     app.add_config_value("rss_service", None, True)
     app.add_config_value("website", "http://127.0.0.1/blog/html/", True)
     app.add_config_value("posts_per_page", 10, True)
+    app.add_config_value("articletagline", "Links From Around The Web", True)
+    app.add_config_value("articletype", "post", True)
 
     # new directives
     app.add_directive("author", author.AuthorDirective)
     app.add_directive("categories", 
             filing.create_filing_directive("categories"))
     app.add_directive("more", readmore.InsertReadMoreLink)
- 
+    app.add_directive("articletagline", articletagline.ArticleTaglineDirective)
+    app.add_directive("articletype", articletype.ArticleTypeDirective)
+
     # create a new Sphinx event which gets called when we generate aggregated
     # pages
     app._events["html-collected-context"] = "pagename, templatename, context"

tinkerer/ext/metadata.py

     CONTRIBUTORS file)
     :license: FreeBSD, see LICENSE file
 '''
+# Added code to get recent tags
+import copy
+# end Added code to get recent tags
 import re
 import datetime
 from sphinx.util.compat import Directive
 from tinkerer.ext.uistr import UIStr
 from tinkerer.utils import name_from_title
 
-
+# added code
+# myinterrogate function
+def myinterrogate(item):
+    """Print useful information about item."""
+    if hasattr(item, '__name__'):
+        print "NAME:    ", item.__name__
+    if hasattr(item, '__class__'):
+        print "CLASS:   ", item.__class__.__name__
+    print "ID:      ", id(item)
+    print "TYPE:    ", type(item)
+    print "VALUE:   ", repr(item)
+    print "CALLABLE:",
+    if callable(item):
+        print "Yes"
+    else:
+        print "No"
+    if hasattr(item, '__doc__'):
+        doc = getattr(item, '__doc__')
+    doc = doc.strip()   # Remove leading/trailing whitespace.
+    firstline = doc.split('\n')[0]
+    print "DOC:     ", firstline
+# end myinterrogate function
+# end added code
 
 def initialize(app):
     '''
         self.formatted_date_short = None
         self.body = None
         self.author = None
+        self.articletagline = None
+        self.articletype = None
         self.filing = { "tags": [], "categories": [] }
         self.comments, self.comment_count = False, False
         self.num = Metadata.num
     context['website'] = app.config.website
 
     # blog tagline and pages
+    context["articletype"] = app.config.articletype
+    context["articletagline"] = app.config.articletagline
     context["tagline"] = app.config.tagline
     context["description"] = app.config.description
     context["pages"] = env.blog_page_list
     # recent posts
     context["recent"] = [(post, env.titles[post].astext()) for post
             in env.blog_posts[:20]]
+
+    #added code
+    most_recent_post = list([(post, env.titles[post].astext()) for post in env.blog_posts[:1]])
+    context["most_recent_post"] = most_recent_post
+    p=env.blog_metadata[most_recent_post[0][0]]
+    context["most_recent_post_tags"] = p.filing["tags"]
+    context["most_recent_post_categories"] = p.filing["categories"]
+    # end added code
+
     # tags & categories
     tags = dict((t, 0) for t in env.filing["tags"])
     taglinks = dict((t, name_from_title(t)) for t in env.filing["tags"])