예제 #1
0
파일: post.py 프로젝트: ymt2/tinkerer
    def __init__(self, title=None, path=None, date=None):
        '''
        Initializes a new post and creates path to it if it doesn't already
        exist.
        '''
        self.title = title

        # get year, month and day from date
        self.year, self.month, self.day = utils.split_date(date)

        # get name from path if specified, otherwise from title
        if path:
            self.name = utils.name_from_path(path)
        else:
            self.name = utils.name_from_title(title)

        # create post directory if it doesn't exist and get post path
        self.path = os.path.join(
            utils.get_path(
                paths.root,
                self.year,
                self.month,
                self.day),
            self.name) + tinkerer.source_suffix

        # docname as it should appear in TOC
        self.docname = "/".join([self.year, self.month, self.day, self.name])
예제 #2
0
파일: draft.py 프로젝트: kiith-sa/tinkerer
def create(title, template=None):
    '''
    Creates a new post draft.
    '''
    name = utils.name_from_title(title)
    template = template or paths.post_template

    path = os.path.join(
                    utils.get_path(
                        paths.root, 
                        "drafts"), 
                    name + tinkerer.source_suffix)

    if os.path.exists(path):
        raise Exception("Draft '%s' already exists at '%s" %
                        (title, path))

    writer.render(template, path,
            { "title"     : title,
              "content"   : "",
              "author"    : "default",
              "categories": "none",
              "tags"      : "none"})

    return path
예제 #3
0
파일: post.py 프로젝트: vladris/tinkerer
    def __init__(self, title=None, path=None, date=None):
        '''
        Initializes a new post and creates path to it if it doesn't already
        exist.
        '''
        self.title = title

        # get year, month and day from date
        self.year, self.month, self.day = utils.split_date(date)

        # get name from path if specified, otherwise from title
        if path:
            self.name = utils.name_from_path(path)
        else:
            self.name = utils.name_from_title(title)

        # create post directory if it doesn't exist and get post path
        self.path = os.path.join(
            utils.get_path(
                paths.root,
                self.year,
                self.month,
                self.day),
            self.name) + tinkerer.source_suffix

        # docname as it should appear in TOC
        self.docname = "/".join([self.year, self.month, self.day, self.name])
예제 #4
0
파일: draft.py 프로젝트: scudette/tinkerer
def create(title, template=None):
    '''
    Creates a new post draft.
    '''
    name = utils.name_from_title(title)
    template = template or paths.post_template

    path = os.path.join(
        utils.get_path(paths.root, "drafts"),
        name + tinkerer.source_suffix,
    )

    if os.path.exists(path):
        raise Exception("Draft '%s' already exists at '%s" % (title, path))

    writer.render(
        template, path, {
            "title": title,
            "content": "",
            "author": "default",
            "categories": "none",
            "tags": "none"
        })

    return path
예제 #5
0
        def run(self):
            '''
            Called when parsing the document.
            '''
            env = self.state.document.settings.env

            for item in " ".join(self.arguments).split(","):
                item = item.strip()
                if item == "none":
                    continue

                if not item:
                    logging.getLogger(__name__).warn(
                        "%s: empty string in '%s' directive" % (
                            env.docname,
                            name,
                        ))
                    continue

                if item not in env.filing[name]:
                    env.filing[name][item] = []
                env.filing[name][item].append(env.docname)
                env.blog_metadata[env.docname].filing[name].append(
                    (utils.name_from_title(item), item))

            return []
예제 #6
0
def generate_feeds(app):
    env = app.builder.env
    categories = env.filing["categories"]

    for category_name, posts in env.filing["categories"].items():
        for name, context, template in rss.generate_feed(app, category_name, posts):
            slug = utils.name_from_title(name)
            yield ("rss/categories/%s" % slug, context, template)
예제 #7
0
def generate_feeds(app):
    env = app.builder.env
    categories = env.filing["categories"]

    for category_name, posts in env.filing["tags"].items():
        for name, context, template in rss.generate_feed(
                app, category_name, posts):
            slug = utils.name_from_title(name)
            yield ("rss/tags/%s" % slug, context, template)
