Skip to content

Commit

Permalink
Enabled re-use of JS optimization for apidoc site.
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlenz committed Jun 14, 2011
1 parent 6f2a595 commit 15196ef
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 21 deletions.
2 changes: 2 additions & 0 deletions apidoc/config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
template.optimized.xhtml
template.previous.xhtml
9 changes: 5 additions & 4 deletions apidoc/config/template.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
<script type="text/javascript" src="/js/jquery.dataTables.min.js"></script>


<script type="text/javascript" src="/js/apidoc/jquery.treeview.js"></script>
<script type="text/javascript" src="/apidoc/js/jquery.treeview.js"></script>

<script type="text/javascript" src="/js/apidoc/tooltip.js"></script>
<script type="text/javascript" src="/apidoc/js/tooltip.js"></script>
<script type="text/javascript" src="/apidoc/js/toc_filter.js"></script>

<!--[if lte IE 7]>
<link href="/css/v-1/screen_ie.css" rel="stylesheet" type="text/css" media="screen" />
Expand All @@ -47,10 +48,10 @@
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript" src="/js/apidoc/jquery.cookie.js"></script>
<script type="text/javascript" src="/apidoc/js/jquery.cookie.js"></script>

<!--
<script type="text/javascript" src="/js/apidoc/splitter.js"></script>
<script type="text/javascript" src="/apidoc/js/splitter.js"></script>
-->


