示例#1
0
    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))
示例#2
0
    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))
示例#3
0
    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))
示例#4
0
 def test_valid_meta(self):
     filepath = '%s/about.md' % self.b.meta_path
     m = meta.Meta(filepath)
     self.assertEqual(True, m.valid)
示例#5
0
 def test_missing_title(self):
     filepath = '%s/missing-title.md' % self.b.meta_path
     m = meta.Meta(filepath)
     self.assertEqual(False, m.valid)
示例#6
0
 def test_bad_separator(self):
     filepath = '%s/bad-separator.md' % self.b.meta_path
     m = meta.Meta(filepath)
     self.assertEqual(False, m.valid)
示例#7
0
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)
示例#8
0
 def test_meta_root_slug(self):
     filepath = self.b.meta_path + '/home.md'
     m = meta.Meta(filepath)
     self.assertEqual(m.slug, '')
示例#9
0
 def test_meta_slug(self):
     filepath = self.b.meta_path + '/about.md'
     m = meta.Meta(filepath)
     self.assertEqual(m.slug, 'about')