コード例 #1
0
ファイル: test_db.py プロジェクト: uniteddiversity/lektor
def test_root_pagination(scratch_project, scratch_env):
    base = scratch_project.tree
    with open(os.path.join(base, "models", "page.ini"), "w") as f:
        f.write("[model]\n"
                "label = {{ this.title }}\n\n"
                "[children]\n"
                "model = page\n"
                "[pagination]\n"
                "enabled = yes\n"
                "per_page = 1\n"
                "[fields.title]\n"
                "type = string\n"
                "[fields.body]\n"
                "type = markdown\n")

    for name in "a", "b", "c":
        os.mkdir(os.path.join(base, "content", name))
        with open(os.path.join(base, "content", name, "contents.lr"),
                  "w") as f:
            f.write("_model: page\n"
                    "---\n"
                    "title: Page %s\n"
                    "---\n"
                    "body: Hello World!\n" % name)

    scratch_pad = Database(scratch_env).new_pad()

    root = scratch_pad.root
    assert root.children.count() == 3

    root_1 = scratch_pad.resolve_url_path("/")
    assert root_1.page_num == 1

    root_2 = scratch_pad.resolve_url_path("/page/2/")
    assert root_2.page_num == 2
コード例 #2
0
def test_default_order_by(scratch_project, scratch_env):
    from lektor.db import Database

    tree = scratch_project.tree
    with open(os.path.join(tree, 'models', 'mymodel.ini'), 'w') as f:
        f.write(
            '[children]\n'
            'order_by = title\n'
            '[attachments]\n'
            'order_by = attachment_filename\n'
            )
    os.mkdir(os.path.join(tree, 'content', 'myobj'))
    with open(os.path.join(tree, 'content', 'myobj', 'contents.lr'), 'w') as f:
        f.write(
            '_model: mymodel\n'
            '---\n'
            'title: My Test Object\n'
            )

    pad = Database(scratch_env).new_pad()
    myobj = pad.get('/myobj')
    children = myobj.children
    assert list(children.get_order_by()) == ['title']
    assert list(children.order_by('explicit').get_order_by()) == ['explicit']
    assert list(myobj.attachments.get_order_by()) == ['attachment_filename']
コード例 #3
0
ファイル: test_db.py プロジェクト: sunliwen/lektor
def test_default_order_by(scratch_project, scratch_env):
    from lektor.db import Database

    tree = scratch_project.tree
    with open(os.path.join(tree, 'models', 'mymodel.ini'), 'w') as f:
        f.write(
            '[children]\n'
            'order_by = title\n'
            '[attachments]\n'
            'order_by = attachment_filename\n'
            )
    os.mkdir(os.path.join(tree, 'content', 'myobj'))
    with open(os.path.join(tree, 'content', 'myobj', 'contents.lr'), 'w') as f:
        f.write(
            '_model: mymodel\n'
            '---\n'
            'title: My Test Object\n'
            )

    pad = Database(scratch_env).new_pad()
    myobj = pad.get('/myobj')
    children = myobj.children
    assert list(children.get_order_by()) == ['title']
    assert list(children.order_by('explicit').get_order_by()) == ['explicit']
    assert list(myobj.attachments.get_order_by()) == ['attachment_filename']
コード例 #4
0
ファイル: devserver.py プロジェクト: jab/lektor
 def build(self):
     try:
         db = Database(self.env, lang=self.lang)
         builder = Builder(db.new_pad(), self.output_path)
         builder.build_all()
     except Exception:
         traceback.print_exc()
     else:
         self.last_build = time.time()
コード例 #5
0
ファイル: devserver.py プロジェクト: jab/lektor
 def build(self):
     try:
         db = Database(self.env, lang=self.lang)
         builder = Builder(db.new_pad(), self.output_path)
         builder.build_all()
     except Exception:
         traceback.print_exc()
     else:
         self.last_build = time.time()
コード例 #6
0
ファイル: devserver.py プロジェクト: RonnyPfannschmidt/lektor
 def build(self, update_source_info_first=False):
     try:
         db = Database(self.env)
         builder = Builder(db.new_pad(), self.output_path)
         if update_source_info_first:
             builder.update_all_source_infos()
         builder.build_all()
         builder.prune()
     except Exception:
         traceback.print_exc()
     else:
         self.last_build = time.time()
コード例 #7
0
 def build(self, update_source_info_first=False):
     try:
         db = Database(self.env)
         builder = Builder(db.new_pad(), self.output_path,
                           build_flags=self.build_flags)
         if update_source_info_first:
             builder.update_all_source_infos()
         builder.build_all()
         if self.prune:
             builder.prune()
     except Exception:
         traceback.print_exc()
     else:
         self.last_build = time.time()
