calingen.contrib.compilers.html_or_download.compiler

The actual implementation of the compiler.

This is a simple extension of calingen.contrib.compilers.download.compiler.DownloadCompiler that serves HTML-based content directly.

Module Contents

Classes

HtmlOrDownloadCompiler

Provide an HTTP response, if the layout renders to HTML or a file download otherwise.

Attributes

SOURCE_TYPE_LOOKUP

A dict that provides meta information for file downloads.

class calingen.contrib.compilers.html_or_download.compiler.HtmlOrDownloadCompiler

Bases: calingen.interfaces.plugin_api.CompilerProvider

Provide an HTTP response, if the layout renders to HTML or a file download otherwise.

title = HtmlOrDownloadCompiler
classmethod get_response(source, layout_type=None)

Get the compiler’s HTTP response.

This is the compiler’s main interface to other components of the app.

It should be used to actually trigger the compilation of the provided source and then return a valid Django Response object.

Parameters:

source (str) – The source as provided by LayoutProvider.render().

Return type:

Django Response object

Notes

This method is called from CompilerView's get() method with an additional keyword argument layout_type, exposing the layout_type attribute of the layout.

calingen.contrib.compilers.html_or_download.compiler.SOURCE_TYPE_LOOKUP

A dict that provides meta information for file downloads.

The get_response() uses this dict to determine the file extension and MIME type for the download, based on the layout’s layout_type attribute (see calingen.interfaces.plugin_api.LayoutProvider).