{% import "Juice/macros/meta.html" as meta with context %}

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

    <meta charset="{{ charset | safe }}">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ title | replace("%s", __.__META__["title"]) | safe }}</title>
    {{ meta.meta("description", __.__META__["description"]) }}
    {{ set_favicon(favicon) }}

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

    {{ css('juice-all.css') }}
    {{ js('jquery.js') }}
    {{ js('juice-all.js') }}

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

    {{ fontawesome(fontawesome_version) }}

{%- endmacro -%}

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


{#: JS--------------------------------------------------------------- #}
{%- macro js(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 %}



{#
 To create an image
 Has the option of making that image easyload

 params:
    - file: The image name
    - lazy: (bool) if True, it will be lazy loaded
    - static: (bool) it will be treated as static files if true
    - responsive: (bool)
#}
{% macro img(file, lazy=true, responsive=true, static=false) %}
    {% set _class = kwargs.pop('class', '') %}
    {% set _responsive = "responsive" if responsive else "" %}

    {% set blank_image_1x1 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNgYAAAAAMAASsJTYQAAAAASUVORK5CYII=" %}
    {% set image_file = static_file(file) if static else file%}
    {% set lazy_class = "lazy" %}

    {% if lazy %}
        {% set img_src = blank_image_1x1 %}
        {% set data_src = image_file %}
    {% else %}
        {% set img_src = image_file %}
        {% set data_src = "" %}
        {% set lazy_class = "" %}
    {% endif %}


    <img src="{{ img_src }}"
         data-src="{{ data_src }}"
         class="{{ lazy_class }} {{ _responsive }} {{ _class }}"
         {% for key in kwargs %}{{key | safe}}="{{kwargs[key]|safe}}"{% endfor %}
    >
{% endmacro %}


{#: OEMBED ------------------------------------------------------------------ #}
{#
To
#}
{%  macro oembed(url, title="") %}
    <a href="{{ url }}" class="oembed">{{ title }}</a>
{%  endmacro %}



#-------------------------------------------------------------------------------


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


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


{% macro bootswatch_theme(name) %}
    {{ css('Juice/bootswatch/%s.css' % name) }}
{% 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) }}"
        Juice.setup_authomatic(redirect)
    })
</script>
{% endmacro %}

#-------------------------------------------------------------------------------