コード例 #8
0
def child_sources_test_project_builder(tmpdir):
    project = Project.from_path(
        os.path.join(os.path.dirname(__file__), "child-sources-test-project"))
    env = Environment(project)
    pad = Database(env).new_pad()

    return Builder(pad, str(tmpdir.mkdir("output")))
コード例 #9
0
 def setUp(self):
     self.project = Project.from_path(
         os.path.join(os.path.dirname(__file__), 'demo-project'))
     self.env = Environment(self.project)
     self.pad = Database(self.env).new_pad()
     self.out = tempfile.mkdtemp()
     self.builder = Builder(self.pad, self.out)
コード例 #10
0
def get_unicode_builder(tmpdir):
    proj = Project.from_path(
        os.path.join(os.path.dirname(__file__), u"ünicöde-project"))
    env = Environment(proj)
    pad = Database(env).new_pad()

    return pad, Builder(pad, str(tmpdir.mkdir("output")))
コード例 #11
0
ファイル: test_db.py プロジェクト: uniteddiversity/lektor
def test_default_order_by(scratch_project, scratch_env):
    tree = scratch_project.tree
    with open(os.path.join(tree, "models", "mymodel.ini"), "w") as f:
        f.write("[children]\n"
                "order_by = title\n"
                "[attachments]\n"
                "order_by = attachment_filename\n")
    os.mkdir(os.path.join(tree, "content", "myobj"))
    with open(os.path.join(tree, "content", "myobj", "contents.lr"), "w") as f:
        f.write("_model: mymodel\n" "---\n" "title: My Test Object\n")

    pad = Database(scratch_env).new_pad()
    myobj = pad.get("/myobj")
    children = myobj.children
    assert list(children.get_order_by()) == ["title"]
    assert list(children.order_by("explicit").get_order_by()) == ["explicit"]
    assert list(myobj.attachments.get_order_by()) == ["attachment_filename"]
コード例 #12
0
ファイル: conftest.py プロジェクト: tumregels/lektor
def child_sources_test_project_builder(request):
    from lektor.db import Database
    from lektor.environment import Environment
    from lektor.project import Project

    project = Project.from_path(
        os.path.join(os.path.dirname(__file__), 'child-sources-test-project'))
    env = Environment(project)
    pad = Database(env).new_pad()

    return make_builder(request, pad)
コード例 #13
0
ファイル: conftest.py プロジェクト: sambacha/tor-styleguide
def child_sources_test_project_builder(tmpdir):
    from lektor.db import Database
    from lektor.environment import Environment
    from lektor.project import Project
    from lektor.builder import Builder

    project = Project.from_path(
        os.path.join(os.path.dirname(__file__), 'child-sources-test-project'))
    env = Environment(project)
    pad = Database(env).new_pad()

    return Builder(pad, str(tmpdir.mkdir("output")))
コード例 #14
0
def get_unicode_builder(tmpdir):
    from lektor.project import Project
    from lektor.environment import Environment
    from lektor.db import Database
    from lektor.builder import Builder

    proj = Project.from_path(os.path.join(os.path.dirname(__file__),
                                          u'ünicöde-project'))
    env = Environment(proj)
    pad = Database(env).new_pad()

    return pad, Builder(pad, str(tmpdir.mkdir('output')))
コード例 #15
0
def test_root_pagination(scratch_project, scratch_env):
    base = scratch_project.tree
    with open(os.path.join(base, 'models', 'page.ini'), 'w') as f:
        f.write(
            '[model]\n'
            'label = {{ this.title }}\n\n'
            '[children]\n'
            'model = page\n'
            '[pagination]\n'
            'enabled = yes\n'
            'per_page = 1\n'
            '[fields.title]\n'
            'type = string\n'
            '[fields.body]\n'
            'type = markdown\n'
        )

    for name in 'a', 'b', 'c':
        os.mkdir(os.path.join(base, 'content', name))
        with open(os.path.join(base, 'content', name, 'contents.lr'), 'w') as f:
            f.write(
                '_model: page\n'
                '---\n'
                'title: Page %s\n'
                '---\n'
                'body: Hello World!\n' % name
            )

    from lektor.db import Database
    scratch_pad = Database(scratch_env).new_pad()

    root = scratch_pad.root
    assert root.children.count() == 3

    root_1 = scratch_pad.resolve_url_path('/')
    assert root_1.page_num == 1

    root_2 = scratch_pad.resolve_url_path('/page/2/')
    assert root_2.page_num == 2
