IfElse Extension
This extension provides basic functionality for markdown based conditional statements to allow for the rendered content to have conditional requirements. The extension adds three commands: if
, elif
, and else
. These commands must be used in the traditional order, where the first is if
, optionally followed by any number of elif
commands and optionally a final else
command.
A complete list of the available configuration options are provided in Table 1 and the following sections demonstrate the use of the commands.
Table 1: Available configuration options for the ifelse extension.
Key | Default | Description |
---|---|---|
active | True | Toggle for disabling the extension. This only changes the initial active state, use setActive to control at runtime. |
modules | [] | A list of python modules to search for functions; by default the 'ifelse.py' extension is included. All functions called must accept the extension as the first argument. |
The "modules" configuration item provides a list of python modules to search when calling conditional functions. The default behavior of the module is equivalent to adding the following the "modules" item.
As such, any function within this module can be called by the "function" setting within the statements. This setting and the associated function is discussed further in the following section.
Simple if Statement
The "if" command requires that a function to evaluate be supplied using the "function" setting. This function must exist within the modules loaded by the extension using the "modules" configuration item (see Table 1).
This extension was originally created to allow content to depend on the application name, as such a scenario will be used to demonstrate use of the syntax. The most basic use is a single "if" statement. When the supplied function returns True
the content is displayed (see Example 1, when False
the content is ignored (see Example 2).
It is possible to flip the state of the return value and create an "if not" statement by prefixing the function with an exclamation mark, as shown in Example 3.
The input to the "function" setting is expected to a function that is available within the modules loaded by the extension. The function must accept the IfElseExtension
object as the first argument. The arguments supplied in the markdown text are appended.
For example, the hasMooseApp
function shown in the above examples is defined as follows in the extension.
The complete list of settings available for the "if" command are provided in Table 2, the "function" setting is required.
Table 2: Available settings for the "if" command.
Key | Default | Description |
---|---|---|
style | None | The style settings that are passed to rendered HTML tag. |
class | None | The class settings to be passed to rendered HTML tag. |
id | None | The class settings to be passed to the rendered tag. |
function | None | The function---with arguments---to evaluate. This setting is +required+. |
Compound if/elif/else Statements
Creating if
-elif
-else
statements is accomplished by using an if
command followed by any number of elif
commands and then a final (optional) else
command. It is important to understand that the implementation actually uses separate commands. As such, each command the if
, elif
, and/or the else
can use the inline or block version of the command definition. The extension will enforce that commands occur in the expected order.
Example 4: A if elif else
statement that mixes the command between inline and block syntax.
!if function=hasMooseApp('UnknownApp') This 'UnknownApp' was found, how did you do that? !elif! function=hasMooseApp('MooseApp') You application includes objects registered by MOOSE as follows. ``` registerMooseObject('MooseApp', Diffusion); ``` !elif-end! !else Your install is messed up!