Example #1
0
    def run(self):
        # parse data
        gists, pages = self._parse_gists()

        # index page
        try:
            os.mkdir(self.output_dir)
        except OSError as e:
            pass

        # template data for main index.html file
        tpl_data = {}
        tpl_data["site"] = self.site
        # use html pages
        tpl_data["pages"] = Builder.page_list(pages, self.base_url)
        tpl_data["gists"] = gists

        index_contents = self._render("base.html", tpl_data)
        index_file = os.path.join(self.output_dir, "index.html")
        self._save_file(index_file, index_contents)

        for title in pages:
            try:
                page_dir = os.path.join(self.output_dir, Builder.slugify(title))
                os.mkdir(page_dir)
            except OSError as e:
                pass

            tpl_data["gist"] = gists[title]
            tpl_data["title"] = title
            page_contents = self._render("page.html", tpl_data)
            page_file = os.path.join(page_dir, "index.html")
            self._save_file(page_file, page_contents)
Example #2
0
    def run(self):
        # parse data
        gists, pages = self._parse_gists()

        # index page
        try:
            os.mkdir(self.output_dir)
        except OSError as e:
            pass

        # template data for main index.html file
        tpl_data = {}
        tpl_data['site'] = self.site
        # use html pages
        tpl_data['pages'] = Builder.page_list(pages, self.base_url)
        tpl_data['gists'] = gists

        index_contents = self._render("base.html", tpl_data)
        index_file = os.path.join(self.output_dir, "index.html")
        self._save_file(index_file, index_contents)

        for title in pages:
            try:
                page_dir = os.path.join(self.output_dir,
                                        Builder.slugify(title))
                os.mkdir(page_dir)
            except OSError as e:
                pass

            tpl_data['gist'] = gists[title]
            tpl_data['title'] = title
            page_contents = self._render("page.html", tpl_data)
            page_file = os.path.join(page_dir, "index.html")
            self._save_file(page_file, page_contents)
Example #3
0
    def process(self):
        # parse data
        gists, pages = self._parse_gists()

        # index page
        try:
            os.mkdir(self.output_dir)
        except OSError as e:
            pass

        # global template data
        tpl_data = {}
        tpl_data['baseurl'] = self.base_url
        tpl_data['site'] = self.site

        # use html pages
        tpl_data['pages'] = Builder.page_list(pages, self.base_url)
        tpl_data['gists'] = gists

        index_contents = self._render("index.html", tpl_data)
        index_file = os.path.join(self.output_dir, "index.html")
        self._save_file(index_file, index_contents)

        for title in pages:
            try:
                page_dir = os.path.join(self.output_dir,
                                        Builder.slugify(title))
                os.mkdir(page_dir)
            except OSError as e:
                pass

            tpl_data['gist'] = gists[title]
            tpl_data['title'] = title
            page_contents = self._render("page.html", tpl_data)
            page_file = os.path.join(page_dir, "index.html")
            self._save_file(page_file, page_contents)

        # static template files, copy entire assets folder
        assets_src = os.path.join(self.template_dir, "assets")
        if os.path.exists(assets_src):
            assets_dest = os.path.join(self.output_dir, "assets")
            shutil.copytree(assets_src, assets_dest)
Example #4
0
    def _parse_gists(self):
        gists = {}
        pages = []

        for username, gist_dict in self.gists.items():
            for title, gist_id in gist_dict.items():
                user_gid = "/".join((username, gist_id))
                gists[title] = Builder.gist(user_gid)
                pages.append(title)

        return gists, sorted(pages)
Example #5
0
    def _parse_gists(self):
        gists = {}
        pages = []

        for username, gist_dict in self.gists.items():
            for title, gist_id in gist_dict.items():
                user_gid = "/".join((username, gist_id))
                gists[title] = Builder.gist(user_gid)
                pages.append(title)

        return gists, sorted(pages)
Example #6
0
    def process(self):
        # parse data
        gists, pages = self._parse_gists()

        # index page
        try:
            os.mkdir(self.output_dir)
        except OSError as e:
            pass

        # global template data
        tpl_data = {}
        tpl_data['baseurl'] = self.base_url
        tpl_data['site'] = self.site

        # use html pages
        tpl_data['pages'] = Builder.page_list(pages, self.base_url)
        tpl_data['gists'] = gists

        index_contents = self._render("index.html", tpl_data)
        index_file = os.path.join(self.output_dir, "index.html")
        self._save_file(index_file, index_contents)

        for title in pages:
            try:
                page_dir = os.path.join(self.output_dir, Builder.slugify(title))
                os.mkdir(page_dir)
            except OSError as e:
                pass

            tpl_data['gist'] = gists[title]
            tpl_data['title'] = title
            page_contents = self._render("page.html", tpl_data)
            page_file = os.path.join(page_dir, "index.html")
            self._save_file(page_file, page_contents)

        # static template files, copy entire assets folder
        assets_src = os.path.join(self.template_dir, "assets")
        if os.path.exists(assets_src):
            assets_dest = os.path.join(self.output_dir, "assets")
            shutil.copytree(assets_src, assets_dest)
Example #7
0
def test_gist():
    assert_equals(Builder.gist(100),
                  '<script src="https://gist.github.com/100.js"></script>')
Example #8
0
def test_page_list():
    assert_equals(Builder.page_list(['foo', 'bar']),
                  ['<a href="/foo">foo</a>', '<a href="/bar">bar</a>'])
Example #9
0
def test_slug_with_trailing_space():
    assert_equals(Builder.slugify('hello '), 'hello')
Example #10
0
def test_slug_with_multiple_dashes_and_spaces():
    assert_equals(Builder.slugify('hello- -world'), 'hello-world')
Example #11
0
def test_slug_with_spaces():
    assert_equals(Builder.slugify('hello world'),'hello-world')
Example #12
0
def test_slug_with_no_special_char():
    assert_equals(Builder.slugify('hello'), 'hello')
Example #13
0
def test_page_list_with_slug():
    assert_equals(Builder.page_list(['foo bar']),
                  ['<a href="/foo-bar">foo bar</a>'])