<project name="page-impl.xml">
    <target name="-build-output-microload-page">
        <if>
            <x-is-true value="${build.enable.embedded.manifest}"/>
            <then>
                <x-compile refid="${compiler.ref.id}">
                    <![CDATA[
                    # generate microloader file
                    microload
                        -operation=microloader
                        -microloaderPath=${app.microloader.path}
                        -tpl=${build.microloader.code.tpl}
                        -out=${build.microloader.path}
                    and
                    # generate json file
                    microload
                        -operation=json
                        -append
                        -tpl=${build.microloader.json.tpl.embedded}
                        -out=${build.microloader.path}
                    ]]>
                </x-compile>
            </then>
            <else>
                <x-compile refid="${compiler.ref.id}">
                    <![CDATA[
                    # generate json file
                    microload
                        -operation=json
                        -tpl=${build.microloader.json.tpl.standalone}
                        -out=${build.out.json.path}
                    and
                    # generate microloader file
                    microload
                        -operation=microloader
                        -microloaderPath=${app.microloader.path}
                        -tpl=${build.microloader.code.tpl}
                        -out=${build.microloader.path}
                    and
                    microload
                        -operation=json
                        -append
                        -tpl=${build.microloader.json.tpl.external}
                        -out=${build.microloader.path}
                    ]]>
                </x-compile>
            </else>
        </if>
        
        <if>
            <x-is-true value="${build.enable.embedded.microloader}"/>
            <then>
                <x-sencha-command dir="${app.dir}" inheritall="true">
                    <![CDATA[
                        fs
                            minify
                                ${build.embedded.microloader.compressor}
                                -from=${build.microloader.path}
                                -to=${build.microloader.path}
                    ]]>
                </x-sencha-command>
                <x-compile refid="${compiler.ref.id}">
                    <![CDATA[
                    markup
                        -contentFile=${build.microloader.path}
                        -tpl=${build.embedded.microloader.tpl}
                        -out=${build.out.page.path}
                    ]]>
                </x-compile>

                <!--once the generated microloader file is embedded, delete it-->
                <delete file="${build.microloader.path}"/>
            </then>
            <else>
                <x-compile refid="${compiler.ref.id}">
                    <![CDATA[
                    markup
                        -markup=${build.external.microloader.markup}
                        -out=${build.out.page.path}
                    ]]>
                </x-compile>
            </else>
        </if>
         
    </target>
    
    <!-- generates a separate json manifest for use with native packager -->
    <target name="-build-standalone-json-manifest">
        <x-run-if-true value="${enable.standalone.manifest}">
            <x-compile refid="${compiler.ref.id}">
                <![CDATA[
                # generate json file
                microload
                    -operation=json
                    -tpl=${build.microloader.json.tpl.standalone}
                    -out=${build.out.json.path}
                ]]>
            </x-compile>
        </x-run-if-true>
    </target>
    
    <target name="-build-output-markup-page">
        <condition property="internal.app.css.rel" value="${app.out.css.rel}">
            <x-is-true value="${enable.ext42.themes}"/>
        </condition>
        <property name="internal.app.css.rel" value=""/>

        <x-compile refid="${compiler.ref.id}">
            <![CDATA[
            markup
                -out=${build.out.page.path}
            ]]>
        </x-compile>
    </target>
    
    <!-- '-detect-app-build-properties' is defined in js-impl.xml -->
    <target name="-build-output-page" 
            depends="-detect-app-build-properties,-build-standalone-json-manifest">
        <if>
            <x-is-true value="${build.output.markuponly}"/>
            <then>
                <x-ant-call target="-build-output-markup-page"/>
            </then>
            <else>
                <x-ant-call target="-build-output-microload-page"/>
            </else>
        </if>
    </target>
    
    <target name="-copy-app-resources" depends="-init-compiler">
        <if>
            <x-is-false value="${build.output.markuponly}"/>
            <then>
                <x-compile refid="${compiler.ref.id}">
                    <![CDATA[
                    app-resources
                        -compress=${enable.resource.compression}
                        -out=${build.dir}
                    ]]>
                </x-compile>
            </then>
        </if>
    </target>
    
    <target name="-generate-deltas" depends="-init-compiler">
        <if>
            <and>
                <x-is-true value="${enable.deltas}"/>
                <x-is-false value="${build.output.markuponly}"/>
            </and>
            <then>
                <x-compile refid="${compiler.ref.id}">
                    <![CDATA[
                    deltas
                        -archivePath=${build.out.archive.path}
                        -deltaPath=${build.out.delta.path}
                        -resourcePath=${build.dir}
                    ]]>
                </x-compile>
            </then>
        </if>
    </target>
    
    <target name="-generate-cache-manifest" depends="-init-compiler">
        <if>
            <and>
                <x-is-true value="${enable.cache.manifest}"/>
                <x-is-false value="${build.output.markuponly}"/>
            </and>
            <then>
                <x-compile refid="${compiler.ref.id}">
                    <![CDATA[
                    cache-manifest
                        -cacheManifestPath=${build.manifest.path}
                    ]]>
                </x-compile>
                <replace file="${build.out.page.path}"
                         token="&lt;html manifest=&quot;&quot;"
                         value="&lt;html manifest=&quot;${build.manifest.name}&quot;"/>
            </then>
        </if>
    </target>
    
    <target name="-before-page"/>
    <target name="-page" 
            depends="-copy-app-resources,
                     -generate-deltas,
                     -build-output-page,
                     -generate-cache-manifest"/>
    <target name="-after-page"/>
</project>