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


Python flask_flatpages.FlatPages类代码示例

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


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

示例1: test_basic

    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,代码行数:32,代码来源:test_markdown_extensions.py

示例2: test_other_html_renderer

    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,代码行数:25,代码来源:test_flask_flatpages.py

示例3: test_html_conversion

 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,代码行数:8,代码来源:tests.py

示例4: test_other_html_renderer

 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,代码行数:8,代码来源:tests.py

示例5: test_instance_relative

 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,代码行数:10,代码来源:test_flask_flatpages.py

示例6: test_extension_object

 def test_extension_object(self):
     app = Flask(__name__)
     from markdown.extensions.codehilite import CodeHiliteExtension
     codehilite = CodeHiliteExtension()
     app.config['FLATPAGES_MARKDOWN_EXTENSIONS'] = [codehilite]
     pages = FlatPages(app)
     self.check_default_codehilite_page(pages)
     codehilite = CodeHiliteExtension(linenums='True') #Check config applies
     app.config['FLATPAGES_MARKDOWN_EXTENSIONS'] = [codehilite]
     pages.reload()
     pages._file_cache = {}
     self.check_codehilite_with_linenums(pages)
开发者ID:SimonSapin,项目名称:Flask-FlatPages,代码行数:12,代码来源:test_markdown_extensions.py

示例7: test_yaml_meta

 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,代码行数:12,代码来源:tests.py

示例8: test_codehilite_linenums_disabled

    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,代码行数:14,代码来源:test_markdown_extensions.py

示例9: test_extra

    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,代码行数:14,代码来源:test_markdown_extensions.py

示例10: test_extension_importpath

 def test_extension_importpath(self):
     app = Flask(__name__)
     app.config['FLATPAGES_MARKDOWN_EXTENSIONS'] = [
         'markdown.extensions.codehilite:CodeHiliteExtension'
     ]
     pages = FlatPages(app)
     self.check_default_codehilite_page(pages)
     app.config['FLATPAGES_EXTENSION_CONFIGS'] = { #Markdown 3 style config
         'markdown.extensions.codehilite:CodeHiliteExtension': {
             'linenums': True
         }
     }
     pages.reload()
     pages._file_cache = {}
     self.check_codehilite_with_linenums(pages)
开发者ID:SimonSapin,项目名称:Flask-FlatPages,代码行数:15,代码来源:test_markdown_extensions.py

示例11: test_codehilite_linenums_disabled

 def test_codehilite_linenums_disabled(self):
     #Test explicity disabled
     app = Flask(__name__)
     app.config['FLATPAGES_MARKDOWN_EXTENSIONS'] = ['codehilite']
     pages = FlatPages(app)
     self.check_default_codehilite_page(pages)
     #Test explicity disabled
     pages.app.config['FLATPAGES_EXTENSION_CONFIGS'] = {
         'codehilite': {
             'linenums': 'False'
         }
     }
     pages.reload()
     pages._file_cache = {}
     self.check_default_codehilite_page(pages)
开发者ID:SimonSapin,项目名称:Flask-FlatPages,代码行数:15,代码来源:test_markdown_extensions.py

示例12: TestFlatPagesPandoc

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,代码行数:33,代码来源:tests.py

示例13: test_headerid_with_toc

    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,代码行数:17,代码来源:test_markdown_extensions.py

示例14: CategorizedFlatPages

class CategorizedFlatPages(object):
    def __init__(self):
        self.flat_pages = FlatPages()
        self.root_category = Category(None, '<root>')

    def init_app(self, app):
        self.flat_pages.init_app(app)
        self._set_categories()

    def __iter__(self):
        return iter(sorted(self.root_category.categories.values(),
            cmp=compare))


    def get(self, category_id, article_id):
        category = self.root_category.categories.get(category_id)
        if category is None:
            return None
        return category.articles.get(article_id)

    def get_articles_of_category(self, category_id):
        barticles = []
        for a in self.root_category.categories.get(category_id).articles.values():
            if a.id != 'index':
                barticles.append(a)
        return barticles

    def get_or_404(self, category_id, article_id):
        page = self.get(category_id, article_id)
        if page is None:
            abort(404)
        return page

    def _set_categories(self):
        for page in self.flat_pages:
            components = page.path.split('/')
            parent = self.root_category
            for category_id in components[:-1]:
                parent = parent.add_category(category_id)
            page_name = components[-1]
            parent.add_article(page_name, page)

    def reload(self):
        self.flat_pages.reload()
        self._set_categories()
开发者ID:janLo,项目名称:sipa,代码行数:45,代码来源:flatpages.py

示例15: TestPages

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,代码行数:10,代码来源:unit_tests.py


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