Ńň Ş5ŽHc @sŢdZddkZddkZddklZlZlZlZddkl Z ddddd gZ ei d ei ƒZ d d „Zddddddddd „Zdd„Zdd„Zd„Zd„Zd„ZdS(sŠHTML helpers that are more than just simple tags. There are no helpers to prettify HTML or canonicalize whitespace because BeautifulSoup and HTMLTidy handle this well. i˙˙˙˙N(tHTMLtliteraltlit_subtescape(tconvert_boolean_attrst button_totmail_tot highlightt strip_linkst auto_links/ ( # 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 tc Ks@|ot|dgƒnd}|iddƒ}|iƒdjo(tidddd d d d |ƒ}n|iƒd jo|pd }||p|}}|idƒ}|idƒ}|djo%|o||d <|id|ƒnd|d<||d > button_to("Edit", url(action='edit', id=3))
Example 2:: >> button_to("Destroy", url(action='destroy', id=3), .. method='DELETE')
Example 3:: # Button as an image. >> button_to("Edit", url(action='edit', id=3), type='image', .. src='icon_delete.gif')
.. note:: This method generates HTML code that represents a form. Forms are "block" content, which means that you should not try to insert them into your HTML where only inline content is expected. For example, you can legally insert a form inside of a ``div`` or ``td`` element or in between ``p`` elements, but not in the middle of a run of text, nor can you place a form within another form. (Bottom line: Always validate your HTML before going public.) tdisabledR tmethodtPUTtDELETEttypethiddentidt_methodtname_tvaluetGETtPOSTtsrctimagetalttsubmittactiontclass_s button-totc(R R( RtpoptupperRtinputtgett setdefaulttformtdiv(tnameturlt html_optionst method_tagR t form_methodt submit_typet img_source((s9/usr/lib/python2.6/site-packages/webhelpers/html/tools.pyR,s$C     c Ksľg} x~d|fd|fd|fd|ffD]R} | d} | o;t| tƒp| dt| ƒf} n| i| ƒq1q1Wti| ƒiddƒ} d }|}|o|id |ƒ}n|o|id |ƒ}n|d joôtid ig}|D]}|dt |ƒq ~ƒƒ}tid ig}|D]}|dt |ƒqI~ƒƒ}t i dƒ}g}xF|D]>}|i |ƒo|idt |ƒƒq‹|i|ƒq‹Wtid i|ƒƒ}nti||ƒ}| o|tidƒ| 7}n|| d>> mail_to("me@domain.com", "My email", encode = "javascript") literal(u'') >>> mail_to("me@domain.com", "My email", encode = "hex") literal(u'My email') You can also specify the cc address, bcc address, subject, and body parts of the message header to create a complex e-mail using the corresponding ``cc``, ``bcc``, ``subject``, and ``body`` keyword arguments. Each of these options are URI escaped and then appended to the ``email_address`` before being output. **Be aware that javascript keywords will not be escaped and may break this feature when encoding with javascript.** Examples:: >>> mail_to("me@domain.com", "My email", cc="ccaddress@domain.com", bcc="bccaddress@domain.com", subject="This is an example email", body= "This is the body of the message.") literal(u'My email') tcctbcctsubjecttbodyiit+s%20smailto:t@t.thexR s&#%d;s\ws%%%xt?threft javascriptsdocument.write('%s');s( // Rstext/javascriptN(t isinstanceRRtappendturllibt urlencodetreplaceRtjointordtretcompiletmatchtatscript(t email_addressR%R,R-R.R/t replace_att replace_dottencodeR'textrastitemtoptiont options_querytprotocoltemail_address_obfuscatedt_[1]txt_[2]tword_ret encoded_partsR&ttagttmpt_[3]tstring((s9/usr/lib/python2.6/site-packages/webhelpers/html/tools.pyR‰sR"+       1=   4s%\1cCsr| p| o|Stidti|ƒtiƒ}t|dƒot|i||ƒƒS|i||ƒSdS(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' s(%s)t__html__N(R>R?RtIthasattrRtsub(ttexttphraset highlightert highlight_re((s9/usr/lib/python2.6/site-packages/webhelpers/html/tools.pyRÜ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") literal(u'Go to http://www.planetpython.com and say hello to guido@python.org') uR^temail_addressesN(t_auto_link_urlst_auto_link_email_addresses(RZtlinkt href_options((s9/usr/lib/python2.6/site-packages/webhelpers/html/tools.pyR üs   c s(‡fd†}ttit||ƒƒS(Ncsš|iƒ}|iddddƒ\}}}}tid|tiƒo|St||ƒ}|djo d}ntˆƒ}t||ƒ|dR@RWRtdictRRA(tmatchobjR^tbeforetprefixRbtafterRZt a_options(Rc(s9/usr/lib/python2.6/site-packages/webhelpers/html/tools.pyt handle_matchs $   (RR>RYt AUTO_LINK_RE(RZRcRk((Rcs9/usr/lib/python2.6/site-packages/webhelpers/html/tools.pyR`s cCstdd|ƒS(Ns4([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)s\1(R(RZ((s9/usr/lib/python2.6/site-packages/webhelpers/html/tools.pyRa!scCsUt|tƒo t}n d„}tidtitiBƒ}||id|ƒƒS(sŹ Strip link tags from ``text`` leaving just the link label. Example:: >>> strip_links('else') 'else' cSs|S(((RN((s9/usr/lib/python2.6/site-packages/webhelpers/html/tools.pyt2ss(.*?)<\/a>s\1(R7RR>R?RWtMRY(RZtlittstrip_re((s9/usr/lib/python2.6/site-packages/webhelpers/html/tools.pyR%s   (t__doc__R>R9twebhelpers.htmlRRRRtwebhelpers.html.tagsRt__all__R?tXRlRtNoneRRR R`RaR(((s9/usr/lib/python2.6/site-packages/webhelpers/html/tools.pyts&  "  ] S