API:EPrints/XHTML

From EPrints Documentation
Jump to: navigation, search

EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects


API: Core API

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.


hidden_field

$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_type

Returns 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/.