annotate piecrust/formatting/textileformatter.py @ 182:a54d3c0b5f4a

tests: Patch `os.path.exists` and improve patching for `open`. You can specify additional modules for which to patch `open`. Also, it was incorrectly updating the opened file, even when it was opened for read only. Now it only updates the contents if the file was opened for write, and supports appending to the end. Last, it supports opening text files in binary mode.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 04 Jan 2015 14:55:41 -0800
parents f49fcf9448df
children f4f5685019a2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
124
f49fcf9448df Add Textile formatter.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 from textile import textile
f49fcf9448df Add Textile formatter.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 from piecrust.formatting.base import Formatter
f49fcf9448df Add Textile formatter.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3
f49fcf9448df Add Textile formatter.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
f49fcf9448df Add Textile formatter.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 class TextileFormatter(Formatter):
f49fcf9448df Add Textile formatter.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 FORMAT_NAMES = ['textile', 'text']
f49fcf9448df Add Textile formatter.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 OUTPUT_FORMAT = 'html'
f49fcf9448df Add Textile formatter.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8
f49fcf9448df Add Textile formatter.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 def render(self, format_name, text):
f49fcf9448df Add Textile formatter.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 assert format_name in self.FORMAT_NAMES
f49fcf9448df Add Textile formatter.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 return textile(text)
f49fcf9448df Add Textile formatter.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12