%{

def caller = _caller
while (caller._caller) caller = caller._caller
def sm = caller.gsSM

def a = _import
if (!a) a = _require

def missings = play.modules.greenscript.utils.DependencyManager.JS_DEP_MGR.comprehend(_load?:[])
sm.addJsMissings(missings)

}%

#{list items:a?:[], as:'name'}
    %{sm.addJsMissing(name)}%
#{/list}

#{if (sm.minimize())}
    #{list items:_load?:[], as:'name'}
        %{sm.addJsLoaded(name)}%
    #{/list}
    %{def fn = play.modules.greenscript.utils.Minimizor.minimizeJs(_load?:[]);}%
    #{if (!fn.isEmpty())}
        <script type="text/javascript" src="/public/gs/${fn}" charset="utf-8"></script>
    #{/if}
    %{sm.clearLoaded()}%

    #{if _loadMissing != null}
        %{fn = play.modules.greenscript.utils.Minimizor.minimizeJs(sm.getJsMissings());}%
        #{if (!fn.isEmpty())}
            <script type="text/javascript" src="/public/gs/${fn}" charset="utf-8"></script>
        #{/if}
    #{/if}
#{/if}
#{else}
    #{list items:_load?:[], as:'name'}
        #{if (sm.addJsLoaded(name))}
            <script type="text/javascript" src="/public/${sm.jsDir()}/${name}.js" charset="utf-8"></script>
        #{/if}
    #{/list}
    %{sm.clearLoaded()}%
    #{if _loadMissing != null}
        #{list items:sm.getJsMissings(), as:'name'}
            <script type="text/javascript" src="/public/${sm.jsDir()}/${name}.js" charset="utf-8"></script>
        #{/list}
    #{/if}
#{/else}

