Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Answering my own question after a few hours of hacking...</p> <pre><code>&lt;script language="groovy" src="build.groovy" /&gt; </code></pre> <p>and this groovy script replaces any referenced javascript or css file with the file contents itself.</p> <pre><code>f = new File("${targetDir}/index.cfm") fContent = f.text fContent = jsReplace(fContent) fContent = cssReplace(fContent) f.write(fContent) // JS Replacement def jsReplace(htmlFileText) { println "Groovy: Replacing Javascript includes" // extract all matched javascript src links def jsRegex = /&lt;script [^&gt;]*src=\"([^\"]+)\"&gt;&lt;\/script&gt;/ def matcher = (htmlFileText =~ jsRegex) for (i in matcher) { // read external files in def includeText = new File(matcher.group(1)).text // sanitize the string for being regex replace string (dollar signs like jQuery/Prototype will screw it up) includeText = java.util.regex.Matcher.quoteReplacement(includeText) // weak compression (might as well) includeText = includeText.replaceAll(/\/\/.*/, "") // remove single-line comments (like this!) includeText = includeText.replaceAll(/[\n\r\f\s]+/, " ") // replace all whitespace with single space // return content with embedded file htmlFileText = htmlFileText.replaceFirst('&lt;script [^&gt;]*src="'+ matcher.group(1) +'"[^&gt;]*&gt;&lt;/script&gt;', '&lt;script type="text/javascript"&gt;'+ includeText+'&lt;/script&gt;'); } return htmlFileText; } // CSS Replacement def cssReplace(htmlFileText) { println "Groovy: Replacing CSS includes" // extract all matched CSS style href links def cssRegex = /&lt;link [^&gt;]*href=\"([^\"]+)\"[^&gt;]*&gt;(&lt;\/link&gt;)?/ def matcher = (htmlFileText =~ cssRegex) for (i in matcher) { // read external files in def includeText = new File(matcher.group(1)).text // compress CSS includeText = includeText.replaceAll(/[\n\r\t\f\s]+/, " ") // sanitize the string for being regex replace string (dollar signs like jQuery/Prototype will screw it up) includeText = java.util.regex.Matcher.quoteReplacement(includeText) // return content with embedded file htmlFileText = htmlFileText.replaceFirst('&lt;link [^&gt;]*href="'+ matcher.group(1) +'"[^&gt;]*&gt;(&lt;\\/link&gt;)?', '&lt;style type=\"text/css\"&gt;'+ includeText+'&lt;/style&gt;'); } return htmlFileText; } </code></pre> <p>So I guess that does it for me. It's been working pretty well, and it's extensible. Definitely not the best Groovy ever, but it's one of my first. Also, it required a few classpathed jars for it to compile. I lost track of which, but I believe it is the javax.scripting engine, groovy-engine.jar and groovy-all-1.5.6.jar</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload