Skip to content

Commit f4e80ce

Browse files
Initial commit
0 parents  commit f4e80ce

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

index_generator/__init__.py

Whitespace-only changes.

index_generator/__main__.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
# *-- coding: utf-8 --*
3+
import sys
4+
5+
import jinja2
6+
import argparse
7+
8+
9+
def main():
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument('--version', '-V', action='store_true', default=False,
12+
help='Print version infomation and quit.')
13+
parser.add_argument('--template', '-t', type=str, default='templates/default',
14+
help='Select template to generate html.')
15+
parser.add_argument('--no-recursive', action='store_true', default=False, help='Do not generate recursively.')
16+
parser.add_argument('--name', '-n', type=str, default='index.html',
17+
help='Default output filename.')
18+
parser.add_argument('--print', '-p', action='store_true', default=False, help='Whether to print to stdout.')
19+
arguments = parser.parse_args(sys.argv[1:])
20+
21+
22+
def generate(templateDir):
23+
environment = jinja2.Environment(
24+
loader=jinja2.PackageLoader('index_generator', templateDir),
25+
autoescape=jinja2.select_autoescape(['html', 'htm'])
26+
)
27+
template = environment.get_template('index.html')
28+
print(template.render(ig={
29+
'currentPath': '/example',
30+
'files': [
31+
{
32+
'name': 'test.txt',
33+
'modified': '-',
34+
'size': '12'
35+
}
36+
]
37+
}))
38+
39+
40+
if __name__ == '__main__':
41+
main()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{% extends "layout.html" %}
2+
{% block extra %}
3+
<style>
4+
body { background-color: #F8F8F8; }
5+
</style>
6+
{% endblock %}
7+
{% block files %}
8+
<table>
9+
<col width="800">
10+
<col width="200">
11+
<col width="80">
12+
<tr>
13+
<th align="left">Filename</th>
14+
<th align="left">Last modified</th>
15+
<th align="left">Size</th>
16+
</tr>
17+
{% for file in ig.files %}
18+
<tr>
19+
<td><a href="#">{{ file.name }}</a></td>
20+
<td>{{ file.modified }}</td>
21+
<td>{{ file.size }}</td>
22+
</tr>
23+
{% endfor %}
24+
</table>
25+
{% endblock %}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>{% block title %}Files: {{ ig.currentPath }}{% endblock %}</title>
6+
{% block extra %}{% endblock %}
7+
</head>
8+
<body>
9+
{% block head %}
10+
<h1>Index of {{ ig.currentPath }}</h1>
11+
<hr>
12+
{% block files %}
13+
{% endblock %}
14+
<hr>
15+
{% endblock %}
16+
<div>{% block footer %}Generated by index-generator.{% endblock %}</div>
17+
</body>
18+
</html>

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Jinja2

0 commit comments

Comments
 (0)