bookish.wiki package

Submodules

bookish.wiki.config module

class bookish.wiki.config.Config(root_path, defaults=None)

Bases: dict

from_envvar(variable_name, silent=False)

Loads a configuration from an environment variable pointing to a configuration file. This is basically just a shortcut with nicer error messages for this line of code:

app.config.from_pyfile(os.environ['YOURAPPLICATION_SETTINGS'])
Parameters:
  • variable_name – name of the environment variable
  • silent – set to True if you want silent failure for missing files.
Returns:

bool. True if able to load config, False otherwise.

from_json(filename, silent=False)

Updates the values in the config from a JSON file. This function behaves as if the JSON object was a dictionary and passed to the from_mapping() function. :param filename: the filename of the JSON file. This can either be an

absolute filename or a filename relative to the root path.
Parameters:silent – set to True if you want silent failure for missing files.

New in version 0.11.

from_mapping(*mapping, **kwargs)

Updates the config like update() ignoring items with non-upper keys. .. versionadded:: 0.11

from_object(obj)

Updates the values from the given object. An object can be of one of the following two types: - a string: in this case the object with that name will be imported - an actual object reference: that object is used directly Objects are usually either modules or classes. from_object() loads only the uppercase attributes of the module/class. A dict object will not work with from_object() because the keys of a dict are not attributes of the dict class. Example of module-based configuration:

app.config.from_object('yourapplication.default_config')
from yourapplication import default_config
app.config.from_object(default_config)

You should not use this function to load the actual configuration but rather configuration defaults. The actual config should be loaded with from_pyfile() and ideally from a location not within the package because the package might be installed system wide. See config-dev-prod for an example of class-based configuration using from_object(). :param obj: an import name or object

from_pyfile(filename, silent=False)

Updates the values in the config from a Python file. This function behaves as if the file was imported as module with the from_object() function. :param filename: the filename of the config. This can either be an

absolute filename or a filename relative to the root path.
Parameters:silent – set to True if you want silent failure for missing files.

New in version 0.7: silent parameter.

bookish.wiki.includes module

exception bookish.wiki.includes.CircularIncludeError

Bases: exceptions.Exception

bookish.wiki.includes.denull(blocks)
bookish.wiki.includes.get_finder(name, value)
bookish.wiki.includes.get_included(block, context, root)
bookish.wiki.includes.get_raw_source(block, context, root)
bookish.wiki.includes.load_include(block, context, root)
bookish.wiki.includes.load_include_impl(path, finder, key, unwrap, context, root)
bookish.wiki.includes.load_include_path(basepath, ref, context, root)
bookish.wiki.includes.make_include(ref, name=None, value=None, unwrap=None, retain=None, remove=None, newtype=None, newid=None)
bookish.wiki.includes.parse_include_path(incpath)
bookish.wiki.includes.spec_from_block(block, context)
bookish.wiki.includes.spec_from_path(basepath, ref)
bookish.wiki.includes.target(root, finder, unwrap)

bookish.wiki.langpaths module

bookish.wiki.langpaths.delang(path)

Takes a language-aware path (e.g. “/+en/foo/bar”) and returns the equivalent language-naive path (e.g. “/foo/bar”).

bookish.wiki.langpaths.enlang(name, path)

Takes a language name and a language-naive path (for example, “en” and “/foo/bar”) and returns the equivalent language-aware path (e.g. “/+en/foo/bar”).

bookish.wiki.langpaths.has_lang(path)
bookish.wiki.langpaths.is_lang_root(path)

Returns True if the given path refers to a language root (and NOT anything under the language root). For example “/+en” or “/+jp/”.

bookish.wiki.langpaths.lang_name(path)
bookish.wiki.langpaths.safe_delang(path)
bookish.wiki.langpaths.split_lang_and_path(path)

Takes a language-aware path and returns two strings: the language name and the language-naive path. For example, split_lang_and_path(“/+en/foo”) returns a tuple of “en” and “/foo”.

bookish.wiki.pipeline module

Bases: bookish.wiki.pipeline.LinkProcessor

Finds links in the content, looks up the linked document in the search index, and adds annotations to the link based on the linked document’s search fields.

add_attrs(*attrs)
default_attrs = ['title', 'type', 'icon', 'summary', 'container']
name = 'annotate'

Bases: bookish.wiki.pipeline.Processor

apply(block, context)
before = ('annotate',)
name = 'backlinks'
exception bookish.wiki.pipeline.CircularDependencyError

Bases: exceptions.Exception

class bookish.wiki.pipeline.DependencyGraph(vs=None)

Bases: object

add(v)
depends_on(v, prereq)
resolve(vs=None)
class bookish.wiki.pipeline.EmptyBlocks

Bases: bookish.wiki.pipeline.Processor

Removes blocks without any content. Ignores certain things.

apply(block, context)
name = 'empty'
class bookish.wiki.pipeline.Flow

Bases: bookish.wiki.pipeline.Processor

after = ('annotate',)
apply(block, context)
name = 'flow'
class bookish.wiki.pipeline.FullPaths

