Difference between revisions of "Xebra Create Tag Library"

(Adding Tags)
(Adding Tags)
Line 40: Line 40:
 
The config.taglib looks like this now:
 
The config.taglib looks like this now:
 
<xml>
 
<xml>
<taglib id="xeb">
+
    <taglib id="xeb">
<tag id="bold" class="FONT_BOLD_TAG">
+
        <tag id="bold" class="FONT_BOLD_TAG">
<attribute id="text"/>
+
            <attribute id="text"/>
</tag>
+
        </tag>
</taglib>
+
    </taglib>
 
</xml>
 
</xml>

Revision as of 16:10, 23 July 2009

This tutorial shows you how you can create a tag library for your own needs. It makes sense to add a custom library if some functionality recurs in your project(s). We will create a simple tag library ("font") with a tag with the ability to format text as bold (bold).

Setting up

Every tag library needs a unique namespace (like xeb or page). We create a folder in $FONT_TAG_LIBRARY where we put all our configuration and tag library files. The API of our tag library is defined in a file called config.taglib and has to be located in $FONT_TAG_LIBRARY. Since we don't have any tags yet, the file will just contain a skeleton:

<taglib id="font">
</taglib>

With this configuration we created a tag library with the namespace "font" and no tags. Since tag libraries are used as libraries we need to add a font_tag_library.ecf in the same folder as well:

<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-5-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-5-0 http://www.eiffel.com/developers/xml/configuration-1-5-0.xsd" name="font_tag_library" uuid="491B4344-79AF-43CB-891B-47EDEAC11056" library_target="font_tag_library">
	<target name="font_tag_library">
		<root all_classes="true"/>
		<option full_class_checking="true" syntax="transitional">
			<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
		</option>
		<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
		<library name="xebra_ast_elements" location="$XEBRA_DEV\eiffel_projects\library\xebra_ast_elements\xebra_ast_elements-voidunsafe.ecf"/>
		<library name="xebra_tags" location="$XEBRA_DEV\eiffel_projects\library\xebra_tags\xebra_tags-voidunsafe.ecf"/>
		<library name="xebra_utilities" location="$XEBRA_DEV\eiffel_projects\library\xebra_utilities\xebra_utilities-voidunsafe.ecf"/>
		<cluster name="font_tag_library" location=".\" recursive="true">
			<file_rule>
				<exclude>/EIFGENs$</exclude>
				<exclude>/.svn$</exclude>
				<exclude>/CVS$</exclude>
			</file_rule>
		</cluster>
	</target>
</system>

Adding Tags

To add our boldifying tag we need to add it to the config.taglib on the one hand and implement an eiffel class representing it on the other. The config.taglib looks like this now:

<taglib id="xeb">
        <tag id="bold" class="FONT_BOLD_TAG">		
            <attribute id="text"/>
        </tag>
    </taglib>