wpart_erlsyntax

Overview

wpart_erlsyntax component is responsible for highlighting the Erlang code on the page. The application provides a single module: wpart_erlsyntax that is responsible for scanning the text and surrounding the content with the proper HTML tags.

Configuration

No configuration parameters are needed. During the install phase application copies its example CSS file into docroot directory (it is deleted during uninstall process).

Usage

In order to highlight some Erlang code we must use the following tags:

Each element of the code will be surrounded with a proper container with the class attribute set:

You can define your own CSS outlook for each of the element type (color, font style, etc.)

Example

The following code pasted in the template:

<html>
<head>
  <title>wpart_erlsyntax example</title>
  <wpart:erlsyntax type="style" path="/erlsyntax_example.css" />
</head>
<body>
  <h1>This is an example: </h1>
  <wpart:erlsyntax legend="Example of the wpart_erlsyntax">
    handle_call(E) ->
    case wpart:has_attribute("attribute::type", E) of
        "style" ->
            Path = wpart:has_attribute("attribute::path", "/erlsyntax.css", E),

            #xmlText{value=?CSS_HEADER(Path),
                     type=cdata};
        false ->
            Legend = case wpart:has_attribute("attribute::legend", E) of
                         false ->
                             "";
                         Desc ->
                             ?LEGEND(Desc)
                     end,
            
            Content = lists:foldl(fun xml_content_fold/2, [], E#xmlElement.content),
            #xmlText{value=highlight_syntax(Content, Legend),
                     type=cdata};
        _ ->
            #xmlText{value="Bad formatted wpart:erlsyntax tag!",
                     type=cdata}
    end.
  </wpart:erlsyntax>
</body>
</html>

will look in our browser in this way:

erlsyntax.png

Ecomponents/wpart_erlsyntax (last edited 2009-05-05 14:35:54 by Michal Ptaszek)