Ñò e>õGc@szdZddkZddkZddkZddkZddkiZddkiZ ddk l Z ddk l Z lZeideiƒZd„Zd„Zdd „Zdd d d „Zdd „Zd dd„Zddd„Zddd„Zdd„Zd„Zdd„Zd„Zd„Zd„Z e!d„Z"d„Zddd d!d"d#d$d%d&d'd(d)d*g Z#dS(+sU Text Helpers Provides methods for filtering, formatting and transforming strings. iÿÿÿÿN(trequest_config(t content_tagt tag_optionss/ ( # leading text <\w+.*?>| # leading HTML tag, or [^=!:'"/]| # leading punctuation, or ^ # beginning of line ) ( (?:https?://)| # protocol spec, or (?:www\.) # www.* ) ( [-\w]+ # subdomain or domain (?:\.[-\w]+)* # remaining subdomains or domain (?::\d+)? # port (?:/(?:(?:[~\w\+%-]|(?:[,.;:][^\s$]))+)?)* # path (?:\?[\w\+%&=.;-]+)? # query string (?:\#[\w\-]*)? # trailing anchor ) ([\.,"'?!;:]|\s|<|$) # trailing text cCstd|dti|ƒƒS(Ntitemstiter(tdictt itertoolstcycle(R((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pytiterdict)scOs©t|ƒdjo |}n |d}|iddƒ}tƒiidhƒ}|i|t|ƒƒ}||idƒ|jot|ƒ}||"> ... use item ... % #endfor You can use named cycles to prevent clashes in nested loops. You'll have to reset the inner cycle, manually:: % for item in items: % for value in item.values: '"> item % #endfor <% reset_cycle("colors") %> % #endfor iitnametdefaultsrailshelpers.cyclesRR(tlentgetRtenviront setdefaultRtnext(targstkargsRR tcyclesR((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyR,s&  R cCs/ytƒid|=Wntj onXdS(sŒ Reset a cycle. Resets the cycle so that it starts from the first element in the array the next time it is used. srailshelpers.cyclesN(RR tKeyError(R ((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyt reset_cycle_sicCsFtƒiidhƒ}d„}|i||||ƒƒ}|iƒS(sReturn the next cardinal in a sequence. Every time ``counter`` is called, the value returned will be the next counting number in that sequence. This is reset to ``start`` on every request, but can also be reset by calling ``reset_counter()``. You can optionally specify the number you want to start at by passing in the ``start`` argument (defaults to 1). You can also optionally specify the step size you want by passing in the ``step`` argument (defaults to 1). Sequences will increase monotonically by ``step`` each time it is called, until the heat death of the universe or python explodes. This can be used to count rows in a table:: # In Myghty % for item in items: <% h.counter() %> % #endfor You can use named counters to prevent clashes in nested loops. You'll have to reset the inner cycle manually though. See the documentation for ``webhelpers.text.cycle()`` for a similar example. srailshelpers.counterscss"xto|V||7}qWdS(N(tTrue(tstarttstep((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyt do_counterŽs(RR RR(R RRtcountersRtcounter((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyRls cCs/ytƒid|=Wntj onXdS(sŠReset a counter. Resets the counter so that it starts from the ``start`` cardinal in the sequence next time it is used. srailshelpers.countersN(RR R(R ((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyt reset_counter—sis...cCsD|pdS|t|ƒ}t|ƒ|jo || |S|SdS(sx Truncate ``text`` with replacement characters. ``length`` The maximum length of ``text`` before replacement ``truncate_string`` If ``text`` exceeds the ``length``, this string will replace the end of the string Example:: >>> truncate('Once upon a time in a world far far away', 14) 'Once upon a...' tN(R (ttexttlengthttruncate_stringtnew_len((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyttruncate£s  s%\1cCsq|dj otidtdƒ|}n| p| o|Stidti|ƒtiƒ}|i||ƒS(s¨ Highlight the ``phrase`` where it is found in the ``text``. The highlighted phrase will be surrounded by the highlighter, by default:: I'm a highlight phrase ``highlighter`` Defines the highlighting phrase. This argument should be a single-quoted string with ``\1`` where the phrase is supposed to be inserted. Note: The ``phrase`` is sanitized to include only letters, digits, and spaces before use. Example:: >>> highlight('You searched for: Pylons', 'Pylons') 'You searched for: Pylons' ssThe highlight function's hilight keyword argument is deprecated: Please use the highlight keyword argument instead.is(%s)N( tNonetwarningstwarntDeprecationWarningtretcompiletescapetItsub(Rtphraset highlightert hilightert highlight_re((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyt highlight»s    "idcCs¼| p| o|Stid|ti|ƒ|ftiƒ}|i|ƒ}|pdS|idƒ}|idƒdjo||}n|idƒt|ƒjo||}n|S(sx Extract an excerpt from the ``text``, or '' if the phrase isn't found. ``phrase`` Phrase to excerpt from ``text`` ``radius`` How many surrounding characters to include ``excerpt_string`` Characters surrounding entire excerpt Example:: >>> excerpt("hello my world", "my", 3) '...lo my wo...' s(.{0,%s}%s.{0,%s})Rs\1ii( R&R'R(R)tsearchtexpandRtendR (RR+tradiustexcerpt_stringtpattmatchtexcerpt((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyR7Ýs+iPcCs#tidtdƒti||ƒS(s Wrap ``text`` into lines of at most ``line_width`` width. Deprecated. This is deprecated: Use python's builtin textwrap.fill instead. This function breaks on the first whitespace character that does not exceed ``line_width``. s`The word_wrap function has been deprecated: Use python's builtin textwrap.fill function instead.i(R#R$R%ttextwraptfill(Rt line_width((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyt word_wrapüs  cCsŸ|djo d}ntidd|ƒ}tidd|ƒ}tidd|ƒ}tidd |ƒ}td |ƒid d ƒ}tid d|ƒ}|S(sZ Return ``text`` transformed into HTML using simple formatting rules. Two or more consecutive newlines(``\n\n``) are considered as a paragraph and wrapped in ``