Expand Down
2 changes: 1 addition & 1 deletion apidoc/controller/url_rewrite.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ declare function local:transform($source-doc) as xs:string {
"/controller/notfound.xqy"

(: Remove version from the URL for versioned assets :)
else if (matches($path, '^/(js|css|images)/v-[0-9]*/.*')) then
else if (matches($path, '^/(css|images)/v-[0-9]*/.*')) then
replace($path, '/v-[0-9]*', '')

(: Static files or 404 :)
Expand Down
1 change: 1 addition & 0 deletions apidoc/js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
optimized
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions apidoc/setup/README.js-optimization.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
From within /apidoc/setup, we're reusing the same JavaScript
optimization code in /setup, via simple wrappers (optimize-js.sh
and optimize-js-requests.xsl) around the original scripts. See
/setup/README.txt for more info.

Follow the same instructions here as you would there, i.e.
run optimize-js.sh from within this directory (/apidoc/setup).
12 changes: 12 additions & 0 deletions apidoc/setup/optimize-js-requests.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="../../setup/optimize-js-requests.xsl"/>

<!-- These settings override the ones in the imported code. -->
<xsl:variable name="absolute-js-dir" select="'/apidoc/js/optimized'"/> <!-- URL path prefix to optimized JS file -->
<xsl:variable name="js-relative-path-prefix" select="'../..'"/> <!-- For finding the JS files relative to the stylesheet -->
<xsl:variable name="stylesheet-uri" select="static-base-uri()"/> <!-- This stylesheet URI -->
<xsl:variable name="server" select="'apidoc'"/> <!-- Used only for informational messages to the console -->

</xsl:stylesheet>
3 changes: 3 additions & 0 deletions apidoc/setup/optimize-js.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

source ../../setup/optimize-js.sh
1 change: 0 additions & 1 deletion apidoc/setup/render-toc.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

<xsl:template match="/">
<div id="all_tocs">
<script type="text/javascript" src="/js/apidoc/toc_filter.js"></script>
<script type="text/javascript">
<xsl:comment>
$(function() {
Expand Down
2 changes: 1 addition & 1 deletion apidoc/view/page.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<xsl:variable name="site-url-for-disqus" select="'http://api.marklogic.com'"/>

<xsl:variable name="template" select="u:get-doc('/apidoc/config/template.xhtml')"/>
<xsl:variable name="template-dir" select="'/apidoc/config'"/>

<!-- Links in content (function descriptions and list page intros) may need to be rewritten
to include the current explicitly specified version -->
Expand Down
1 change: 1 addition & 0 deletions controller/access.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<paths>
<prefix>/css/</prefix>
<prefix>/js/</prefix>
<prefix>/apidoc/js/</prefix>
<prefix>/images/</prefix>
<prefix>/hacks/</prefix>
<prefix>/favicon.ico</prefix>
Expand Down
4 changes: 4 additions & 0 deletions git-hooks/developer.marklogic.com/post-receive
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ git checkout -f
export PATH=/usr/local/bin:$PATH
cd /space/git/rundmc.git/setup
./optimize-js.sh

# Enable the following once we merge the apidoc branch to master
#cd /space/git/rundmc.git/apidoc/setup
#./optimize-js.sh
3 changes: 3 additions & 0 deletions git-hooks/dmc-stage.marklogic.com/post-merge
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ export PATH=/usr/local/bin:$PATH
cd /space/git/rundmc.git/setup
./optimize-js.sh

# Enable the following once we merge the apidoc branch to master
#cd /space/git/rundmc.git/apidoc/setup
#./optimize-js.sh
31 changes: 20 additions & 11 deletions setup/optimize-js-requests.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,40 @@
<xsl:param name="previous-result"/>

<!-- Where we store the combined JS files -->
<xsl:variable name="js-dir" select="'/js/optimized'"/>
<xsl:variable name="relative-js-dir" select="'../js/optimized'"/>
<xsl:variable name="relative-config-dir" select="'../config'"/>

<!-- These variables are overridden by apidoc's import of this code. -->
<xsl:variable name="absolute-js-dir" select="'/js/optimized'"/> <!-- URL path prefix to optimized JS file -->
<xsl:variable name="js-relative-path-prefix" select="'..'"/> <!-- For finding the JS files relative to the stylesheet -->
<xsl:variable name="stylesheet-uri" select="static-base-uri()"/> <!-- This stylesheet URI -->
<xsl:variable name="server" select="'DMC'"/> <!-- Used only for informational messages to the console -->

<!-- Get the previous optimized template, if present -->
<xsl:variable name="previous-template-path" select="concat('../config/', $previous-result)"/>
<xsl:variable name="previous-template-path" select="resolve-uri(concat($relative-config-dir, '/', $previous-result), $stylesheet-uri)"/>
<xsl:variable name="previous-template" select="if (doc-available($previous-template-path))
then doc ($previous-template-path)
else ()"/>

<!-- Get the last combined result, if present -->
<xsl:variable name="last-js-path" select="concat('..', $js-dir, '/', $last-all.js)"/>
<xsl:variable name="last-js-path" select="resolve-uri(concat($relative-js-dir, '/', $last-all.js), $stylesheet-uri)"/>
<xsl:variable name="last-js" select="if (unparsed-text-available($last-js-path))
then unparsed-text ($last-js-path)
else ()"/>

<!-- Combine all the current local .js files -->
<!-- Combine all the current .js files -->
<xsl:variable name="new-js" as="xs:string">
<xsl:value-of select="/html/head/script[my:is-local-external-script(.)]/@src/unparsed-text(concat('..', .))" separator="&#xA;"/>
<xsl:value-of select="/html/head/script[my:is-local-external-script(.)]/@src
/unparsed-text(resolve-uri(concat($js-relative-path-prefix,.), $stylesheet-uri))"
separator="&#xA;"/>
</xsl:variable>

<!-- Compare the two to see if we need to update -->
<xsl:variable name="js-updated" select="not($last-js eq $new-js)"/>

<xsl:template match="/">
<!-- Always output the result to new-all.js (which will get renamed to last-all.js) -->
<xsl:result-document href="..{$js-dir}/new-all.js" method="text">
<xsl:result-document href="{$relative-js-dir}/new-all.js" method="text">
<xsl:value-of select="$new-js"/>
</xsl:result-document>
<!-- Process template contents -->
Expand All @@ -57,17 +66,17 @@
<!-- If JS has been updated or previous template is missing,
then create a new script file and reference to it -->
<xsl:when test="$js-updated or not($previous-template)">
<xsl:message>JavaScript changes detected; creating new all-*.js file</xsl:message>
<xsl:variable name="file-name" select="concat($js-dir, '/all-', current-dateTime(), '.js')"/>
<script src="{$file-name}" type="text/javascript"/>
<xsl:result-document href="..{$file-name}" method="text">
<xsl:message>JavaScript changes detected in <xsl:value-of select="$server"/>; creating new all-*.js file</xsl:message>
<xsl:variable name="file-name" select="concat('all-', current-dateTime(), '.js')"/>
<script src="{$absolute-js-dir}/{$file-name}" type="text/javascript"/>
<xsl:result-document href="{$relative-js-dir}/{$file-name}" method="text">
<xsl:value-of select="$new-js"/>
</xsl:result-document>
</xsl:when>
<!-- Otherwise, leave the existing script reference unchanged;
i.e. grab it from the last template we generated -->
<xsl:otherwise>
<xsl:message>No JavaScript changes detected; using same all-*.js file</xsl:message>
<xsl:message>No JavaScript changes detected in <xsl:value-of select="$server"/>; using same all-*.js file</xsl:message>
<xsl:copy-of select="$previous-template/html/head/script[my:is-local-external-script(.)]"/>
</xsl:otherwise>
</xsl:choose>
Expand Down
11 changes: 8 additions & 3 deletions view/page.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@
<xsl:variable name="highlight-search" select="string($params[@name eq 'hl'])"/>
<xsl:variable name="content" select="if ($highlight-search) then u:highlight-doc(/, $highlight-search) else /"/>

<xsl:variable name="template" select="if (xdmp:uri-is-file('/config/template.optimized.xhtml'))
then u:get-doc('/config/template.optimized.xhtml')
else u:get-doc('/config/template.xhtml')"/>
<xsl:variable name="template-dir" select="'/config'"/>

<xsl:variable name="optimized-template-file" select="concat($template-dir,'/template.optimized.xhtml')"/>
<xsl:variable name="regular-template-file" select="concat($template-dir,'/template.xhtml')"/>

<xsl:variable name="template" select="if (xdmp:uri-is-file($optimized-template-file))
then u:get-doc($optimized-template-file)
else u:get-doc( $regular-template-file)"/>

<xsl:variable name="preview-context" select="$params[@name eq 'preview-as-if-at']"/>

Expand Down

0 comments on commit 15196ef

Please sign in to comment.