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


Python LOREM_IPSUM_WORDS.split方法代码示例

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


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

示例1: generate_lorem_ipsum

# 需要导入模块: from jinja2.constants import LOREM_IPSUM_WORDS [as 别名]
# 或者: from jinja2.constants.LOREM_IPSUM_WORDS import split [as 别名]
def generate_lorem_ipsum(n=5, html=True, min=20, max=100):
    """Generate some lorem impsum for the template."""
    from jinja2.constants import LOREM_IPSUM_WORDS
    from random import choice, randrange

    words = LOREM_IPSUM_WORDS.split()
    result = []

    for _ in xrange(n):
        next_capitalized = True
        last_comma = last_fullstop = 0
        word = None
        last = None
        p = []

        # each paragraph contains out of 20 to 100 words.
        for idx, _ in enumerate(xrange(randrange(min, max))):
            while True:
                word = choice(words)
                if word != last:
                    last = word
                    break
            if next_capitalized:
                word = word.capitalize()
                next_capitalized = False
            # add commas
            if idx - randrange(3, 8) > last_comma:
                last_comma = idx
                last_fullstop += 2
                word += ","
            # add end of sentences
            if idx - randrange(10, 20) > last_fullstop:
                last_comma = last_fullstop = idx
                word += "."
                next_capitalized = True
            p.append(word)

        # ensure that the paragraph ends with a dot.
        p = u" ".join(p)
        if p.endswith(","):
            p = p[:-1] + "."
        elif not p.endswith("."):
            p += "."
        result.append(p)

    if not html:
        return u"\n\n".join(result)
    return Markup(u"\n".join(u"<p>%s</p>" % escape(x) for x in result))
开发者ID:dotandimet,项目名称:Flocks,代码行数:50,代码来源:jinja2util.py

示例2: generate_lorem_ipsum

# 需要导入模块: from jinja2.constants import LOREM_IPSUM_WORDS [as 别名]
# 或者: from jinja2.constants.LOREM_IPSUM_WORDS import split [as 别名]
def generate_lorem_ipsum(n = 5, html = True, min = 20, max = 100):
    from jinja2.constants import LOREM_IPSUM_WORDS
    from random import choice, randrange
    words = LOREM_IPSUM_WORDS.split()
    result = []
    for _ in xrange(n):
        next_capitalized = True
        last_comma = last_fullstop = 0
        word = None
        last = None
        p = []
        for idx, _ in enumerate(xrange(randrange(min, max))):
            while True:
                word = choice(words)
                if word != last:
                    last = word
                    break

            if next_capitalized:
                word = word.capitalize()
                next_capitalized = False
            if idx - randrange(3, 8) > last_comma:
                last_comma = idx
                last_fullstop += 2
                word += ','
            if idx - randrange(10, 20) > last_fullstop:
                last_comma = last_fullstop = idx
                word += '.'
                next_capitalized = True
            p.append(word)

        p = u' '.join(p)
        if p.endswith(','):
            p = p[:-1] + '.'
        elif not p.endswith('.'):
            p += '.'
        result.append(p)

    if not html:
        return u'\n\n'.join(result)
    return Markup(u'\n'.join((u'<p>%s</p>' % escape(x) for x in result)))
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:43,代码来源:utils.py


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