コード例 #16
0
ファイル: test_db.py プロジェクト: doobeh/lektor
def test_root_pagination(scratch_project, scratch_env):
    base = scratch_project.tree
    with open(os.path.join(base, 'models', 'page.ini'), 'w') as f:
        f.write(
            '[model]\n'
            'label = {{ this.title }}\n\n'
            '[children]\n'
            'model = page\n'
            '[pagination]\n'
            'enabled = yes\n'
            'per_page = 1\n'
            '[fields.title]\n'
            'type = string\n'
            '[fields.body]\n'
            'type = markdown\n'
        )

    for name in 'a', 'b', 'c':
        os.mkdir(os.path.join(base, 'content', name))
        with open(os.path.join(base, 'content', name, 'contents.lr'), 'w') as f:
            f.write(
                '_model: page\n'
                '---\n'
                'title: Page %s\n'
                '---\n'
                'body: Hello World!\n' % name
            )

    from lektor.db import Database
    scratch_pad = Database(scratch_env).new_pad()

    root = scratch_pad.root
    assert root.children.count() == 3

    root_1 = scratch_pad.resolve_url_path('/')
    assert root_1.page_num == 1

    root_2 = scratch_pad.resolve_url_path('/page/2/')
    assert root_2.page_num == 2
コード例 #17
0
def demo_output(site_path, my_plugin_id, my_plugin_cls, tmp_path_factory):
    """ Build the demo site.

    Return path to output directory.

    """
    project = Project.from_path(str(site_path))
    env = Environment(project, load_plugins=False)

    # Load our plugin
    env.plugin_controller.instanciate_plugin(my_plugin_id, my_plugin_cls)
    env.plugin_controller.emit('setup-env')

    pad = Database(env).new_pad()
    output_path = tmp_path_factory.mktemp('demo-site')
    builder = Builder(pad, str(output_path))
    with CliReporter(env):
        failures = builder.build_all()
        assert failures == 0
    return output_path
コード例 #18
0
 def new_pad(self):
     """Convenience function to create a database and pad."""
     from lektor.db import Database
     return Database(self).new_pad()
コード例 #19
0
def pntest_pad(request, pntest_env):
    return Database(pntest_env).new_pad()
コード例 #20
0
ファイル: devserver.py プロジェクト: vinodpanicker/lektor
 def get_pad(self):
     db = Database(self.env)
     pad = db.new_pad()
     return pad
コード例 #21
0
    def new_pad(self):
        """Convenience function to create a database and pad."""
        from lektor.db import Database  # pylint: disable=import-outside-toplevel

        return Database(self).new_pad()
コード例 #22
0
 def get_pad(self):
     return Database(self.env, lang=self.lang).new_pad()
コード例 #23
0
ファイル: devserver.py プロジェクト: jab/lektor
 def get_pad(self):
     db = Database(self.env, lang=self.lang)
     pad = db.new_pad()
     return pad
コード例 #24
0
def pntest_pad(request, pntest_env):
    from lektor.db import Database

    return Database(pntest_env).new_pad()
コード例 #25
0
 def get_pad(self):
     return Database(self.env).new_pad()
コード例 #26
0
ファイル: conftest.py プロジェクト: sambacha/tor-styleguide
def pad(env):
    from lektor.db import Database
    return Database(env).new_pad()
コード例 #27
0
ファイル: cli.py プロジェクト: jab/lektor
 def new_pad(self):
     from lektor.db import Database
     env = self.get_env()
     return Database(env).new_pad()
コード例 #28
0
ファイル: test_db.py プロジェクト: turalaksel/lektor
def test_Database_iter_items_invalid_path(env):
    # Check that there is no problem with uncaught
    # OSError(errno=EINVAL) when a path contains non-filename-safe
    # characters in Database.iter_items.
    db = Database(env)
    assert len(list(db.iter_items("/<foo>"))) == 0
コード例 #29
0
def scratch_pad(scratch_env):
    return Database(scratch_env).new_pad()
コード例 #30
0
ファイル: devserver.py プロジェクト: jab/lektor
 def get_pad(self):
     db = Database(self.env, lang=self.lang)
     pad = db.new_pad()
     return pad
コード例 #31
0
ファイル: conftest.py プロジェクト: sambacha/tor-styleguide
def scratch_pad(scratch_env):
    from lektor.db import Database
    return Database(scratch_env).new_pad()
コード例 #32
0
ファイル: test_themes.py プロジェクト: turalaksel/lektor
def theme_pad(theme_env):

    return Database(theme_env).new_pad()
コード例 #33
0
def theme_pad(theme_env):
    from lektor.db import Database

    return Database(theme_env).new_pad()
コード例 #34
0
def pad(env):
    return Database(env).new_pad()