コード例 #1
0
ファイル: __init__.py プロジェクト: ryonsherman/noise
class Noise(object):
    def __init__(self, path):
        # initialize project path helper
        self.path = Path(path)

        # initialize project route helper
        self.route = Route(self)
        self.routes = {}

        # initialize template helper
        self.template = Template(self)

    def init(self):
        # initialize paths
        self.path.init()

        # create project init file
        path = self.path('__init__.py')
        if not os.path.exists(path):
            from noise.route import BOILERPLATE
            with open(path, 'w') as f:
                f.write(BOILERPLATE)

    def build(self):
        # clear build directory
        build_path = str(self.path.build)
        if os.path.exists(build_path):
            shutil.rmtree(build_path)
        # copy static contents to build path
        static_path = str(self.path.static)
        if os.path.exists(static_path):
            shutil.copytree(static_path, build_path)
        # recreate build directory
        else: os.mkdir(build_path)

        # iterate routes
        for route, page in self.routes.items():
            # build page if callback passed
            if type(page) is not Page:
                # save callback
                callback = page
                # initialize page object
                page = Page(self, route)
                # perform callback on page
                callback(page)
            # render page
            page.render()
コード例 #2
0
ファイル: __init__.py プロジェクト: ryonsherman/noise
    def __init__(self, path):
        # initialize project path helper
        self.path = Path(path)

        # initialize project route helper
        self.route = Route(self)
        self.routes = {}

        # initialize template helper
        self.template = Template(self)