예제 #8
0
파일: filing.py 프로젝트: lakhman/tinkerer
def make_tag_pages(app):
    '''
    Generates archive pages for each tag.
    '''
    env = app.builder.env
    for tag in env.filing["tags"]:
        yield make_archive_page(env, UIStr.TAGGED_WITH_FMT % tag,
                                "tags/" + utils.name_from_title(tag),
                                lambda post: post in env.filing["tags"][tag])
예제 #9
0
def generate_feeds(app):
    env = app.builder.env
    categories = env.filing["categories"]

    for category_name, posts in env.filing["categories"].items():
        app.info("Generating RSS feed for category '%s'." % category_name)
        name, context, template = rss.generate_feed(app, category_name, posts)
        slug = utils.name_from_title(name)
        yield ("rss/categories/%s" % slug, context, template)
예제 #10
0
파일: filing.py 프로젝트: lakhman/tinkerer
def make_category_pages(app):
    '''
    Generates archive pages for each category.
    '''
    env = app.builder.env
    for category in env.filing["categories"]:
        yield make_archive_page(
            env, UIStr.FILED_UNDER_FMT % category,
            "categories/" + utils.name_from_title(category),
            lambda post: post in env.filing["categories"][category])
예제 #11
0
파일: filing.py 프로젝트: MiCHiLU/tinkerer
def make_category_pages(app):
    '''
    Generates archive pages for each category.
    '''
    env = app.builder.env
    for category in env.filing["categories"]:
        yield make_archive_page(env,
                UIStr.FILED_UNDER_FMT % category,
                "categories/" + utils.name_from_title(category),
                lambda post: post in env.filing["categories"][category])
예제 #12
0
파일: filing.py 프로젝트: MiCHiLU/tinkerer
def make_tag_pages(app):
    '''
    Generates archive pages for each tag.
    '''
    env = app.builder.env
    for tag in env.filing["tags"]:
        yield make_archive_page(env,
                UIStr.TAGGED_WITH_FMT % tag,
                "tags/" + utils.name_from_title(tag),
                lambda post: post in env.filing["tags"][tag])
예제 #13
0
    def __init__(self, title=None, path=None):
        '''
        Determines page filename based on title or given path and creates the
        path to the page if it doesn't already exist.
        '''
        self.title = title

        # get name from path if specified, otherwise from title
        if path:
            self.name = utils.name_from_path(path)
        else:
            self.name = utils.name_from_title(title)

        # create page directory if it doesn't exist and get page path
        self.path = os.path.join(utils.get_path(paths.root, "pages"),
                                 self.name) + tinkerer.source_suffix

        # docname as it should appear in TOC
        self.docname = "pages/" + self.name
예제 #14
0
    def __init__(self, title=None, path=None):
        '''
        Determines page filename based on title or given path and creates the
        path to the page if it doesn't already exist.
        '''
        self.title = title

        # get name from path if specified, otherwise from title
        if path:
            self.name = utils.name_from_path(path)
        else:
            self.name = utils.name_from_title(title)

        # create page directory if it doesn't exist and get page path
        self.path = os.path.join(
            utils.get_path(paths.root, "pages"),
            self.name) + tinkerer.source_suffix

        # docname as it should appear in TOC
        self.docname = "pages/" + self.name
예제 #15
0
def create(title):
    '''
    Creates a new post draft.
    '''
    name = utils.name_from_title(title)

    path = os.path.join(
                    utils.get_path(
                        paths.root, 
                        "drafts"), 
                    name + tinkerer.source_suffix)

    writer.render(paths.post_template, path,
            { "title"     : title,
              "content"   : "",
              "author"    : "default",
              "categories": "none",
              "tags"      : "none"})

    return path
예제 #16
0
파일: filing.py 프로젝트: MiCHiLU/tinkerer
        def run(self):
            '''
            Called when parsing the document.
            '''
            env = self.state.document.settings.env

            for item in " ".join(self.arguments).split(","):
                item = item.strip()
                if item == "none":
                    continue

                if not item:
                    env.warn(env.docname, "Empty string in '%s' directive" % (name,))
                    continue

                if item not in env.filing[name]:
                    env.filing[name][item] = []
                env.filing[name][item].append(env.docname)
                env.blog_metadata[env.docname].filing[name].append(
                        (utils.name_from_title(item), item))

            return []
