当前位置: 首页>>代码示例>>Python>>正文


Python FlatPages.get方法代码示例

本文整理汇总了Python中flask_flatpages.FlatPages.get方法的典型用法代码示例。如果您正苦于以下问题:Python FlatPages.get方法的具体用法?Python FlatPages.get怎么用?Python FlatPages.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask_flatpages.FlatPages的用法示例。


在下文中一共展示了FlatPages.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_basic

# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
    def test_basic(self):
        pages = FlatPages(Flask(__name__))

        hello = pages.get('headerid')
        self.assertEqual(
            hello.html,
            u'<h1>Page Header</h1>\n<h2>Paragraph Header</h2>\n<p>Text</p>'
        )

        pages.app.config['FLATPAGES_MARKDOWN_EXTENSIONS'] = []
        pages.reload()
        pages._file_cache = {}

        hello = pages.get('headerid')
        self.assertEqual(
            hello.html,
            u'<h1>Page Header</h1>\n<h2>Paragraph Header</h2>\n<p>Text</p>'
        )

        pages.app.config['FLATPAGES_MARKDOWN_EXTENSIONS'] = [
            'codehilite', 'headerid'
        ]
        pages.reload()
        pages._file_cache = {}

        hello = pages.get('headerid')
        self.assertEqual(
            hello.html,
            '<h1 id="page-header">Page Header</h1>\n'
            '<h2 id="paragraph-header">Paragraph Header</h2>\n'
            '<p>Text</p>'
        )
开发者ID:danielgloven,项目名称:Flask-FlatPages,代码行数:34,代码来源:test_markdown_extensions.py

示例2: test_other_html_renderer

# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
    def test_other_html_renderer(self):
        def body_renderer(body):
            return body.upper()

        def page_renderer(body, pages, page):
            return page.body.upper()

        def pages_renderer(body, pages):
            return pages.get('hello').body.upper()

        renderers = filter(None, (
            operator.methodcaller('upper'),
            'string.upper' if not compat.IS_PY3 else None,
            body_renderer,
            page_renderer,
            pages_renderer
        ))

        for renderer in (renderers):
            pages = FlatPages(Flask(__name__))
            pages.app.config['FLATPAGES_HTML_RENDERER'] = renderer
            hello = pages.get('hello')
            self.assertEqual(hello.body, u'Hello, *世界*!\n')
            # Upper-case, markdown not interpreted
            self.assertEqual(hello.html, u'HELLO, *世界*!\n')
开发者ID:SimonSapin,项目名称:Flask-FlatPages,代码行数:27,代码来源:test_flask_flatpages.py

示例3: TestFlatPagesPandoc

# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
class TestFlatPagesPandoc(unittest.TestCase):
    def setUp(self):
        self.tmp = mkdtemp()
        self.content = os.path.join(self.tmp, "content")
        os.makedirs(self.content)

        self.app = Flask(__name__)
        self.app.config.update(
            FLATPAGES_ROOT=self.content,
            FLATPAGES_ENCODING="utf-8",
            FLATPAGES_AUTO_RELOAD=True,
        )
        self.pages = FlatPages(self.app)
        FlatPagesPandoc("markdown", self.app, pre_render=False)

    def tearDown(self):
        rmtree(self.tmp)

    def get(self, body, ext=".md", enc="utf-8"):
        self.app.config.update(FLATPAGES_EXTENSION=ext)
        with open(os.path.join(self.content, "test" + ext), "w", enc) as f:
            f.write(u"title:test\n\n" + body)
        return self.pages.get("test").html

    def test_h1(self):
        self.assertEqual(self.get("# test"), '<h1 id="test">test</h1>\n')

    def test_unicode(self):
        self.assertEqual(self.get(u"萬大事都有得解決"), u"<p>萬大事都有得解決</p>\n")

    def test_unicode2(self):
        self.app.config.update(FLATPAGES_ENCODING="iso-8859-15")
        self.assertEqual(self.get(u"äöü", enc="iso-8859-15"), u"<p>äöü</p>\n")
开发者ID:fhirschmann,项目名称:Flask-FlatPages-Pandoc,代码行数:35,代码来源:tests.py

示例4: test_html_conversion

# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
 def test_html_conversion(self):
     pages = FlatPages(Flask(__name__))
     foo = pages.get("foo")
     print "we get here"
     print foo["description_html"]
     self.assertTrue(True)
     self.assertEquals(foo["description"].strip(), '# hello')
     self.assertEquals(foo["description_html"], '<h1>hello</h1>')
开发者ID:fredkingham,项目名称:Flask-FlatPages,代码行数:10,代码来源:tests.py

示例5: test_other_html_renderer

# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
 def test_other_html_renderer(self):
     for renderer in (unicode.upper, 'string.upper'):
         pages = FlatPages(Flask(__name__))
         pages.app.config['FLATPAGES_HTML_RENDERER'] = renderer
         hello = pages.get('hello')
         self.assertEquals(hello.body, u'Hello, *世界*!\n')
         # Upper-case, markdown not interpreted
         self.assertEquals(hello.html, u'HELLO, *世界*!\n')
开发者ID:AleksandarMicovic,项目名称:Flask-FlatPages,代码行数:10,代码来源:tests.py

示例6: TestPages

# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
class TestPages(TestCase):
    def setUp(self):
        app.config["FLATPAGES_ROOT"] = "test/test_pages"
        self.pages = FlatPages(app)

    def test_get_fenced_blocks(self):
        page = self.pages.get("test-install-python")
        code = fenced_code(page.html)
        assert_not_in("Verified on MacOSX", code)
        assert_in("brew install python3", code)
开发者ID:pombredanne,项目名称:killtheyak.github.com,代码行数:12,代码来源:unit_tests.py

示例7: test_instance_relative

# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
 def test_instance_relative(self):
     with temp_directory() as temp:
         source = os.path.join(os.path.dirname(__file__), 'pages')
         dest = os.path.join(temp, 'instance', 'pages')
         shutil.copytree(source, dest)
         app = Flask(__name__, instance_path=os.path.join(temp, 'instance'))
         app.config['FLATPAGES_INSTANCE_RELATIVE'] = True
         pages = FlatPages(app)
         bar = pages.get('foo/bar')
         self.assertTrue(bar is not None)
开发者ID:SimonSapin,项目名称:Flask-FlatPages,代码行数:12,代码来源:test_flask_flatpages.py

示例8: test_yaml_meta

# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
 def test_yaml_meta(self):
     pages = FlatPages(Flask(__name__))
     foo = pages.get('foo')
     self.assertEquals(foo.meta, {
         'title': 'Foo > bar',
         'created': datetime.date(2010, 12, 11),
         'versions': [3.14, 42]
     })
     self.assertEquals(foo['title'], 'Foo > bar')
     self.assertEquals(foo['created'], datetime.date(2010, 12, 11))
     self.assertEquals(foo['versions'], [3.14, 42])
     self.assertRaises(KeyError, lambda: foo['nonexistent'])
开发者ID:AleksandarMicovic,项目名称:Flask-FlatPages,代码行数:14,代码来源:tests.py

示例9: test_extra

# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
    def test_extra(self):
        app = Flask(__name__)
        app.config['FLATPAGES_MARKDOWN_EXTENSIONS'] = ['extra']
        pages = FlatPages(app)
        extra_sep = '\n' if sys.version_info[:2] > (2, 6) else '\n\n'

        extra = pages.get('extra')
        self.assertEqual(
            extra.html,
            '<p>This is <em>true</em> markdown text.</p>\n'
            '<div>{0}'
            '<p>This is <em>true</em> markdown text.</p>\n'
            '</div>'.format(extra_sep)
        )
开发者ID:danielgloven,项目名称:Flask-FlatPages,代码行数:16,代码来源:test_markdown_extensions.py

示例10: test_codehilite_linenums_disabled

# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
    def test_codehilite_linenums_disabled(self):
        app = Flask(__name__)
        app.config['FLATPAGES_MARKDOWN_EXTENSIONS'] = [
            'codehilite(linenums=False)'
        ]
        pages = FlatPages(app)

        codehilite = pages.get('codehilite')
        self.assertEqual(
            codehilite.html,
            '<div class="codehilite"><pre><span class="k">print</span>'
            '<span class="p">(</span><span class="s">&#39;Hello, world!&#39;'
            '</span><span class="p">)</span>\n</pre></div>'
        )
