Skip to content
Nat! edited this page Mar 1, 2023 · 3 revisions

About

Imagine MulleScion as logic-less template system, with some logic added. A template should not be as complex as a script. But it is still convenient to be able to perform some small logical operations in a template.

Give it a try

To try out an example, compile the project and put mulle-scion into your $PATH. It's a commandline program.

Run an example file:

mulle-scion 'dox/set.scion' 'dox/properties.plist'

General Structure

Comments are enclosed in {# and #}.

Expressions, i.e. values that produce output are enclosed in {{ and }}.

Commands are enclosed in {% and %}. You can have multiple commands, if you separate them with semicolons or newlines. Commands do not produce output. Everything between comments, expressions and commands is copied verbatim to the output.

Commands

MulleScion has a small assortment of logic commands like if else endif, for endfor, while endwhile together with various preprocessing commands like define, block and template. Look at the documentation of each keyword for more information

Expressions

In a MulleScion template expressions are filled with properties from an object. That object can be anything NSObject based. The data is accessed through key value coding. Anything between two curly brackets '{' is called an expression. The expresssion is evaluated and the resulting value is added to the output.

Example 1

name={{ name }}

Output:

name=VfL Bochum 1848

Expressions can be postprocessed with pipes.

Example 2

when={{ name | lowercaseString }}

Output:

when=vfl bochum 1848

Pipes can also contain ObjC calls with parameters, where the left side of the pipe is substituted for self in the right side.

Example 3

when={{ name | [self stringByReplacingOccurrencesOfString:@" 1848" withString:@""] }}

Output:

when=VfL Bochum

Key Value Coding

As that can become unwieldy, you can use a define to make common calls nicer to read.

Example 4

{% define no1848 = [self stringByReplacingOccurrencesOfString:@" 1848"
                                                   withString:@""] %}
when={{ name | no1848 }}

Output:

when=VfL Bochum

You have full key value coding available. With for loops can you iterate over collections just like NSEnumerator (it is in an NSEnumerator internally :))

Example 5

The bag contains {{ bag.@count }} entries
{% if defined( "bag") %}
{% for item in [bag allKeys] %}
   {{ [bag objectForKey:item] }}
{% endfor %}
{% endif %}

Output:

The bag contains 0 entries
   b (value)
   a (value)

But with dots separated by spaces you can do even more complicated KVC.

Multiline commands

You can place multiple commands within one {% and %} container. Separate the commands with semicolon or newlines. For convenience you can mix output expressions {{ }} with commands. The above example then could be written equivalently as

Example 6

The bag contains {{ bag.@count }} entries
{%
   if defined( "bag")
      for item in [bag allKeys]
         {{ @"   " }} {{ [bag objectForKey:item] }} {{ @"\n" }}
      endfor
   endif
%}

Output:

The bag contains 0 entries
   b (value)
   a (value)

Not all commands may appear in multiline commands. You can use

  • block/endblock
  • define
  • extends
  • includes
  • macro
  • requires
  • verbatim

only in single line commands.

See properties.plist for the values used in this example.

Clone this wiki locally