Pagd

Template. Context. Page.

myblog – myblog layout engine

Module contents

class pagd.layouts.myblog.MyBlog(pa, *args, **kwargs)[source]

Bases: pluggdapps.plugin.Plugin

A layout plugin to generate personal blog sites. Support create, gen, newpage interfaces APIs for corresponding sub-commands.

create(**kwargs)[source]

Creates a new layout under sitepath. Uses the directory tree under pagd:layouts/myblog as a template for the new layout. Accepts the following variable while creating,

sitepath,
directory-path under which the new layout had to be created.
generate(buildtarget, **kwargs)[source]

Generate a static, personal blog site from the layout under sitepath. Note that previously a new-layout must have been created using this plugin and available under sitepath.

This method,

  • iterates over each page availabe under the source-layout,
  • gathers page contexts.
  • translates page content into html.
  • locate a template for the page and generate the html for page.

Refer to pages() method to know how pages are located under layout’s content-directory.

is_exist()[source]

padg.interfaces.ILayout.is_exist() interface method.

pagecontent(page)[source]

Pages are located based on filename, and the file extension is not used to differential pages. Hence there can be more than one file by same filename, like, _contents/hello-world.rst, _contents/hello-world.md. In such cases, all files will be considered as part of same page and translated to html based on the extension type.

Return a single element list of articles, each article as tuple. Refer to :class:Page class and its articles attribute to know its data-structure.

pagecontext(page)[source]

Gathers default context for page.

Default context is specified by one or more JSON files by name _context.json that is located under every sub-directory that leads to the page-content under layout’s content-directory. _context.json found one level deeper under content directory will override _context.json found in the upper levels.

Also, if a pagename has a corresponding JSON file, for eg, <layout>/_contents/path/hello-world.rst file has a corresponding <layout>/_contents/path/hello-world.json, it will be interepreted as the page’s context. This context will override all the default context.

If _xcontext attribute is found in a default context file, it will be interpreted as plugin name implementing IXContext interface. The plugin will be queried, instantiated, to fetch context information from external sources like database.

Finally last_modified time will be gathered from content-file’s mtime statistics.

pages()[source]

Individual pages are picked based on the relative directory path along with filenames. Note that file extensions are not used to differentite pages, they are only used to detect the file type and apply corresponding translation algorithm to get page’s html.

pagetemplate(page)[source]

For every page that pages() method iterates, a corresponding template file should be located. It is located by following steps.

  • if page’s context contain a template attribute, then its value is interpreted as the template file for page in asset specification format.
  • join the relative path of the page with _template sub-directory under the layout, and check whether a template file by pagename is available. For eg, if pagename is hello-world and its relative path is blog/2010, then a template file _templates/blog/2010/hello-world will be lookup. Note that the extensio of the template file is immaterial.
  • If both above steps have failed then will lookup for a _default template under each sub-directory leading to _templates/blog/2010/.

Table Of Contents

Related Topics

This Page