Search in sources :

Example 1 with ColorTheme

use of org.xwiki.lesscss.internal.colortheme.ColorTheme in project xwiki-platform by xwiki.

the class DefaultLESSColorThemeConverterTest method getColorThemeFromSkinFileWhenInCache.

@Test
public void getColorThemeFromSkinFileWhenInCache() throws Exception {
    // Mocks
    ColorTheme cachedColorTheme = new ColorTheme();
    cachedColorTheme.put("key", "value1");
    LESSSkinFileResourceReference lessSkinFileResourceReference = new LESSSkinFileResourceReference("file", null, null);
    when(lessResourceReferenceFactory.createReferenceForSkinFile("file")).thenReturn(lessSkinFileResourceReference);
    when(cache.get(eq(lessSkinFileResourceReference), eq(new FSSkinReference("skin")), eq(new NamedColorThemeReference("colorTheme")))).thenReturn(cachedColorTheme);
    // Test
    ColorTheme result = mocker.getComponentUnderTest().getColorThemeFromSkinFile("file", "skin", false);
    // Verify
    assertEquals(cachedColorTheme, result);
    // Verify that the returned value is not the instance stored in the cache (that the end-user would wrongly be
    // able to modify)
    assertTrue(result != cachedColorTheme);
    // Be extra-sure :)
    result.put("key", "value2");
    assertNotEquals("value2", cachedColorTheme.get("key"));
}
Also used : ColorTheme(org.xwiki.lesscss.internal.colortheme.ColorTheme) NamedColorThemeReference(org.xwiki.lesscss.internal.colortheme.NamedColorThemeReference) FSSkinReference(org.xwiki.lesscss.internal.skin.FSSkinReference) LESSSkinFileResourceReference(org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference) Test(org.junit.Test)

Example 2 with ColorTheme

use of org.xwiki.lesscss.internal.colortheme.ColorTheme in project xwiki-platform by xwiki.

the class CachedLESSColorThemeConverter method getColorThemeFromCSS.

/**
 * Parse a CSS and returns a Color Theme.
 * @param css code to parse
 * @return the corresponding color theme
 */
private ColorTheme getColorThemeFromCSS(String css) {
    ColorTheme results = new ColorTheme();
    String cssWithoutComments = css.replaceAll("/\\*[\\u0000-\\uffff]*?\\*/", "");
    Matcher m = pattern.matcher(cssWithoutComments);
    while (m.find()) {
        String variable = m.group(1);
        String value = m.group(3);
        results.put(variable, value);
    }
    return results;
}
Also used : Matcher(java.util.regex.Matcher) ColorTheme(org.xwiki.lesscss.internal.colortheme.ColorTheme)

Example 3 with ColorTheme

use of org.xwiki.lesscss.internal.colortheme.ColorTheme in project xwiki-platform by xwiki.

the class LessCompilerScriptServiceTest method getColorThemeFromSkinFileWithException.

@Test
public void getColorThemeFromSkinFileWithException() throws Exception {
    // Mocks
    Exception exception = new LESSCompilerException("Exception with LESS", null);
    when(lessColorThemeConverter.getColorThemeFromSkinFile("style.less", false)).thenThrow(exception);
    // Test
    ColorTheme result = mocker.getComponentUnderTest().getColorThemeFromSkinFile("style.less");
    // Verify
    assertEquals(0, result.size());
}
Also used : ColorTheme(org.xwiki.lesscss.internal.colortheme.ColorTheme) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) Test(org.junit.Test)

Example 4 with ColorTheme

use of org.xwiki.lesscss.internal.colortheme.ColorTheme in project xwiki-platform by xwiki.

the class LessCompilerScriptServiceTest method getColorThemeFromSkinFileWithOtherSkinAndException.

@Test
public void getColorThemeFromSkinFileWithOtherSkinAndException() throws Exception {
    // Mocks
    Exception exception = new LESSCompilerException("Exception with LESS", null);
    when(lessColorThemeConverter.getColorThemeFromSkinFile("style.less", "flamingo", false)).thenThrow(exception);
    // Test
    ColorTheme result = mocker.getComponentUnderTest().getColorThemeFromSkinFile("style.less", "flamingo");
    // Verify
    assertEquals(0, result.size());
}
Also used : ColorTheme(org.xwiki.lesscss.internal.colortheme.ColorTheme) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) Test(org.junit.Test)

Aggregations

ColorTheme (org.xwiki.lesscss.internal.colortheme.ColorTheme)4 Test (org.junit.Test)3 LESSCompilerException (org.xwiki.lesscss.compiler.LESSCompilerException)2 Matcher (java.util.regex.Matcher)1 NamedColorThemeReference (org.xwiki.lesscss.internal.colortheme.NamedColorThemeReference)1 LESSSkinFileResourceReference (org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference)1 FSSkinReference (org.xwiki.lesscss.internal.skin.FSSkinReference)1