Skip to content

Commit 6857c20

Browse files
authored
Merge pull request #54 from norm/fix-example-site
The command `flourish example` was both erroring out and creating an out-of-date example that didn't generate. This should fix both, and adds tests to ensure it doesn't easily happen again.
2 parents d5d30b5 + ecee4e6 commit 6857c20

13 files changed

Lines changed: 701 additions & 31 deletions

flourish/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ def __init__(
8080
self._rescan_sources()
8181

8282
filename = '%s/generate.py' % self.source_dir
83-
spec = importlib.util.spec_from_file_location("generate_module", filename)
83+
spec = importlib.util.spec_from_file_location(
84+
"generate_module",
85+
filename,
86+
)
8487
if spec is None:
8588
raise Flourish.RuntimeError(
8689
('The source directory "%s"'

flourish/command_line.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,12 @@ def create_example(args):
359359
generate(argparse.Namespace(
360360
source='source',
361361
templates='templates',
362+
fragments=None,
362363
output='output',
363364
action='generate',
364365
verbose=True,
366+
include_future=True,
367+
exclude_future=False,
365368
path=[],
366369
))
367370
print('Example site created: run "flourish preview --generate"')

flourish/examples.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
"""),
1515

1616
'source/generate.py': dedent("""\
17-
from flourish import helpers
18-
from flourish.generators import (
17+
from flourish.generators.base import (
1918
IndexGenerator,
20-
PageGenerator,
19+
SourceGenerator,
2120
)
2221
2322
@@ -28,32 +27,29 @@ class Homepage(IndexGenerator):
2827
2928
def global_context(self):
3029
return {
31-
'dates': helpers.all_valid_dates(self.flourish),
30+
'dates': self.publication_dates,
3231
}
3332
34-
GLOBAL_CONTEXT = global_context
3533
34+
GLOBAL_CONTEXT = global_context
3635
37-
SOURCE_URL = (
38-
'/#slug',
39-
PageGenerator.as_generator(),
40-
)
4136
42-
URLS = (
43-
(
44-
'/',
45-
'homepage',
46-
Homepage.as_generator()
37+
PATHS = (
38+
SourceGenerator(
39+
path='/#slug',
40+
name='source'
41+
),
42+
Homepage(
43+
path='/',
44+
name='homepage'
4745
),
48-
(
49-
'/#year/',
50-
'year-index',
51-
IndexGenerator.as_generator()
46+
IndexGenerator(
47+
path='/#year/',
48+
name='year-index'
5249
),
53-
(
54-
'/#year/#month',
55-
'month-index',
56-
IndexGenerator.as_generator()
50+
IndexGenerator(
51+
path='/#year/#month',
52+
name='month-index'
5753
),
5854
)
5955
"""),
@@ -248,10 +244,10 @@ def global_context(self):
248244
<ul>
249245
{% for year in global.dates %}
250246
<li>
251-
<a href='/{{year.year}}/'>{{year.year}}</a>:
247+
<a href='{{ path("year-index", year=year.year.year) }}'>{{year.year.year}}</a>:
252248
<ul>
253249
{% for month in year.months %}
254-
<li><a href='/{{year.year}}/{{month.month}}'>{{month.month}}</a></li>
250+
<li><a href='{{ path("month-index", year=year.year.year, month=month.month.month) }}'>{{month.month.strftime("%m")}}</a></li>
255251
{% endfor %}
256252
</ul>
257253
</li>
@@ -297,7 +293,7 @@ def global_context(self):
297293
{{page.published.strftime('%A %B %d, %Y')}}
298294
</time>
299295
{% endif %}
300-
<a href='{{page.url}}'>{{page.title}}</a>
296+
<a href='{{page.path}}'>{{page.title}}</a>
301297
</li>
302298
{% endfor %}
303299
</ul>

tests/compare_directories.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@ def setup_method(self, meth):
1111
def teardown_method(self, meth):
1212
rmtree(self.tempdir)
1313

14-
def compare_directories(self):
15-
tested_files = relative_list_of_files_in_directory(self.tempdir)
14+
def compare_directories(self, input_dir=None):
15+
if input_dir is None:
16+
input_dir = self.tempdir
17+
tested_files = relative_list_of_files_in_directory(input_dir)
1618
assert sorted(tested_files) == sorted(self.expected_files)
1719

1820
for filename in self.expected_files:
19-
self.compare_file(filename)
21+
self.compare_file(filename, input_dir=input_dir)
2022

21-
def compare_file(self, filename):
23+
def compare_file(self, filename, input_dir=None):
24+
if input_dir is None:
25+
input_dir = self.tempdir
2226
expected_file = '%s/%s' % (self.expected_directory, filename)
23-
tested_file = '%s/%s' % (self.tempdir, filename)
27+
tested_file = '%s/%s' % (input_dir, filename)
2428
with open(expected_file) as file:
2529
expected = file.read()
2630
with open(tested_file) as file:

tests/example/2016/06.html

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<html lang='en-GB'>
2+
<head>
3+
<meta charset='UTF-8'>
4+
<title></title>
5+
<link rel='stylesheet' href='/site.css'>
6+
</head>
7+
<body>
8+
9+
<header>
10+
11+
<p>
12+
<a href='/'>
13+
Your New Flourish Blog
14+
</a>
15+
</p>
16+
17+
18+
<nav>
19+
<ul>
20+
21+
<li>
22+
<a href='/2016/'>2016</a>:
23+
<ul>
24+
25+
<li><a href='/2016/06'>06</a></li>
26+
27+
<li><a href='/2016/07'>07</a></li>
28+
29+
</ul>
30+
</li>
31+
32+
</ul>
33+
</nav>
34+
</header>
35+
36+
37+
<div id='body'>
38+
39+
40+
<ul id='posts'>
41+
42+
<li>
43+
44+
<time datetime='2016-06-30T10:00:00Z'>
45+
Thursday June 30, 2016
46+
</time>
47+
48+
<a href='/editing-the-site'>Editing the site</a>
49+
</li>
50+
51+
<li>
52+
53+
<time datetime='2016-06-29T10:00:00Z'>
54+
Wednesday June 29, 2016
55+
</time>
56+
57+
<a href='/welcome'>Welcome to your new blog</a>
58+
</li>
59+
60+
</ul>
61+
62+
63+
</div>
64+
65+
<footer>
66+
<p>
67+
Copyright &copy; 2016 Your Name Goes Here.
68+
Site made <a href='http://withaflourish.net'>with a flourish</a>.
69+
</p>
70+
</footer>
71+
72+
</body>
73+
</html>

tests/example/2016/07.html

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<html lang='en-GB'>
2+
<head>
3+
<meta charset='UTF-8'>
4+
<title></title>
5+
<link rel='stylesheet' href='/site.css'>
6+
</head>
7+
<body>
8+
9+
<header>
10+
11+
<p>
12+
<a href='/'>
13+
Your New Flourish Blog
14+
</a>
15+
</p>
16+
17+
18+
<nav>
19+
<ul>
20+
21+
<li>
22+
<a href='/2016/'>2016</a>:
23+
<ul>
24+
25+
<li><a href='/2016/06'>06</a></li>
26+
27+
<li><a href='/2016/07'>07</a></li>
28+
29+
</ul>
30+
</li>
31+
32+
</ul>
33+
</nav>
34+
</header>
35+
36+
37+
<div id='body'>
38+
39+
40+
<ul id='posts'>
41+
42+
<li>
43+
44+
<time datetime='2016-07-01T10:00:00Z'>
45+
Friday July 01, 2016
46+
</time>
47+
48+
<a href='/adding-pages'>Adding pages</a>
49+
</li>
50+
51+
</ul>
52+
53+
54+
</div>
55+
56+
<footer>
57+
<p>
58+
Copyright &copy; 2016 Your Name Goes Here.
59+
Site made <a href='http://withaflourish.net'>with a flourish</a>.
60+
</p>
61+
</footer>
62+
63+
</body>
64+
</html>

tests/example/2016/index.html

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<html lang='en-GB'>
2+
<head>
3+
<meta charset='UTF-8'>
4+
<title></title>
5+
<link rel='stylesheet' href='/site.css'>
6+
</head>
7+
<body>
8+
9+
<header>
10+
11+
<p>
12+
<a href='/'>
13+
Your New Flourish Blog
14+
</a>
15+
</p>
16+
17+
18+
<nav>
19+
<ul>
20+
21+
<li>
22+
<a href='/2016/'>2016</a>:
23+
<ul>
24+
25+
<li><a href='/2016/06'>06</a></li>
26+
27+
<li><a href='/2016/07'>07</a></li>
28+
29+
</ul>
30+
</li>
31+
32+
</ul>
33+
</nav>
34+
</header>
35+
36+
37+
<div id='body'>
38+
39+
40+
<ul id='posts'>
41+
42+
<li>
43+
44+
<time datetime='2016-07-01T10:00:00Z'>
45+
Friday July 01, 2016
46+
</time>
47+
48+
<a href='/adding-pages'>Adding pages</a>
49+
</li>
50+
51+
<li>
52+
53+
<time datetime='2016-06-30T10:00:00Z'>
54+
Thursday June 30, 2016
55+
</time>
56+
57+
<a href='/editing-the-site'>Editing the site</a>
58+
</li>
59+
60+
<li>
61+
62+
<time datetime='2016-06-29T10:00:00Z'>
63+
Wednesday June 29, 2016
64+
</time>
65+
66+
<a href='/welcome'>Welcome to your new blog</a>
67+
</li>
68+
69+
</ul>
70+
71+
72+
</div>
73+
74+
<footer>
75+
<p>
76+
Copyright &copy; 2016 Your Name Goes Here.
77+
Site made <a href='http://withaflourish.net'>with a flourish</a>.
78+
</p>
79+
</footer>
80+
81+
</body>
82+
</html>

0 commit comments

Comments
 (0)