Changeset 4376 for waeup


Ignore:
Timestamp:
27 Jun 2009, 15:26:56 (15 years ago)
Author:
uli
Message:

Add tests for new helper function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-rewrite/src/waeup/utils/helpers.txt

    r4189 r4376  
    126126    >>> removeFileOrDirectory('src')
    127127    >>> removeFileOrDirectory('dst')
     128
     129:func:`getInnerHTMLPart()`
     130==========================
     131
     132.. function:: getInnerHTMLPart(html_code)
     133
     134   Get the 'inner' part out of a piece of HTML code.
     135
     136   Helper function mainly to extract 'real content' from already
     137   rendered forms.
     138
     139   The term 'inner part' here means the ``<form>`` part of an HTML
     140   snippet. If this cannot be found, we look for a ``<body>`` part and
     141   if this cannot be found as well, we simply return the whole input.
     142
     143   If a ``<form>`` part can be found in an HTML snippet, this is
     144   returned with all preceeding/following stuff stripped:
     145
     146     >>> from waeup.utils.helpers import getInnerHTMLPart
     147     >>> print getInnerHTMLPart("""<html>
     148     ... <head>
     149     ... </head>
     150     ... <BLANKLINE>
     151     ... <body>
     152     ... <form action="http://localhost/myuniversity/faculties/TF/add"
     153     ...       method="post" class="edit-form"
     154     ...       enctype="multipart/form-data">
     155     ...   <h1>Add a department</h1>
     156     ... </form>
     157     ... </body>
     158     ... </html>
     159     ... """)
     160     <BLANKLINE>
     161     <form action="http://localhost/myuniversity/faculties/TF/add"
     162           method="post" class="edit-form"
     163           enctype="multipart/form-data">
     164     <BLANKLINE>
     165       <h1>Add a department</h1>
     166     </form>
     167     <BLANKLINE>
     168     <BLANKLINE>
     169
     170   If there is no ``<form>`` part, try to find any ``<body>`` part:
     171
     172     >>> print getInnerHTMLPart("""<html>
     173     ... <head>
     174     ... </head>
     175     ... <BLANKLINE>
     176     ... <body>
     177     ...  <div>Some content</div>
     178     ... </body>
     179     ... </html>
     180     ... """)
     181     <BLANKLINE>
     182      <div>Some content</div>
     183     <BLANKLINE>
     184
     185   If there is also no ``<body>`` tag, we return the input as-is:
     186
     187     >>> print getInnerHTMLPart("""<div>
     188     ...  <div>Some content</div>
     189     ... </div>
     190     ... """)
     191     <div>
     192      <div>Some content</div>
     193     </div>
Note: See TracChangeset for help on using the changeset viewer.