{% namespace tests.call %}

{% macro callme(name) %}{% if name %}{{name }}{% else %}I{% endif %} was called!{% endmacro %}

{% macro call1() %}{{ tests.call.callme() }}{% endmacro %}

{% macro call2() %}{{ tests.call.callme(name = "Michael") }}{% endmacro %}

{% macro dictcall(name) %}{{ name.first }} {{ name.second }}{% endmacro %}

{% macro call3() %}{{ tests.call.dictcall(name = {'first': 'Michael', 'second': 'Kerrin'}) }}{% endmacro %}

/**
 * Test call blocks
 */

// callblock1

{% macro render_dialog_box(type) -%}
<div class="{{ type }}">{{ caller() }}</div>
{%- endmacro %}

{% macro render_dialog() -%}
{% call tests.call.render_dialog_box(type = "box") -%}
Hello, World!
{%- endcall %}
{%- endmacro %}

// callblock2

{% macro list_users(users) -%}
<ul>
{%- for user in users -%}
<li>{{ caller(user = user) }}</li>
{%- endfor -%}
</ul>
{%- endmacro %}

{% macro users(users) -%}
{% call(user) tests.call.list_users(users = users) -%}
Hello, {{ user }}!
{%- endcall %}
{%- endmacro %}

// callblock3

{% macro print_user(user) -%}
Goodbye, {{ user }}!
{%- endmacro %}

{% macro users2(users) -%}
{% call(user) tests.call.list_users(users = users) -%}
{{ tests.call.print_user(user = user) }}
{%- endcall %}
{%- endmacro %}

// callblock4

{% macro users3(name, users, users_old) -%}
{% call(user) tests.call.list_users(users = users) -%}
Hello {{ user }}!
{%- endcall %}
{%- call(user) tests.call.list_users(users = users_old) -%}
Goodbye {{ user }} from {{ name }}!
{%- endcall %}
{%- endmacro %}

// callblock5 - callblocks with default values.

{% macro users4(users, name = "Michael") -%}
{%- call(user) tests.call.list_users(users = users) -%}
Hi {{ user }} from {{ name }}!
{%- endcall %}
{%- endmacro %}

// callblock6 - callblocks with default values.

{% macro list_users2(users, skip = "Michael") -%}
<ul>
{%- for user in users -%}
<li>{% if user == skip -%}
{{ caller() }}
{%- else -%}
{{ caller(user = user) }}
{%- endif %}</li>
{%- endfor -%}
</ul>
{%- endmacro %}

{% macro users5(users, name = "Michael") -%}
{%- call(user = "Anonymous") tests.call.list_users2(users = users) -%}
Hi {{ user }} from {{ name }}!
{%- endcall %}
{%- endmacro %}
