use of com.github.sommeri.less4j.core.DefaultLessCompiler in project xwiki-platform by xwiki.
the class Less4jCompiler method compile.
/**
* Compile the LESS code and get the included files from the skin templates.
* @param lessCode code to compile
* @param skin skin holding the templates
* @param inlineSourceMap whether to create inline sourcemaps in the generated css
* @return the results of the LESS compilation
* @throws Less4jException if problems occur
*/
public String compile(String lessCode, String skin, boolean inlineSourceMap) throws Less4jException {
LessCompiler lessCompiler = new DefaultLessCompiler();
LessCompiler.Configuration options = new LessCompiler.Configuration();
options.setCompressing(true);
options.getSourceMapConfiguration().setInline(inlineSourceMap);
options.getSourceMapConfiguration().setIncludeSourcesContent(true);
LessSource lessSource = new CustomContentLESSSource(lessCode, templateManager, skinManager.getSkin(skin));
LessCompiler.CompilationResult lessResult = lessCompiler.compile(lessSource, options);
return lessResult.getCss();
}
use of com.github.sommeri.less4j.core.DefaultLessCompiler in project xwiki-platform by xwiki.
the class CachedLESSColorThemeConverterTest method compute.
@Test
public void compute() throws Exception {
StringWriter lessSource = new StringWriter();
IOUtils.copy(getClass().getResourceAsStream("/styleWithColorTheme.less"), lessSource);
// To have a better test, we use Less4j to generate the CSS that contains the color theme mapping
LessCompiler less4jCompiler = new DefaultLessCompiler();
LessCompiler.Configuration options = new LessCompiler.Configuration();
options.setCompressing(true);
LessCompiler.CompilationResult lessResult = less4jCompiler.compile(lessSource.toString(), options);
when(lessCompiler.compile(any(LESSResourceReference.class), eq(false), eq(false), eq("skin"), eq(false))).thenReturn(lessResult.getCss());
// So now we can test the converter on the less4j output
Map<String, String> results = mocker.getComponentUnderTest().compute(new LESSSkinFileResourceReference("file", null, null), false, false, true, "skin");
assertEquals("#E8E8E8", results.get("borderColor"));
assertEquals("#3e444c", results.get("highlightColor"));
}
Aggregations