Class TTag

Unit

Declaration

type TTag = class(TObject)

Description

Hierarchy

Overview

Methods

Public constructor Create(ATagManager: TTagManager; const AName: string; AOnPreExecute: TTagExecuteEvent; AOnExecute: TTagExecuteEvent; const ATagOptions: TTagOptions);
Public procedure PreExecute(var ThisTagData: TObject; EnclosingTag: TTag; var EnclosingTagData: TObject; const TagParameter: string; var ReplaceStr: string); virtual;
Public procedure Execute(var ThisTagData: TObject; EnclosingTag: TTag; var EnclosingTagData: TObject; const TagParameter: string; var ReplaceStr: string); virtual;
Public function AllowedInside(EnclosingTag: TTag): boolean; virtual;
Public function CreateOccurenceData: TObject; virtual;
Public procedure DestroyOccurenceData(Value: TObject); virtual;

Properties

Public property TagOptions: TTagOptions read FTagOptions write FTagOptions;
Public property TagManager: TTagManager read FTagManager;
Public property Name: string read FName write FName;
Public property OnPreExecute: TTagExecuteEvent read FOnPreExecute write FOnPreExecute;
Public property OnExecute: TTagExecuteEvent read FOnExecute write FOnExecute;
Public property OnAllowedInside: TTagAllowedInsideEvent read FOnAllowedInside write FOnAllowedInside;

Description

Methods

Public constructor Create(ATagManager: TTagManager; const AName: string; AOnPreExecute: TTagExecuteEvent; AOnExecute: TTagExecuteEvent; const ATagOptions: TTagOptions);

Note that AName will be converted to lowercase before assigning to Name.

Public procedure PreExecute(var ThisTagData: TObject; EnclosingTag: TTag; var EnclosingTagData: TObject; const TagParameter: string; var ReplaceStr: string); virtual;

This is completely analogous to Execute but used when TTagManager.PreExecute is True. In this class this simply calls OnPreExecute.

Public procedure Execute(var ThisTagData: TObject; EnclosingTag: TTag; var EnclosingTagData: TObject; const TagParameter: string; var ReplaceStr: string); virtual;

This will be used to do main work when this @-tag occured in description.

EnclosingTag parameter specifies enclosing tag. This is useful for tags that must behave differently in different contexts, e.g. in plain-text output @item tag will behave differently inside @orderedList and @unorderedList. EnclosingTag is nil when the tag occured at top level of the description.

ThisTagData and EnclosingTagData form a mechanism to pass arbitraty data between child tags enclosed within one parent tag. Example uses:

  • This is the way for multiple @item tags inside @orderedList tag to count themselves (to provide list item numbers, for pasdoc output formats that can't automatically number list items).

  • This is the way for @itemSpacing tag to communicate with enclosing @orderedList tag to specify list style.

  • And this is the way for @cell tags to be collected inside rows data and then @rows tags to be collected inside table data. Thanks to such collecting TDocGenerator.FormatTable receives at once all information about given table, and can use it to format table.

How does this XxxTagData mechanism work:

When we start parsing parameter of some tag with toRecursiveTags, we create a new pointer inited to CreateOccurenceData. When @-tags occur inside this parameter, we pass them this pointer as EnclosingTagData (this way all @-tags with the same parent can use this pointer to communicate with each other). At the end, when parameter was parsed, we call given tag's Execute method passing the resulting pointer as ThisTagData (this way @-tags with the same parent can use this pointer to pass some data to their parent).

In this class this method simply calls OnExecute (if assigned).

Public function AllowedInside(EnclosingTag: TTag): boolean; virtual;

This will be checked always when this tag occurs within description. Given EnclosingTag is enclosing tag, nil if we're in top level. If this returns false then this tag will not be allowed inside EnclosingTag.

In this class this method

  1. Assumes that Result = true if we're at top level or EnclosingTag.TagOptions contains toAllowOtherTagsInsideByDefault. Else it assumes Result = false.

  2. Then it calls OnAllowedInside(Self, EnclosingTag, Result) (if OnAllowedInside is assigned).

Public function CreateOccurenceData: TObject; virtual;

In this class this simply returns Nil.

Public procedure DestroyOccurenceData(Value: TObject); virtual;

In this class this simply does Value.Free.

Properties

Public property TagOptions: TTagOptions read FTagOptions write FTagOptions;
 
Public property TagManager: TTagManager read FTagManager;

TagManager that will recognize and handle this tag. Note that the tag instance is owned by this tag manager (i.e. it will be freed inside this tag manager). It can be nil if no tag manager currently owns this tag.

Note that it's very useful in Execute or OnExecute implementations.

E.g. you can use it to report a message by TagManager.DoMessage(...), this is e.g. used by implementation of TPasItem.StoreAbstractTag.

You could also use this to manually force recursive behavior of a given tag. I.e let's suppose that you have a tag with TagOptions = [toParameterRequired], so the TagParameter parameter passed to handler was not recursively expanded. Then you can do inside your handler

NewTagParameter := TagManager.Execute(TagParameter, ...)

and this way you have explicitly recursively expanded the tag.

Scenario above is actually used in implementation of @noAutoLink tag. There I call TagManager.Execute with parameter AutoLink set to false thus preventing auto-linking inside text within @noAutoLink.

Public property Name: string read FName write FName;

Name of the tag, that must be specified by user after the "@" sign. Value of this property must always be lowercase.

Public property OnPreExecute: TTagExecuteEvent read FOnPreExecute write FOnPreExecute;
 
Public property OnExecute: TTagExecuteEvent read FOnExecute write FOnExecute;
 
Public property OnAllowedInside: TTagAllowedInsideEvent read FOnAllowedInside write FOnAllowedInside;
 

Generated by PasDoc 0.16.0.