def test_vanilla_entry_markdown(self): filepath = '%s/vanilla.md' % self.b.entry_path e = entry.Entry(filepath) expected_markdown = ("\n\n### oh, memory\n\n" "it's a fickle thing.\n" "we should try to make it better..\n" "with *texts*.\n") self.assertEqual(expected_markdown, e.markdown)
def test_multiple_separators(self): # separators ('---') in the markdown should be allowed filepath = '%s/multiple-separators.md' % self.b.entry_path e = entry.Entry(filepath) expected_markdown = ("\n\n### oh, memory\n\n" "it's a fickle thing.\n" "we should try to make it better..\n" "with *texts*.\n" "---\n" "or maybe emails!\n") self.assertEqual(expected_markdown, e.markdown)
def test_unique_routes(self): source_path = 'bugle/tests/fixtures/unique-routes/' out_path = '' self.b = bugle.Bugle(source_path, out_path) entry_filepaths = self.b.discover_files(self.b.entry_path) entries = [entry.Entry(f) for f in entry_filepaths] meta_filepaths = self.b.discover_files(self.b.meta_path) meta_files = [meta.Meta(f) for f in meta_filepaths] self.assertTrue(self.b.verify_unique_routes(entries, meta_files))
def test_repeated_routes(self): # in this source, tags and entry titles overlap -- should fail source_path = 'bugle/tests/fixtures/nonunique-routes/' out_path = '' self.b = bugle.Bugle(source_path, out_path) entry_filepaths = self.b.discover_files(self.b.entry_path) entries = [entry.Entry(f) for f in entry_filepaths] meta_filepaths = self.b.discover_files(self.b.meta_path) meta_files = [meta.Meta(f) for f in meta_filepaths] self.assertFalse(self.b.verify_unique_routes(entries, meta_files))
def test_repeated_meta_and_entry_routes(self): # a meta file and an entry share a title -- should fail source_path = 'bugle/tests/fixtures/nonunique-routes-meta/' out_path = '' self.b = bugle.Bugle(source_path, out_path) entry_filepaths = self.b.discover_files(self.b.entry_path) entries = [entry.Entry(f) for f in entry_filepaths] meta_filepaths = self.b.discover_files(self.b.meta_path) meta_files = [meta.Meta(f) for f in meta_filepaths] self.assertFalse(self.b.verify_unique_routes(entries, meta_files))
def test_discover_tags(self): samples = ['uno.md', 'dos.md', 'tres.md'] filepaths = [os.path.join(self.b.entry_path, s) for s in samples] entries = [] for filepath in filepaths: entries.append(entry.Entry(filepath)) tags = self.b.compile_tags(entries) expected_tags = [{'count': 3, 'name': 'python'} , {'count': 3, 'name': 'twilio'} , {'count': 1, 'name': 'notes'} , {'count': 1, 'name': 'projects'}] self.assertEqual(tags, expected_tags)
def test_multiple_separators(self): # we should only look for the first instance of the separator # so multiple separators should be allowed filepath = '%s/multiple-separators.md' % self.b.entry_path e = entry.Entry(filepath) self.assertEqual(True, e.valid)
def test_empty_creation_time(self): filepath = '%s/empty-creation-time.md' % self.b.entry_path e = entry.Entry(filepath) self.assertEqual(False, e.valid)
def build(): b = bugle.Bugle(env.source_path, env.out_path) b.ensure_path_exists(b.out_path) # finds and instantiates entries entry_filepaths = b.discover_files(b.entry_path) entries = [entry.Entry(f) for f in entry_filepaths] for e in entries: if not e.valid: print 'validation failed for %s with message %s.' % ( e, e.validation_message) sys.exit() # find and instantiate meta files meta_filepaths = b.discover_files(b.meta_path) meta_files = [meta.Meta(f) for f in meta_filepaths] for m in meta_files: if not m.valid: print 'validation failed for %s with message %s.' % ( m, m.validation_message) sys.exit() # sort them by the slug meta_files.sort(key=lambda k: k.slug) # slugs from tags and entries should all be unique together if not b.verify_unique_routes(entries, meta_files): print 'paths not unique' sys.exit() # find all tags tags = b.compile_tags(entries) # copy over the css css_files = os.path.join(b.css_path, '*.css') css_out_path = os.path.join(b.out_path, 'css') b.ensure_path_exists(css_out_path) local('cp -L %s %s' % (css_files, css_out_path)) # copy over the js js_files = os.path.join(b.js_path, '*.js') js_out_path = os.path.join(b.out_path, 'js') b.ensure_path_exists(js_out_path) local('cp -L %s %s' % (js_files, js_out_path)) # render entry templates for e in entries: out_dir = os.path.join(b.out_path, e.slug) b.ensure_path_exists(out_dir) # create a jinja env and render the template environ = Environment(loader=FileSystemLoader(b.template_path)) template = environ.get_template('entry.html') html = template.render(entry=e, tags=tags, meta_files=meta_files) # write the page with open(os.path.join(out_dir, 'index.html'), 'w') as f: f.write(html) # render tag templates for tag in tags: tagged_entries = [] for e in entries: if tag['name'] in e.config['tags']: tagged_entries.append(e) # sort the entries by date tagged_entries.sort(key=lambda e: e.config['last_update'], reverse=True) # create a jinja env and render the template environ = Environment(loader=FileSystemLoader(b.template_path)) template = environ.get_template('tag.html') html = template.render(tags=tags, tag=tag['name'], entries=tagged_entries, meta_files=meta_files) # write the page tag_slug = tag['name'].replace(' ', '-') out_dir = os.path.join(b.out_path, tag_slug) b.ensure_path_exists(out_dir) with open(os.path.join(out_dir, 'index.html'), 'w') as f: f.write(html) # render the meta pages for m in meta_files: # create a jinja env and render the template environ = Environment(loader=FileSystemLoader(b.template_path)) template = environ.get_template('entry.html') html = template.render(entry=m, tags=tags, meta_files=meta_files, current_page=m.slug) # check for the root page if m.slug == '': out_dir = b.out_path else: # write the page out_dir = os.path.join(b.out_path, m.slug) b.ensure_path_exists(out_dir) # write the file with open(os.path.join(out_dir, 'index.html'), 'w') as f: f.write(html)
def test_missing_tags(self): filepath = '%s/missing-tags.md' % self.b.entry_path e = entry.Entry(filepath) self.assertEqual(False, e.valid)
def test_empty_tags(self): filepath = '%s/empty-tags.md' % self.b.entry_path e = entry.Entry(filepath) self.assertEqual(False, e.valid)
def test_bad_yaml(self): filepath = '%s/bad_yaml.md' % self.b.entry_path e = entry.Entry(filepath) self.assertEqual(False, e.valid)
def test_valid_entry(self): filepath = '%s/uno.md' % self.b.entry_path e = entry.Entry(filepath) self.assertEqual(True, e.valid)
def test_vanilla_entry_yaml(self): # confirm that yaml has been captured and is a dict filepath = '%s/vanilla.md' % self.b.entry_path e = entry.Entry(filepath) self.assertEqual(type(e.config), type({}))
def test_slug_override(self): filepath = self.b.entry_path + '/override.md' e = entry.Entry(filepath) self.assertEqual(e.slug, 'never-the-sms-time-capsule')
def test_improper_creation_time_formatting(self): filepath = ('%s/improper-creation-time-formatting.md' % self.b.entry_path) e = entry.Entry(filepath) self.assertFalse(e.valid)
def test_basic_slug(self): filepath = self.b.entry_path + '/basic.md' e = entry.Entry(filepath) self.assertEqual(e.slug, 'sms-time-capsule')
def test_tag_with_dash(self): filepath = '%s/tags-with-dash.md' % self.b.entry_path e = entry.Entry(filepath) expected_tags = ['python-sorta', 'twilio'] self.assertTrue(e.valid and e.config['tags'] == expected_tags)
def test_tag_with_space(self): filepath = '%s/tags-with-space.md' % self.b.entry_path e = entry.Entry(filepath) expected_tags = ['python and stuff', 'twilio'] self.assertTrue(e.valid and e.config['tags'] == expected_tags)
def test_tag_with_punctuation(self): filepath = '%s/tags-with-punctuation.md' % self.b.entry_path e = entry.Entry(filepath) self.assertEqual(False, e.valid)
def test_slug_with_khmer(self): filepath = self.b.entry_path + '/khmer.md' e = entry.Entry(filepath) self.assertEqual(e.slug, 'khemrbhaasaa')
def test_slug_with_maths(self): filepath = self.b.entry_path + '/maths.md' e = entry.Entry(filepath) self.assertEqual(e.slug, 'lambda-is-difficult')
def test_improper_update_time_formatting(self): filepath = '%s/improper-update-time-formatting.md' % self.b.entry_path e = entry.Entry(filepath) self.assertFalse(e.valid)
def test_slug_with_punctuation(self): filepath = self.b.entry_path + '/punctuation.md' e = entry.Entry(filepath) self.assertEqual(e.slug, 'never-an-sms-time-capsule')
def test_markdown_rendering(self): filepath = '%s/vanilla.md' % self.b.entry_path e = entry.Entry(filepath) self.assertIn('<h3>', e.rendered_markdown)
def test_no_separator(self): filepath = '%s/no_separator.md' % self.b.entry_path e = entry.Entry(filepath) self.assertEqual(False, e.valid)