开发者ID:danielgloven,项目名称:Flask-FlatPages,代码行数:16,代码来源:test_markdown_extensions.py

示例11: test_headerid_with_toc

# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
    def test_headerid_with_toc(self):
        app = Flask(__name__)
        pages = FlatPages(app)
        pages.app.config['FLATPAGES_MARKDOWN_EXTENSIONS'] = [
            'codehilite', 'toc' #headerid is deprecated in Markdown 3.0
        ]
        pages.reload()
        pages._file_cache = {}

        hello = pages.get('headerid')
        self.assertEqual(
            hello.html,
            '<h1 id="page-header">Page Header</h1>\n'
            '<h2 id="paragraph-header">Paragraph Header</h2>\n'
            '<p>Text</p>'
        )
        self.check_default_codehilite_page(pages) #test codehilite also loaded
开发者ID:SimonSapin,项目名称:Flask-FlatPages,代码行数:19,代码来源:test_markdown_extensions.py

示例12: TestFlatPagesKnitr

# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
class TestFlatPagesKnitr(unittest.TestCase):
    def setUp(self):
        self.tmp = mkdtemp()
        self.content = os.path.join(self.tmp, "content")
        os.makedirs(self.content)

        self.app = Flask(__name__, static_folder=os.path.join(self.tmp, "static"))
        self.app.config.update(
            FLATPAGES_ROOT=self.content,
            FLATPAGES_AUTO_RELOAD=True,
            FLATPAGES_ENCODING="utf-8",
            FLATPAGES_MARKDOWN_EXTENSIONS=["fenced_code"],
        )
        self.pages = FlatPages(self.app)
        FlatPagesKnitr(self.app)

    def tearDown(self):
        rmtree(self.tmp)

    def get(self, body, ext=".Rmd", enc="utf-8"):
        self.app.config.update(FLATPAGES_EXTENSION=ext)
        with open(os.path.join(self.content, "test" + ext), "w", enc) as f:
            f.write("title:test\n\n" + body)
        return self.pages.get("test").html

    def test_rmd(self):
        self.assertEqual(self.get("#test"), "<h1>test</h1>")

    def test_r(self):
        self.assertTrue("3.14" in self.get("```{r}\npi\n```"))

    def test_plot(self):
        self.get("```{r, test}\nplot(1:4, 1:4)\n```")
        self.assertTrue(os.path.exists(os.path.join(
            self.tmp, "static", "knitr", "test", "figure", "test-1.png")))

    def test_unicode(self):
        self.assertTrue(u"萬大事都有得解決" in self.get(u"```{r}\npaste('萬大事都有得解決')\n```"))

    def test_unicode2(self):
        self.app.config.update(FLATPAGES_ENCODING="iso-8859-15")
        self.assertEqual(self.get(u"äöü", enc="iso-8859-15"), u"<p>äöü</p>")
开发者ID:fhirschmann,项目名称:Flask-FlatPages-Knitr,代码行数:44,代码来源:tests.py

示例13: test_markdown

# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
 def test_markdown(self):
     pages = FlatPages(Flask(__name__))
     foo = pages.get('foo')
     self.assertEqual(foo.body, 'Foo *bar*\n')
     self.assertEqual(foo.html, '<p>Foo <em>bar</em></p>')
开发者ID:SimonSapin,项目名称:Flask-FlatPages,代码行数:7,代码来源:test_flask_flatpages.py

示例14: test_get

# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
 def test_get(self):
     pages = FlatPages(Flask(__name__))
     self.assertEqual(pages.get('foo/bar').path, 'foo/bar')
     self.assertEqual(pages.get('nonexistent'), None)
     self.assertEqual(pages.get('nonexistent', 42), 42)
开发者ID:SimonSapin,项目名称:Flask-FlatPages,代码行数:7,代码来源:test_flask_flatpages.py

示例15: test_consistency

# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
 def test_consistency(self):
     pages = FlatPages(Flask(__name__))
     for page in pages:
         assert pages.get(page.path) is page
开发者ID:SimonSapin,项目名称:Flask-FlatPages,代码行数:6,代码来源:test_flask_flatpages.py


注:本文中的flask_flatpages.FlatPages.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。