-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexer.py
38 lines (27 loc) · 1.14 KB
/
indexer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
from composer.index import Index, Route, Static
from composer.filters import Mako, MakoContainer
class UntaritIndex(Index):
def _register_filters(self):
self.register_filter('mako', Mako, {'directories': ['templates']})
self.register_filter('filetype', MakoContainer, {'directories': ['templates'], 'template': 'filetype.mako'})
def _generate_static(self):
yield Static('/static', 'static')
def _generate_routes(self):
# TODO: Pull this from a yaml file or something
known_types = ['tar.gz', 'tar.bz2']
yield Route('/', 'templates/index.mako', filters=['mako'], context={
'known_types': known_types,
})
for filetype in known_types:
url = self.absolute_url(filetype + '/')
context = {
'filetype': filetype,
'known_types': known_types,
}
yield Route(url, 'templates/filetype.mako', filters=['filetype'], context=context)
if __name__ == '__main__':
import json
import os
index = UntaritIndex(os.path.dirname(__file__))
print json.dumps(index.to_dict(), indent=4)