Created
May 30, 2012 17:38
-
-
Save michalbcz/2837835 to your computer and use it in GitHub Desktop.
groovy - html modification with state-of-art library JSoup -
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grapes( | |
@Grab(group='org.jsoup', module='jsoup', version='1.6.2') | |
) | |
import org.jsoup.* | |
import org.jsoup.nodes.* | |
/** | |
* during build time we combine all the js files to single file (to speed up page loading) | |
* this script is part of the this script and its purpose is to collect all the external js files refered in | |
* MasterPage.html (template for the page) to feed up function which do the real combining and minifying to | |
* 'all.js' file. Thus this script replace (in fact remove all the external script links and append new one) | |
* scripts with only the combined js file (in this case called 'all.js') | |
*/ | |
def masterPage = new File("MasterPage.html") | |
Document doc = Jsoup.parse(masterPage, "UTF-8"); | |
def scriptSources = [] | |
doc.select("script").each { element -> | |
if (element.hasAttr("src")) { | |
scriptSources << element.attr("src") | |
element.remove() | |
} | |
} | |
doc.select("script").before('<script src="/js/all.js" type="text/javascript"></script>') | |
masterPage.text = doc.outerHtml() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment