use of org.lesscss.LessCompiler in project uPortal by Jasig.
the class AbstractDynamicSkinService method processLessFile.
/**
* Less compile the include file into a temporary css file. When done rename the temporary css file to the
* correct output filename. Since the less compilation phase takes several seconds, this insures the
* output css file is does not exist on the filesystem until it is complete.
*
* @param lessIncludeFilepath less include file that includes all dependencies
* @param outputFilepath name of the output css file
* @param lessCssJavascriptUrl lessCssJavascript compiler url
* @throws IOException
* @throws LessException
*/
private void processLessFile(DynamicSkinInstanceData data) throws IOException, LessException {
final PortletContext ctx = data.getPortletRequest().getPortletSession().getPortletContext();
final URL lessCssJavascriptUrl = ctx.getResource(this.lessCssJavascriptUrlPath);
final LessSource lessSource = new LessSource(new File(this.getSkinLessPath(data)));
if (log.isDebugEnabled()) {
final String result = lessSource.getNormalizedContent();
final File lessSourceOutput = new File(this.getSkinCssTempFileAbsolutePath(data) + "lesssource");
IOUtils.write(result, new FileOutputStream(lessSourceOutput));
log.debug("Full Less source from include file {0}, using lessCssJavascript at {1}" + ", is at {2}, output css will be written to {3}", this.getSkinLessPath(data), lessCssJavascriptUrl.toString(), lessSourceOutput, this.getSkinCssPath(data));
}
final LessCompiler compiler = new LessCompiler();
compiler.setLessJs(lessCssJavascriptUrl);
compiler.setCompress(true);
final File tempOutputFile = new File(this.getSkinCssTempFileAbsolutePath(data));
compiler.compile(lessSource, tempOutputFile);
this.moveCssFileToFinalLocation(data, tempOutputFile);
}
Aggregations