API:EPrints/XHTML: Difference between revisions
No edit summary |
No edit summary |
||
| Line 8: | Line 8: | ||
'''EPrints::XHTML''' - XHTML Module | '''EPrints::XHTML''' - XHTML Module | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=head_synopsis --> | <!-- Pod2Wiki=head_synopsis --> | ||
==SYNOPSIS== | ==SYNOPSIS== | ||
<source lang="perl">$xhtml = $repo->xhtml; | |||
$utf8_string = $xhtml->to_xhtml( $dom_node, %opts ); | |||
$xhtml_dom_node = $xhtml->input_field( $name, $value, type => "text" ); | |||
$xhtml_dom_node = $xhtml->hidden_field( $name, $value ); | |||
$xhtml_dom_node = $xhtml->text_area_field( $name, $value, rows => 4 ); | |||
$xhtml_dom_node = $xhtml->form( "get", $url ); | |||
$xhtml_dom_node = $xhtml->data_element( $name, $value, indent => 4 );</source> | |||
< | |||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=head_tree --> | <!-- Pod2Wiki=head_tree --> | ||
===tree()=== | ===tree()=== | ||
<pre> $xhtml->tree([ # dl | |||
[ "fruit", # dt | [ "fruit", # dt | ||
[ "apple", "orange", ], # ul {li, li} | [ "apple", "orange", ], # ul {li, li} | ||
| Line 55: | Line 47: | ||
]); | ]); | ||
<dl> | |||
<dt>fruit</dt> | |||
<dd> | |||
<ul> | |||
<li>apple</li> | |||
<li>orange</li> | |||
</ul> | |||
</dd> | |||
<dt>vegetable</dt> | |||
<dd> | |||
<ul> | |||
<li>potato</li> | |||
<li>carrot</li> | |||
</ul> | |||
</dd> | |||
<dt>animal</dt> | |||
<dd> | |||
<dl> | |||
<dt>cat</dt> | |||
<dd> | |||
<ul> | |||
<li>lion</li> | |||
<li>leopard</li> | |||
</ul> | |||
</dd> | |||
</dl> | |||
</dd> | |||
</dl> | |||
<ul> | |||
<li>soup</li> | |||
</ul> | |||
<p /></pre> | |||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=head_description --> | <!-- Pod2Wiki=head_description --> | ||
==DESCRIPTION== | ==DESCRIPTION== | ||
The XHTML object facilitates the creation of XHTML objects. | The XHTML object facilitates the creation of XHTML objects. | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=head_methods --> | <!-- Pod2Wiki=head_methods --> | ||
==METHODS== | ==METHODS== | ||
< | <!-- Pod2Wiki=head_form --> | ||
===form=== | |||
<source lang="perl">$node = $xhtml->form( $method [, $action] ) | |||
</source> | |||
</ | |||
Returns an XHTML form. If $action isn't defined uses the current URL. | Returns an XHTML form. If $action isn't defined uses the current URL. | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=head_input_field --> | |||
<!-- Pod2Wiki= | |||
===input_field=== | ===input_field=== | ||
<source lang="perl">$node = $xhtml->input_field( $name, $value, %opts ) | |||
</source> | |||
<pre> $node = $xhtml->input_field( "name", "Bob", type => "text" );</pre> | |||
Returns an XHTML input field with name $name and value $value. Specify "noenter" to prevent the form being submitted when the user presses the enter key. | Returns an XHTML input field with name $name and value $value. Specify "noenter" to prevent the form being submitted when the user presses the enter key. | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=head_hidden_field --> | |||
<!-- Pod2Wiki= | |||
===hidden_field=== | ===hidden_field=== | ||
<source lang="perl">$node = $xhtml->hidden_field( $name, $value, %opts ); | |||
</source> | |||
Returns an XHTML hidden input field. | Returns an XHTML hidden input field. | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=head_action_button --> | |||
<!-- Pod2Wiki= | |||
===action_button=== | ===action_button=== | ||
<source lang="perl">$node = $xhtml->action_button( $name, $value, %opts ) | |||
</source> | |||
Creates a submit button that is styled to an EPrints form button. | Creates a submit button that is styled to an EPrints form button. | ||
$value is the text shown on the button. | $value is the text shown on the button. | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
</ | <!-- Pod2Wiki=head_action_icon --> | ||
<!-- Pod2Wiki= | ===action_icon=== | ||
<source lang="perl">$node = $xhtml->action_icon( $name, $src, %opts ) | |||
</source> | |||
Creates an image button that links to $src. | |||
For usability it is strongly recommended to supply the alt= attribute. | |||
<!-- Edit below this comment --> | |||
<!-- Pod2Wiki= --> | |||
<!-- Pod2Wiki=head_text_area_field --> | |||
===text_area_field=== | ===text_area_field=== | ||
<source lang="perl">$node = $xhtml->text_area_field( $name, $value, %opts ) | |||
</source> | |||
Returns an XHTML textarea input. | Returns an XHTML textarea input. | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=head_data_element --> | |||
<!-- Pod2Wiki= | |||
===data_element=== | ===data_element=== | ||
<source lang="perl">$node = $xhtml->data_element( $name, $value, %opts ) | |||
</source> | |||
Create a new element named $name containing a text node containing $value. | Create a new element named $name containing a text node containing $value. | ||
| Line 193: | Line 183: | ||
indent - amount of whitespace to indent by | indent - amount of whitespace to indent by | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=head_to_xhtml --> | |||
<!-- Pod2Wiki= | |||
===to_xhtml=== | ===to_xhtml=== | ||
<source lang="perl">$utf8_string = $xhtml->to_xhtml( $node, %opts ) | |||
</source> | |||
Returns $node as valid XHTML. | Returns $node as valid XHTML. | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=head_to_text_dump --> | |||
<!-- Pod2Wiki= | |||
===to_text_dump=== | ===to_text_dump=== | ||
<source lang="perl">$string = $xhtml->to_text_dump( $tree, %opts ) | |||
</source> | |||
Dumps the XHTML contents of $tree as a utf8 string, stripping tags and converting common HTML layout elements into their plain-text equivalent. | Dumps the XHTML contents of $tree as a utf8 string, stripping tags and converting common HTML layout elements into their plain-text equivalent. | ||
Options: | Options: | ||
<pre> width - word-wrap after the given number of columns | |||
show_links - see below | show_links - see below | ||
preformatted - equivalent to wrapping $tree in <pre></pre> | preformatted - equivalent to wrapping $tree in <pre></pre></pre> | ||
XHTML elements are removed with the following exceptions: | XHTML elements are removed with the following exceptions: | ||
| Line 237: | Line 225: | ||
<a href="foo">bar</a> will be replaced by "bar <foo>" if '''show_links''' is set. | <a href="foo">bar</a> will be replaced by "bar <foo>" if '''show_links''' is set. | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=head_box --> | |||
<!-- Pod2Wiki= | ===box=== | ||
=== | |||
<source lang="perl">$node = $xhtml->box( $content, %opts ) | |||
</source> | |||
Render a collapsible box. | |||
Options: | |||
* basename = ep_box | |||
: Prefix to use for identifying page elements. | |||
* collapsed = 1 | |||
: Should the box start rolled up. | |||
* show_label | |||
: Label shown when the box is hidden (in the link). | |||
* hide_label | |||
: Label shown when the box is visible (in the link). | |||
* show_icon_url = "style/images/plus.png" | |||
: The url of the icon to use instead of the [+]. | |||
* hide_icon_url = "style/images/minus.png" | |||
: The url of the icon to use instead of the [-]. | |||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=head_tabs --> | |||
<!-- Pod2Wiki= | |||
===tabs=== | ===tabs=== | ||
<source lang="perl">$node = $xhtml->tabs( $labels, $contents, %opts ) | |||
</source> | |||
Render a tabbed box where: | Render a tabbed box where: | ||
<pre> labels - an array of label XHTML fragments | |||
contents - an array of content XHTML fragments | contents - an array of content XHTML fragments</pre> | ||
Options: | Options: | ||
<pre> base_url - the link to follow under non-JS (default = current URL) | |||
basename - prefix for tab identifiers (default = "ep_tabs") | basename - prefix for tab identifiers (default = "ep_tabs") | ||
current - index of tab to show first (default = 0) | current - index of tab to show first (default = 0) | ||
expensive - array of tabs to not javascript-link | expensive - array of tabs to not javascript-link | ||
aliases - map tab index to alias name | aliases - map tab index to alias name</pre> | ||
< | |||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=head_tree --> | |||
<!-- Pod2Wiki= | |||
===tree=== | ===tree=== | ||
<source lang="perl">$node = $xhtml->tree( $root, OPTIONS ) | |||
</source> | |||
Render a tree using definition lists (DLs). | Render a tree using definition lists (DLs). | ||
Options: | Options: | ||
<pre> prefix - id to use for the parent <div> | |||
render_value - custom renderer for values | class | ||
HTML class to use for div and prefix for open/close, defaults to | |||
< | 'prefix' option | ||
< | render_value - custom renderer for values</pre> | ||
<!-- Edit below this comment --> | |||
<!-- Pod2Wiki= --> | |||
<!-- Pod2Wiki=head_action_list --> | |||
===action_list=== | |||
<source lang="perl">$node = $xhtml->action_list( $actions, %opts ) | |||
</source> | |||
Returns an unordered list (<UL>) of actions on a single line. $actions is an array reference of XHTML fragments (e.g. icons or buttons). | |||
<!-- Edit below this comment --> | |||
<!-- Pod2Wiki= --> | |||
<!-- Pod2Wiki=head_action_definition_list --> | |||
===action_definition_list=== | |||
<source lang="perl">$node = $xhtml->action_definition_list( $actions, $definitions, %opts ) | |||
</source> | |||
Returns a definition list (<DL>) of actions plus their definitions. $actions is an array reference of XHTML fragments (e.g. icons or buttons). | |||
<!-- Edit below this comment --> | |||
<!-- Pod2Wiki= --> | |||
<!-- Pod2Wiki=head_doc_type --> | |||
===doc_type=== | |||
<source lang="perl">$str = $xhtml->doc_type | |||
</source> | |||
Returns the default DOCTYPE as a string. | |||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=head_copyright --> | <!-- Pod2Wiki=head_copyright --> | ||
==COPYRIGHT== | ==COPYRIGHT== | ||
Copyright 2000-2011 University of Southampton. | |||
This file is part of EPrints http://www.eprints.org/. | |||
EPrints is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | |||
EPrints is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | |||
You should have received a copy of the GNU Lesser General Public License along with EPrints. If not, see http://www.gnu.org/licenses/. | |||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=_postamble_ --> | |||
<!-- Pod2Wiki=_postamble_ --><!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Latest revision as of 09:56, 22 January 2013
EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects
Latest Source Code (3.4, 3.3) | Revision Log | Before editing this page please read Pod2Wiki
NAME
EPrints::XHTML - XHTML Module
SYNOPSIS
$xhtml = $repo->xhtml;
$utf8_string = $xhtml->to_xhtml( $dom_node, %opts );
$xhtml_dom_node = $xhtml->input_field( $name, $value, type => "text" );
$xhtml_dom_node = $xhtml->hidden_field( $name, $value );
$xhtml_dom_node = $xhtml->text_area_field( $name, $value, rows => 4 );
$xhtml_dom_node = $xhtml->form( "get", $url );
$xhtml_dom_node = $xhtml->data_element( $name, $value, indent => 4 );
tree()
$xhtml->tree([ # dl
[ "fruit", # dt
[ "apple", "orange", ], # ul {li, li}
],
[ "vegetable", # dt
[ "potato", "carrot", ], # ul {li, li}
],
[ "animal", # dt
[ "cat", # dt
[ "lion", "leopard", ], # ul {li, li}
],
],
"soup", # ul {li}
$xml->create_element( "p" ), # <p> is appended
]);
<dl>
<dt>fruit</dt>
<dd>
<ul>
<li>apple</li>
<li>orange</li>
</ul>
</dd>
<dt>vegetable</dt>
<dd>
<ul>
<li>potato</li>
<li>carrot</li>
</ul>
</dd>
<dt>animal</dt>
<dd>
<dl>
<dt>cat</dt>
<dd>
<ul>
<li>lion</li>
<li>leopard</li>
</ul>
</dd>
</dl>
</dd>
</dl>
<ul>
<li>soup</li>
</ul>
<p />
DESCRIPTION
The XHTML object facilitates the creation of XHTML objects.
METHODS
form
$node = $xhtml->form( $method [, $action] )Returns an XHTML form. If $action isn't defined uses the current URL.
input_field
$node = $xhtml->input_field( $name, $value, %opts )$node = $xhtml->input_field( "name", "Bob", type => "text" );
Returns an XHTML input field with name $name and value $value. Specify "noenter" to prevent the form being submitted when the user presses the enter key.
$node = $xhtml->hidden_field( $name, $value, %opts );Returns an XHTML hidden input field.
action_button
$node = $xhtml->action_button( $name, $value, %opts )Creates a submit button that is styled to an EPrints form button.
$value is the text shown on the button.
action_icon
$node = $xhtml->action_icon( $name, $src, %opts )Creates an image button that links to $src.
For usability it is strongly recommended to supply the alt= attribute.
text_area_field
$node = $xhtml->text_area_field( $name, $value, %opts )Returns an XHTML textarea input.
data_element
$node = $xhtml->data_element( $name, $value, %opts )Create a new element named $name containing a text node containing $value.
Options: indent - amount of whitespace to indent by
to_xhtml
$utf8_string = $xhtml->to_xhtml( $node, %opts )Returns $node as valid XHTML.
to_text_dump
$string = $xhtml->to_text_dump( $tree, %opts )Dumps the XHTML contents of $tree as a utf8 string, stripping tags and converting common HTML layout elements into their plain-text equivalent.
Options:
width - word-wrap after the given number of columns show_links - see below preformatted - equivalent to wrapping $tree in <pre></pre>
XHTML elements are removed with the following exceptions:
<br /> is replaced by a newline.
<p>...</p> will have a blank line above and below.
<img /> is replaced with the content of the alt attribute.
<hr /> will insert a line of dashes if width is set.
<a href="foo">bar</a> will be replaced by "bar <foo>" if show_links is set.
box
$node = $xhtml->box( $content, %opts )Render a collapsible box.
Options:
- basename = ep_box
- Prefix to use for identifying page elements.
- collapsed = 1
- Should the box start rolled up.
- show_label
- Label shown when the box is hidden (in the link).
- hide_label
- Label shown when the box is visible (in the link).
- show_icon_url = "style/images/plus.png"
- The url of the icon to use instead of the [+].
- hide_icon_url = "style/images/minus.png"
- The url of the icon to use instead of the [-].
tabs
$node = $xhtml->tabs( $labels, $contents, %opts )Render a tabbed box where:
labels - an array of label XHTML fragments contents - an array of content XHTML fragments
Options:
base_url - the link to follow under non-JS (default = current URL) basename - prefix for tab identifiers (default = "ep_tabs") current - index of tab to show first (default = 0) expensive - array of tabs to not javascript-link aliases - map tab index to alias name
tree
$node = $xhtml->tree( $root, OPTIONS )Render a tree using definition lists (DLs).
Options:
prefix - id to use for the parent <div>
class
HTML class to use for div and prefix for open/close, defaults to
'prefix' option
render_value - custom renderer for values
action_list
$node = $xhtml->action_list( $actions, %opts )Returns an unordered list (<UL>) of actions on a single line. $actions is an array reference of XHTML fragments (e.g. icons or buttons).
action_definition_list
$node = $xhtml->action_definition_list( $actions, $definitions, %opts )Returns a definition list (<DL>) of actions plus their definitions. $actions is an array reference of XHTML fragments (e.g. icons or buttons).
doc_type
$str = $xhtml->doc_typeReturns the default DOCTYPE as a string.
COPYRIGHT
Copyright 2000-2011 University of Southampton.
This file is part of EPrints http://www.eprints.org/.
EPrints is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
EPrints is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with EPrints. If not, see http://www.gnu.org/licenses/.