-
Notifications
You must be signed in to change notification settings - Fork 1
Freezing Documents
The HTME library is designed around the assumption that you will define you documents in an otherwise empty module, then import your docs from that module into any modules that need them. HTME supports freezing documents to assist with this workflow.
Once you have created an empty module, you will want to start with something like this (note that we normally use docs
(plural), not doc
(singular) to refer to the engine instance:
from htme import *
docs = Engine(favicon="/static/favicon.png")
Note: Importing everything from htme
provides the core runtime, and all of the example code in this document will then work as it is written.
With everything initialised, you can now start hacking on the engine to get it into the correct state. Once you have something you want to use, you can freeze the document using a key (a string which is used to reference the frozen doc later):
docs.freeze("404 Error")
Freezing a doc converts it into a string of HTML, then stashes it in a dictionary (the engine’s freezer
attribute).
Once your doc is frozen, you can continue mutating the engine to represent a different document, which can then be frozen with a different key. The freezer gives you a convenient place to store your documents, and makes it possible to later import many documents with one line of code:
from <docs module> import docs
Freezers also make it possible to generate sets of similar pages with very little extra work (often in a simple loop, as shown in the Complete Example in the wiki).
Note: Each element also has a freezer, which has exactly the same API as the engine freezer (storing the current state of the element as HTML).
HTME | The Hypertext Markup Engine | Simple, Pythonic HTML Code Generation for Python 2 or 3
To learn to use HTME, read these articles (in this order):