{#
HTML Macros

#}


{#  META  #}

{#: The basic meta tag :#}
{% macro meta_tag(name, value) %}
    <meta name="{{ name }}" content="{{ value | safe }}">
{% endmacro %}

{#: Custom meta tag :#}
{% macro meta_custom(namespace, name, value) %}
    <meta {{ namespace }}="{{ name }}" content="{{ value | safe }}">
{% endmacro %}

{#: opengraph property :#}
{% macro meta_property(namespace, name, value) %}
    <meta property="{{ namespace }}:{{ name }}" content="{{ value | safe }}">
{% endmacro %}

{#: opengraph tag :#}
{%- macro meta_opengraph(name, value) -%}
    {% if value %}
        <meta property="og:{{ name }}" content="{{ value | safe }}">
    {% endif %}
{%- endmacro %}

{#: Custom meta tag :#}
{%- macro meta_googleplus(name, value) -%}
    {% if value %}
        <meta itemprop="{{ name }}" content="{{ value | safe }}">
    {% endif %}
{%- endmacro -%}

{#: Custom meta tag :#}
{%- macro meta_twitter(name, value) -%}
    {% if value %}
        <meta name="twitter:{{ name }}" content="{{ value | safe }}">
    {% endif %}
{%- endmacro -%}

{#: SOCIAL_GRAPH() ---------------------------------------------------------- #}
{%- macro opengraph(use_opengraph=True, use_googleplus=True, use_twitter=True) -%}

    {% set url = __.__META__["url"] or request.base_url %}
    {% set image =  __.__META__["image"] %}

    {% if __.__META__["use_opengraph"] and use_opengraph %}
        {{ meta_opengraph("title", __.__META__["title"]) }}
        {{ meta_opengraph("description", __.__META__["description"]) }}
        {{ meta_opengraph("url", url) }}
        {{ meta_opengraph("site_name", __.__META__["site_name"]) }}
        {%  set object_type = __.__META__["object_type"] %}
            {{- meta_opengraph("type", __.__META__["object_type"]) -}}
        {% if image %}
            {{ meta_opengraph("image", image) }}
        {% endif %}
    {% endif %}

    {% if __.__META__["use_googleplus"] and use_googleplus %}
        {{ meta_googleplus("description", __.__META__["description"]) }}
        {{ meta_googleplus("name", __.__META__["title"]) }}
        {{ meta_googleplus("url", url) }}
        {% if image %}
            {{ meta_googleplus("image", image) }}
        {% endif %}
    {% endif %}

    {% if __.__META__["use_twitter"] and use_twitter -%}
        {{ meta_twitter("title", __.__META__["title"]) }}
        {{ meta_twitter("description", __.__META__["description"]) }}
        {{ meta_twitter("url", url ) }}
        {% if image %}
            {{ meta_twitter("image", image) }}
            {{ meta_twitter("card", "summary_large_image") }}
        {% else %}
            {{ meta_twitter("card", "summary") }}
        {% endif %}
    {% endif %}

    {%  for k, v in __.__META__.properties.items() %}
        {{ meta_custom("property", k, v) }}
    {% endfor %}

{% endmacro %}


{# Create the title, charset tag #}
{% macro header(title="%title%", charset="utf-8") %}
    <meta charset="{{ charset }}">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ title | replace("%title%", __.__META__.title) | safe }}</title>
    {{ meta_tag("description", __.__META__.description) }}
{% endmacro %}

{#: Favicon :#}
{% macro favicon(path) %}
    <link rel="shortcut icon" href="{{- static_file(path) -}}">
{% endmacro %}

{% macro global_assets() %}
    {{ css_asset('global.css') }}
    {{ js_asset('jquery.js') }}
    {{ js_asset('global.js') }}
{% endmacro %}

{% macro bootstrap() %}
    {{ css_asset('bootstrap.css') }}
    {{ js_asset('bootstrap.js') }}
{% endmacro %}


{%- macro fontawesome() -%}
    {{ css_asset("vendor/font-awesome/font-awesome.min.css") }}
{%- endmacro -%}

{%- macro fontawesome_cdn(version="4.3.0") -%}
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/{{ version }}/css/font-awesome.min.css">
{%- endmacro -%}


{% macro bootswatch_theme(name) %}
    {% set file = 'Mambo/bootswatch/%s.css' % name %}
    {% set output = "gen/bootswatch_%s.css" % name %}
    {%- assets output=output, file %}
        <link rel="stylesheet" href="{{ ASSET_URL }}" type="text/css" >
    {%- endassets %}
{% endmacro %}

{#: HEADER() ----------------------------------------------------------- #}
{%- macro head(title="%s",
        favicon_="favicon.ico",
        charset="utf-8",
        add_social_graph=true,
        add_google_analytics=true,
        fontawesome_version="4.4.0") -%}

    {{ page_header() }}
    {{ favicon(favicon_) }}
    {{ global_assets() }}

    {% if add_social_graph == true %}
        {{ meta.social_graph() }}
    {% endif %}



    {% if add_google_analytics == true %}
        {{ google_analytics() }}
    {% endif %}

    {{ fontawesome(fontawesome_version) }}

{%- endmacro -%}

{#: CSS ------------------------------------------------------------- #}
{%- macro css_asset(file) %}
    {%- assets file %}
    <link rel="stylesheet" href="{{ ASSET_URL }}" type="text/css" >
    {% endassets -%}
{% endmacro -%}


{#: JS--------------------------------------------------------------- #}
{%- macro js_asset(file) %}
    {%- assets file %}
    <script type="text/javascript" src="{{ ASSET_URL }}"></script>
    {% endassets -%}
{% endmacro -%}


{#:: static_file(url) ::#}
{#:: Include static assets ::#}
{%- macro static_file(url) -%}
    {%- if not url.startswith('http') and not url.startswith('//')  -%}
        {%- set url = url_for('static', filename=url) -%}
    {%- endif -%}
    {{ url | safe }}
{%- endmacro -%}



{#: GOOGLE_ANALYTICS() ------------------------------------------------------ #}
{% macro google_analytics(code=None) %}
    {% if not code %}
        {% set code = __.APPLICATION_GOOGLE_ANALYTICS_ID %}
    {% endif %}
    {% if code %}
        <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
          (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

          ga('create', '{{ code }}', 'auto');
          ga('send', 'pageview');
        </script>
    {% endif %}
{% endmacro %}

{##-------------------------------------------------------------------------------#}

{# IN EXPERIMENT #}
{% macro oauth_providers(text="Signin with #provider", size="lg", btn_block=true) %}
<script>
    $(function(){
        var redirect = "{{ login_url_next | default(login_url_default) }}"
        Mambo.setup_authomatic(redirect)
    })
</script>
{% endmacro %}

{##-------------------------------------------------------------------------------#}



