Search in sources :

Example 1 with LessSource

use of org.lesscss.LessSource 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);
}
Also used : LessSource(org.lesscss.LessSource) FileOutputStream(java.io.FileOutputStream) LessCompiler(org.lesscss.LessCompiler) PortletContext(javax.portlet.PortletContext) File(java.io.File) URL(java.net.URL)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 URL (java.net.URL)1 PortletContext (javax.portlet.PortletContext)1 LessCompiler (org.lesscss.LessCompiler)1 LessSource (org.lesscss.LessSource)1