Bases: bookish.wiki.pipeline.LinkProcessor

Finds links in the content, and annotates them with the absolute path to the linked page.

name = 'fullpaths'
class bookish.wiki.pipeline.Groups(types=('bullet', 'ord', 'dt', 'item'), blacklist=('billboard', 'null'))

Bases: bookish.wiki.pipeline.Processor

Groups blocks of the same type “N” under “group_N” superblocks.

after = ('hierarchy', 'sections')
apply(block, context)
name = 'groups'
class bookish.wiki.pipeline.Hierarchy(attr='indent', default=0)

Bases: bookish.wiki.pipeline.Processor

Organizes a linear list of blocks into a hierarchy based on the relative values of a key (usually “indent”).

apply(block, context)
name = 'hierarchy'
class bookish.wiki.pipeline.Includes

Bases: bookish.wiki.pipeline.Processor

Finds include directives and replaces them with the included wiki content.

after = ('promote', 'properties')
apply(block, context)
name = 'includes'
class bookish.wiki.pipeline.JoinKeys

Bases: bookish.wiki.pipeline.TextModifier

Coalesces consecutive keys spans.

name = 'joinkeys'
text(text, context)
class bookish.wiki.pipeline.JoinText

Bases: bookish.wiki.pipeline.TextModifier

Joins adjacent runs of text together, so [“foo”, “bar”] becomes [“foobar”].

name = 'join'
text(text, context)
class bookish.wiki.pipeline.LinkProcessor

Bases: bookish.wiki.pipeline.Processor

Base class for processors of links.

apply(block, context, basepath=None)
text(context, text, basepath)
class bookish.wiki.pipeline.Metadata

Bases: bookish.wiki.pipeline.Processor

Adds some simple metadata to the JSON after it’s generated.

apply(block, context)
name = 'metadata'
class bookish.wiki.pipeline.Modifier

Bases: bookish.wiki.pipeline.Processor

A type of Processor that only modifies a single block at a time (that is, that doesn’t care about hierarchy). This allows them to be grouped together in a MultiModifier.

apply(block, context)
modify(block, context)
class bookish.wiki.pipeline.MultiModifier(modifiers)

Bases: bookish.wiki.pipeline.Processor

Processor that wraps multiple Modifier objects. This object walks the document tree and calls each modifier on each block.

add(modifier)
apply(block, context)
class bookish.wiki.pipeline.Parents

Bases: bookish.wiki.pipeline.Processor

Annotates the current document with information about its parent documents, including their subtopics, allowing the template to display things like breadcrumbs and a tree view.

apply(block, context)
static get_parent_path(pages, path, block)
name = 'parents'
static parent_info(prevpath, json, path)
class bookish.wiki.pipeline.Pipe(processors)

Bases: bookish.wiki.pipeline.Processor

Processor that wraps multiple processor objects and calls them each in turn.

add(other)
apply(block, context)
processor_by_class(cls)
class bookish.wiki.pipeline.Processor

Bases: object

Base class for objects that walk a document tree modifying the blocks in place.

add(other)
apply(block, context)
name = ''
class bookish.wiki.pipeline.Promote

Bases: bookish.wiki.pipeline.Processor

Finds blocks where a bit of xml or an include is the only thing in the block, and “promotes” that span up to block level.

apply(block, context)
name = 'promote'
class bookish.wiki.pipeline.Properties

Bases: bookish.wiki.pipeline.Processor

Changes “property” blocks into attributes on the parent block. Make sure this runs after Hierarchy.

after = ('sortheadings',)
apply(block, context)
name = 'properties'
class bookish.wiki.pipeline.RenumberHeadings

Bases: bookish.wiki.pipeline.Processor

Adds “level” keys to headings indicating their level in the heading hierarchy.

after = ('sortheadings', 'includes')
apply(block, context, level=2)
name = 'renumberheadings'
class bookish.wiki.pipeline.RunSearches

Bases: bookish.wiki.pipeline.Processor

Finds various items that run searches and replaces them with the search results.

apply(block, context, root=None)
default_fields = ['path', 'title', 'summary', 'type', 'icon', 'status', 'tags']
static get_results(block, context)
name = 'searches'
class bookish.wiki.pipeline.Sections

Bases: bookish.wiki.pipeline.Processor

Sets the “text” on sections if it wasn’t given, and changes the “type” of plain items inside a section to a type based on the section name. For example, a plain item inside a @properties section becomes type properties_item.

after = ('hierarchy',)
apply(block, context, itemtype=None)
name = 'sections'
class bookish.wiki.pipeline.Shortcuts

Bases: bookish.wiki.pipeline.TextModifier

Finds shortcuts and looks for a method corresponding to the shortcut’s scheme to process it. You must subclass this to get it to do anything.

name = 'shortcuts'
text(text, context)
class bookish.wiki.pipeline.SortHeadings

Bases: bookish.wiki.pipeline.Processor

Implements “linear” header style, where blocks simply come after headers at the same indent, instead of being indented under the heading. This processor looks for headings without bodies and pulls any subsequent blocks into them.

