當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。