예제 #17
0
def add_metadata(app, pagename, context):
    '''
    Passes metadata to the templating engine.
    '''
    env = app.builder.env

    # page data
    context['website'] = app.config.website

    # blog tagline and pages
    context["tagline"] = app.config.tagline
    context["description"] = app.config.description
    context["pages"] = env.blog_page_list

    # set translation context variables
    context["text_recent_posts"] = UIStr.RECENT_POSTS
    context["text_posted_by"] = UIStr.POSTED_BY
    context["text_blog_archive"] = UIStr.BLOG_ARCHIVE
    context["text_filed_under"] = UIStr.FILED_UNDER
    context["text_tags"] = UIStr.TAGS
    context["text_tags_cloud"] = UIStr.TAGS_CLOUD
    context["text_categories"] = UIStr.CATEGORIES

    # recent posts
    context["recent"] = [(post, env.titles[post].astext()) for post
                         in env.blog_posts[:20]]
    # tags & categories
    tags, categories = [dict([(p, 0) for p in env.filing[c] if not
                        p.startswith('{{')]) for c in ["tags", "categories"]]
    taglinks = dict((t, name_from_title(t)) for t in tags)
    catlinks = dict([(c, name_from_title(c)) for c in categories])

    for post in env.blog_posts:
        p = env.blog_metadata[post]
        for tag in p.filing["tags"]:
            tags[tag[1]] += 1
        for cat in p.filing["categories"]:
            categories[cat[1]] += 1
    context["tags"] = tags
    context["taglinks"] = taglinks
    context["categories"] = categories
    context["catlinks"] = catlinks

    # if there is metadata for the page, it is not an auto-generated one
    if pagename in env.blog_metadata:
        context["metadata"] = env.blog_metadata[pagename]

        # if this is a post
        if pagename in env.blog_posts:
            # save body
            env.blog_metadata[pagename].body = context["body"]

            # no prev link if first post, no next link for last post
            if pagename == env.blog_posts[0]:
                context["prev"] = None
            if pagename == env.blog_posts[-1]:
                context["next"] = None
        # if this is not documententation
        elif not (pagename.startswith("doc/") or pagename.startswith("docs/")):
            # no rellinks for non-posts/docs
            context["prev"], context["next"] = None, None

    # otherwise provide default metadata
    else:
        context["metadata"] = Metadata()
예제 #18
0
def add_metadata(app, pagename, context):
    '''
    Passes metadata to the templating engine.
    '''
    env = app.builder.env

    # page data
    context['website'] = app.config.website

    # blog tagline and pages
    context["tagline"] = app.config.tagline
    context["description"] = app.config.description
    context["pages"] = env.blog_page_list

    # set translation context variables
    context["text_recent_posts"] = UIStr.RECENT_POSTS
    context["text_posted_by"] = UIStr.POSTED_BY
    context["text_blog_archive"] = UIStr.BLOG_ARCHIVE
    context["text_filed_under"] = UIStr.FILED_UNDER
    context["text_tags"] = UIStr.TAGS
    context["text_tags_cloud"] = UIStr.TAGS_CLOUD
    context["text_categories"] = UIStr.CATEGORIES

    # recent posts
    context["recent"] = [(post, env.titles[post].astext()) for post
            in env.blog_posts[:20]]
    # 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"])
    categories = dict((c, 0) for c in env.filing["categories"])
    catlinks = dict([(c, name_from_title(c)) for c in env.filing["categories"]])
    for post in env.blog_posts:
        p = env.blog_metadata[post]
        for tag in p.filing["tags"]:
            tags[tag[1]] += 1
        for cat in p.filing["categories"]:
            categories[cat[1]] += 1
    context["tags"] = tags
    context["taglinks"] = taglinks
    context["categories"] = categories
    context["catlinks"] = catlinks

    # if there is metadata for the page, it is not an auto-generated one
    if pagename in env.blog_metadata:
        context["metadata"] = env.blog_metadata[pagename]

        # if this is a post
        if pagename in env.blog_posts:
            # save body
            env.blog_metadata[pagename].body = context["body"]

            # no prev link if first post, no next link for last post
            if pagename == env.blog_posts[0]:
                context["prev"] = None
            if pagename == env.blog_posts[-1]:
                context["next"] = None
        # if this is not documententation
        elif not (pagename.startswith("doc/") or pagename.startswith("docs/")):
            # no rellinks for non-posts/docs
            context["prev"], context["next"] = None, None

    # otherwise provide default metadata
    else:
        context["metadata"] = Metadata()