after = ('hierarchy', 'promote')
apply(block, context)
name = 'sortheadings'
class bookish.wiki.pipeline.Tables

Bases: bookish.wiki.pipeline.Processor

Because of the way simple tables are marked up, you end up with a cell block for each row, where each rightward cell is the only child of the cell to its left. This processor re-organizes this into a more render-friendly structure.

after = ('hierarchy',)
apply(block, context)
name = 'tables'
class bookish.wiki.pipeline.TextModifier

Bases: bookish.wiki.pipeline.Modifier

Special subclass of Modifier that only modifies text nodes.

modify(block, context)
text(text, context)
class bookish.wiki.pipeline.Title

Bases: bookish.wiki.pipeline.Processor

Finds the page title and summary blocks and copies their text up to the root for easier access by other code.

apply(block, context)
name = 'title'
class bookish.wiki.pipeline.Toc

Bases: bookish.wiki.pipeline.Processor

apply(block, context)
before = ('annotate',)
name = 'toc'
class bookish.wiki.pipeline.TreeProcessor

Bases: bookish.wiki.pipeline.Processor

Middle-ware for processors that might have to process every block in the tree. Does the work of traversing the tree, calling modify(block, context) at each block. If the modify method returns True, the processor recursively processes each child of the block.

apply(block, context)
modify(block, context)
bookish.wiki.pipeline.default_post_pipeline()
bookish.wiki.pipeline.default_pre_pipeline()
bookish.wiki.pipeline.make_pipeline(objs)

bookish.wiki.styles module

class bookish.wiki.styles.JinjaStoreLoader(store, prefix='/templates/')

Bases: jinja2.loaders.BaseLoader

Jinja template loader that loads templates from a Bookish storage object.

get_source(environment, template_path)

Get the template source, filename and reload helper for a template. It’s passed the environment and template name and has to return a tuple in the form (source, filename, uptodate) or raise a TemplateNotFound error if it can’t locate the template.

The source part of the returned tuple must be the source of the template as unicode string or a ASCII bytestring. The filename should be the name of the file on the filesystem if it was loaded from there, otherwise None. The filename is used by python for the tracebacks if no loader extension is used.

The last item in the tuple is the uptodate function. If auto reloading is enabled it’s always called to check if the template changed. No arguments are passed so the function must store the old state somewhere (for example in a closure). If it returns False the template will be reloaded.

list_templates(extensions=None, filter_func=None)

Iterates over all templates. If the loader does not support that it should raise a TypeError which is the default behavior.

class bookish.wiki.styles.Stylesheet(env, templatename, index_page_name)

Bases: object

context_and_function(basepath, jsondata, extras=None)

Returns a Jinja context function you can use to transform a JSON document using the rules contained in this style’s template.

static default_rule(jinctx, obj, render)
render(basepath, jsondata)

bookish.wiki.wikipages module

class bookish.wiki.wikipages.PageCache(cachedir)

Bases: object

cache_path(path)
delete_path(path)
empty()
ext = '.json'
get_cached_json(pages, sourcepath)
put_cache(cachepath, jsondata)
exception bookish.wiki.wikipages.ParserError

Bases: exceptions.Exception

exception bookish.wiki.wikipages.Redirect(newpath)

Bases: exceptions.Exception

class bookish.wiki.wikipages.WikiPages(store, jinja_env, config)

Bases: object

available_languages(path)
content(path, reformat=False, encoding='utf8')
context_from(wcontext, path, conditional=True, save_to_cache=True, searcher=None, extra_context=None)
enlang(path, lang=None)
etag(path, locale=None)
exists(path)
file_path(path)

Takes a virtual server path and translates it into a “real” file path, or None if the resource does not exist in a file.

find_source(path, locales=None)
full_path(origin, relpath)
html(path, stylename=None, templatename=None, language=None, conditional=True, save_to_cache=True, searcher=None, extras=None, allow_redirect=False)
is_index_page(path)
is_wiki(path)
is_wiki_source(path)
json(path, wcontext=None, conditional=True, process=True, postprocess=True, save_to_cache=True, extra_context=None, searcher=None, allow_redirect=False)
json_to_html(path, jsondata, stylename=None, templatename=None, extras=None, searcher=None)
last_modified(path)
page_lang(path)
preview(path, content, stylename=None, templatename=None, language=None, searcher=None, extras=None)
size(path)
source_path(path, locale=None)
string_to_json(path, content, wcontext=None, searcher=None, extras=None, postprocess=True, allow_redirect=False)
style(templatename)
wiki_context(path, conditional=True, save_to_cache=True, searcher=None, profiling=False)
bookish.wiki.wikipages.block(typename, indent, text, role=None, **kwargs)
bookish.wiki.wikipages.parse_to_blocklist(string)
bookish.wiki.wikipages.parse_to_root(string)
bookish.wiki.wikipages.remove_duplicates(ls)
bookish.wiki.wikipages.span(typename, text, **kwargs)

Module contents