Home | Trees | Indices | Help |
|
---|
|
object --+ | XmlComponent --+ | DIV
HTML helper, for easy generating and manipulating a DOM structure. Little or no validation is done.
Behaves like a dictionary regarding updating of attributes. Behaves like a list regarding inserting/appending components.
example:>>> DIV('hello', 'world', _style='color:red;').xml() '<div style="color:red;">helloworld</div>'
all other HTML helpers are derived from DIV.
_something="value" attributes are transparently translated into something="value" HTML attributes
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Inherited from |
|
|||
tag =
|
|||
regex_tag = re.compile(r'^
|
|||
regex_id = re.compile(r'#
|
|||
regex_class = re.compile(r'\.
|
|||
regex_attr = re.compile(r'\[
|
|
|||
Inherited from |
|
:param *components: any components that should be nested in this element :param **attributes: any attributes you want to give to this element :raises SyntaxError: when a stand alone tag receives components
|
>>> a=DIV() >>> a.append(SPAN('x')) >>> print a <div><span>x</span></div> |
>>> a=DIV() >>> a.insert(0,SPAN('x')) >>> print a <div><span>x</span></div> |
gets attribute with name 'i' or component #i. If attribute 'i' is not found returns None :param i: index if i is a string: the name of the attribute otherwise references to number of the component |
sets attribute with name 'i' or component #i. :param i: index if i is a string: the name of the attribute otherwise references to number of the component :param value: the new value |
deletes attribute with name 'i' or component #i. :param i: index if i is a string: the name of the attribute otherwise references to number of the component |
Handling of provided components. Nothing to fixup yet. May be overridden by subclasses, eg for wrapping some components in another component or blocking them. |
helper for _fixup. Checks if a component is in allowed_parents, otherwise wraps it in wrap_parent :param allowed_parents: (tuple) classes that the component should be an instance of :param wrap_parent: the class to wrap the component in, if needed :param wrap_lambda: lambda to use for wrapping, if needed |
Handling of attributes (normally the ones not prefixed with '_'). Nothing to postprocess yet. May be overridden by subclasses |
|
helper for xml generation. Returns separately: - the component attributes - the generated xml of the inner components Component attributes start with an underscore ('_') and do not have a False or None value. The underscore is removed. A value of True is replaced with the attribute name. :returns: tuple: (attributes, components) |
|
|
>>> markdown = lambda text,tag=None,attributes={}: {None: re.sub('\s+',' ',text), 'h1':'#'+text+'\n\n', 'p':text+'\n'}.get(tag,text) >>> a=TAG('<h1>Header</h1><p>this is a test</p>') >>> a.flatten(markdown) '#Header\n\nthis is a test\n' |
find all component that match the supplied attribute dictionary, or None if nothing could be found All components of the components are searched.>>> a = DIV(DIV(SPAN('x'),3,DIV(SPAN('y')))) >>> for c in a.elements('span',first_only=True): c[0]='z' >>> print a <div><div><span>z</span>3<div><span>y</span></div></div></div> >>> for c in a.elements('span'): c[0]='z' >>> print a <div><div><span>z</span>3<div><span>z</span></div></div></div>It also supports a syntax compatible with jQuery >>> a=TAG('<div><span><a id="1-1" u:v=$>hello</a></span><p class="this is a test">world</p></div>') >>> for e in a.elements('div a#1-1, p.is'): print e.flatten() hello world >>> for e in a.elements('#1-1'): print e.flatten() hello >>> a.elements('a[u:v=$]')[0].xml() '<a id="1-1" u:v="$">hello</a>' >>> a=FORM( INPUT(_type='text'), SELECT(range(1)), TEXTAREA() ) >>> for c in a.elements('input, select, textarea'): c['_disabled'] = 'disabled' >>> a.xml() '<form action="" enctype="multipart/form-data" method="post"><input disabled="disabled" type="text" /><select disabled="disabled"><option value="0">0</option></select><textarea cols="40" disabled="disabled" rows="10"></textarea></form>' |
find the first component that matches the supplied attribute dictionary, or None if nothing could be found Also the components of the components are searched. |
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Thu Aug 4 00:47:01 2011 | http://epydoc.sourceforge.net |