-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #415 from gratipay/renderers-more-data
Give more data to renderers
- Loading branch information
Showing
3 changed files
with
49 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
from aspen import json | ||
from aspen.renderers import Factory, Renderer | ||
|
||
|
||
def test_a_custom_renderer(harness): | ||
class TestRenderer(Renderer): | ||
|
||
def compile(self, *a): | ||
return self.raw.upper() | ||
|
||
def render_content(self, context): | ||
d = dict((k, v) for k, v in self.__dict__.items() if k[0] != '_') | ||
return json.dumps(d) | ||
|
||
class TestFactory(Factory): | ||
Renderer = TestRenderer | ||
|
||
def compile_meta(self, configuration): | ||
return 'foobar' | ||
|
||
website = harness.client.website | ||
website.renderer_factories['lorem'] = TestFactory(website) | ||
|
||
r = harness.simple("[---]\n[---] text/html via lorem\nLorem ipsum") | ||
d = json.loads(r.body) | ||
assert d['meta'] == 'foobar' | ||
assert d['raw'] == 'Lorem ipsum' | ||
assert d['media_type'] == 'text/html' | ||
assert d['offset'] == 2 | ||
assert d['compiled'] == 'LOREM IPSUM' |