`` tags. One newline (``\n``) is considered a linebreak and a ``
`` tag is appended. This method does not remove the newlines from the text. Rs (\r\n|\n|\r)s\ns\n\n+s\n\ns(\n\n)s

\1

s([^\n])(\n)(?=[^\n])s \1\2
tps

s

s

s

\n

N(R"R&R*Rtreplace(R((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyt simple_format s  tallcKsV|pdS|djott|ƒ|S|djo t|ƒSt||SdS(sÐ Turn all urls and email addresses into clickable links. ``link`` Used to determine what to link. Options are "all", "email_addresses", or "urls" Example:: >>> auto_link("Go to http://www.planetpython.com and say hello to guido@python.org") 'Go to http://www.planetpython.com and say hello to guido@python.org' RR?temail_addressesN(tauto_link_urlstauto_link_email_addresses(Rtlinkt href_options((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyt auto_links   c s.t|‰‡fd†}tit||ƒS(Ncs‰|iƒ}|iddddƒ\}}}}tid|tiƒo|S||}|djo d}nd|||ˆ||fS( Niiiis%s%s(tgroupR&R6R)(tmatchobjR?tatbtctdR(t extra_options(s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyt handle_match7s $   (RR&R*t AUTO_LINK_RE(RRDRM((RLs9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyRA5s  cCstidd|ƒS(Ns4([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)s\1(R&R*(R((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyRBBs cCs,tidtitiBƒ}|id|ƒS(s¬ Strip link tags from ``text`` leaving just the link label. Example:: >>> strip_links('else') 'else' s(.*?)<\/a>s\1(R&R'R)tMR*(Rtstrip_re((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyt strip_linksFs cCsti|ƒ}|id|ƒS(s-Format the text with Textile formatting. This function uses the `PyTextile library `_ which is included with WebHelpers. Additionally, the output can be sanitized which will fix tags like ,
and


for proper XHTML output. tsanitize(ttextiletTextilertprocess(RRRttexer((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyt textilizeSs cKsti||S(sÐFormat the text with MarkDown formatting. This function uses the `Python MarkDown library `_ which is included with WebHelpers. (t _markdowntmarkdown(Rtkwargs((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyRY`sRRRRR!R/R7R;R>RERQRWRY($t__doc__RR&R8R#twebhelpers.textileRStwebhelpers.markdownRYRXtroutesRtwebhelpers.rails.tagsRRR'tXRNRRRRRR!R"R/R7R;R>RERARBRQtFalseRWt__all__(((s9/usr/lib/python2.6/site-packages/webhelpers/rails/text.pyts:      3 +  !