Search in sources :

Example 1 with DefaultLessCompiler

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();
}
Also used : LessSource(com.github.sommeri.less4j.LessSource) DefaultLessCompiler(com.github.sommeri.less4j.core.DefaultLessCompiler) LessCompiler(com.github.sommeri.less4j.LessCompiler) DefaultLessCompiler(com.github.sommeri.less4j.core.DefaultLessCompiler)

Example 2 with DefaultLessCompiler

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"));
}
Also used : StringWriter(java.io.StringWriter) DefaultLessCompiler(com.github.sommeri.less4j.core.DefaultLessCompiler) LessCompiler(com.github.sommeri.less4j.LessCompiler) DefaultLessCompiler(com.github.sommeri.less4j.core.DefaultLessCompiler) LESSResourceReference(org.xwiki.lesscss.resources.LESSResourceReference) LESSSkinFileResourceReference(org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference) Test(org.junit.Test)

Aggregations

LessCompiler (com.github.sommeri.less4j.LessCompiler)2 DefaultLessCompiler (com.github.sommeri.less4j.core.DefaultLessCompiler)2 LessSource (com.github.sommeri.less4j.LessSource)1 StringWriter (java.io.StringWriter)1 Test (org.junit.Test)1 LESSSkinFileResourceReference (org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference)1 LESSResourceReference (org.xwiki.lesscss.resources.LESSResourceReference)1