Skip to content
Snippets Groups Projects
Commit 165e959c authored by Guillaume Delhumeau's avatar Guillaume Delhumeau
Browse files

XWIKI-10708: Allow LESS syntax in SSX.

* Add the property "contentType" to the SSX objects
* SSX objects can handle LESS code
* Create Skin and Color Theme references
* Continuing the refactoring of the LESS module to be able to compile LESS resources that are not files
* Lot of tests done locally in addition of unit tests, that is why I allow myself to low down the jacoco requirement, with the ambition to write new tests in the following weeks.
parent ff96c6ff
No related branches found
No related tags found
No related merge requests found
Showing
with 400 additions and 56 deletions
......@@ -17,15 +17,16 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss;
package org.xwiki.lesscss.cache;
import org.xwiki.component.annotation.Role;
import org.xwiki.lesscss.colortheme.ColorTheme;
import org.xwiki.stability.Unstable;
/**
* Component to cache color themes computed from LESS files.
*
* @since 6.1M2
* @since 6.4M2
* @version $Id$
*/
@Unstable
......
......@@ -17,14 +17,18 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss;
package org.xwiki.lesscss.cache;
import org.xwiki.lesscss.colortheme.ColorThemeReference;
import org.xwiki.lesscss.resources.LESSResourceReference;
import org.xwiki.lesscss.skin.SkinReference;
/**
* Component to cache objects computed from a LESS files contained in the skin.
*
* @param <T> class of the objects to cache
*
* @since 6.1M2
* @since 6.4M2
* @version $Id$
*/
public interface LESSCache<T>
......@@ -32,25 +36,22 @@ public interface LESSCache<T>
/**
* Get an object from the name of the LESS source, the skin and the name of the color theme.
* @param lessResourceReference reference of the code to compile
* @param skin name of the skin
* @param colorTheme name of the color theme
* @param skin reference of the skin
* @param colorTheme reference of the color theme
* @return the corresponding CSS
*
* @since 6.4M2
*/
T get(LESSResourceReference lessResourceReference, String skin, String colorTheme);
T get(LESSResourceReference lessResourceReference, SkinReference skin, ColorThemeReference colorTheme);
/**
* Add an object in the cache.
*
* @param lessResourceReference reference of the code to compile
* @param skin name of the skin
* @param colorThemeName name of the color theme
* @param skin reference of the skin
* @param colorThemeName reference of the color theme
* @param object the object to cache
*
* @since 6.4M2
*/
void set(LESSResourceReference lessResourceReference, String skin, String colorThemeName, T object);
void set(LESSResourceReference lessResourceReference, SkinReference skin, ColorThemeReference colorThemeName,
T object);
/**
* Clear the cache.
......@@ -60,27 +61,21 @@ public interface LESSCache<T>
/**
* Clear all the cached content related to a skin.
*
* @param skin name of the filesystem skin
*
* @since 6.4M2
* @param skin reference to the skin
*/
void clearFromSkin(String skin);
void clearFromSkin(SkinReference skin);
/**
* Clear all the cached content related to a color theme.
*
* @param colorTheme name of the color theme
*
* @since 6.3M2
* @param colorTheme reference of the color theme
*/
void clearFromColorTheme(String colorTheme);
void clearFromColorTheme(ColorThemeReference colorTheme);
/**
* Clear all the cached content related to a LESS resource.
*
* @param lessResourceReference reference of a LESS resource
*
* @since 6.4M2
*/
void clearFromLESSResource(LESSResourceReference lessResourceReference);
}
......@@ -17,20 +17,20 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss;
package org.xwiki.lesscss.cache;
import org.xwiki.component.annotation.Role;
import org.xwiki.stability.Unstable;
/**
* Component to cache already computed LESS files contained in the skin.
* Component to cache already computed LESS resources.
*
* @since 6.1M1
* @since 6.4M2
* @version $Id$
*/
@Role
@Unstable
public interface LESSSkinFileCache extends LESSCache<String>
public interface LESSResourcesCache extends LESSCache<String>
{
}
......@@ -17,7 +17,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss;
package org.xwiki.lesscss.colortheme;
import java.util.HashMap;
......@@ -26,7 +26,7 @@
/**
* Map containing color theme variables and their values.
*
* @since 6.1M2
* @since 6.4M2
* @version $Id$
*/
@Unstable
......
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss.colortheme;
import org.xwiki.stability.Unstable;
/**
* A reference to a color theme.
*
* @since 6.4M2
* @version $Id$
*/
@Unstable
public interface ColorThemeReference
{
@Override
boolean equals(Object o);
@Override
int hashCode();
}
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss.colortheme;
import org.xwiki.component.annotation.Role;
import org.xwiki.lesscss.compiler.LESSCompilerException;
import org.xwiki.stability.Unstable;
/**
* Factory to create the appropriate reference depending on a color theme name.
*
* @since 6.4M2
* @version $Id$
*/
@Role
@Unstable
public interface ColorThemeReferenceFactory
{
/**
* @param colorThemeName name of the color theme
* @return the appropriate reference depending on the color theme name
* @throws LESSCompilerException if problem occurs
*/
ColorThemeReference createReference(String colorThemeName) throws LESSCompilerException;
}
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss.colortheme;
import org.xwiki.component.annotation.Role;
import org.xwiki.stability.Unstable;
/**
* Serialize to a string a {@link ColorThemeReference}.
*
* @since 6.4M2
* @version $Id$
*/
@Role
@Unstable
public interface ColorThemeReferenceSerializer
{
/**
* @param colorThemeReference a reference to a color theme
* @return the serialized reference
*/
String serialize(ColorThemeReference colorThemeReference);
}
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss.colortheme;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.stability.Unstable;
/**
* Specialized implementation of {@link org.xwiki.lesscss.colortheme.ColorThemeReference} for color theme stored as a
* document in the wiki.
*
* @since 6.4M2
* @version $Id$
*/
@Unstable
public class DocumentColorThemeReference implements ColorThemeReference
{
private DocumentReference colorThemeDocument;
/**
* Construct a new reference.
* @param colorThemeDocument reference to the color theme document
*/
public DocumentColorThemeReference(DocumentReference colorThemeDocument)
{
this.colorThemeDocument = colorThemeDocument;
}
/**
* @return the color theme document
*/
public DocumentReference getColorThemeDocument()
{
return colorThemeDocument;
}
@Override
public boolean equals(Object o) {
if (o instanceof DocumentColorThemeReference) {
DocumentColorThemeReference documentSkinReference = (DocumentColorThemeReference) o;
return colorThemeDocument.equals(documentSkinReference.colorThemeDocument);
}
return false;
};
@Override
public int hashCode() {
return colorThemeDocument.hashCode();
}
@Override
public String toString()
{
return String.format("ColorThemeDocument[%s]", colorThemeDocument);
}
}
......@@ -17,16 +17,17 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss;
package org.xwiki.lesscss.colortheme;
import org.xwiki.component.annotation.Role;
import org.xwiki.lesscss.compiler.LESSCompilerException;
/**
* Component to parse a LESS skin file and to return a Color Theme from it.
*
* This component must cache its results in an instance of {@link ColorThemeCache}.
* This component must cache its results in an instance of {@link org.xwiki.lesscss.cache.ColorThemeCache}.
*
* @since 6.1M2
* @since 6.4M2
* @version $Id$
*/
@Role
......@@ -37,7 +38,7 @@ public interface LESSColorThemeConverter
* @param fileName name of the LESS file
* @param force force the computation, even if the output is already in the cache (not recommended)
* @return the computed Color Theme
* @throws LESSCompilerException if problem occurs
* @throws org.xwiki.lesscss.compiler.LESSCompilerException if problem occurs
*/
ColorTheme getColorThemeFromSkinFile(String fileName, boolean force) throws LESSCompilerException;
......
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss.colortheme;
import org.xwiki.stability.Unstable;
/**
* Specialized implementation of {@link org.xwiki.lesscss.colortheme.ColorThemeReference} for color themes that are not
* stored in the wiki (currently, it concerns the "default" color theme only).
*
* @since 6.4M2
* @version $Id$
*/
@Unstable
public class NamedColorThemeReference implements ColorThemeReference
{
private String colorThemeName;
/**
* Construct a new reference to a color theme that is not stored in the wiki.
* @param colorThemeName name of the color theme
*/
public NamedColorThemeReference(String colorThemeName)
{
this.colorThemeName = colorThemeName;
}
/**
* @return the color theme name
*/
public String getColorThemeName()
{
return colorThemeName;
}
@Override
public boolean equals(Object o) {
if (o instanceof NamedColorThemeReference) {
NamedColorThemeReference namedColorThemeReference = (NamedColorThemeReference) o;
return colorThemeName.equals(namedColorThemeReference.colorThemeName);
}
return false;
};
@Override
public int hashCode() {
return colorThemeName.hashCode();
}
@Override
public String toString()
{
return String.format("ColorThemeFS[%s]", colorThemeName);
}
}
......@@ -17,9 +17,10 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss;
package org.xwiki.lesscss.compiler;
import org.xwiki.component.annotation.Role;
import org.xwiki.lesscss.resources.LESSResourceReference;
import org.xwiki.stability.Unstable;
/**
......@@ -42,12 +43,13 @@ public interface IntegratedLESSCompiler
* @param lessResourceReference reference of the LESS resource to compile
* @param includeSkinStyle include the main LESS file of the skin in order to have variables and mix-ins
* defined there
* @param useVelocity either or not the resource be parsed by Velocity before compiling it
* @param force force the computation, even if the output is already in the cache (not recommended)
* @return the generated CSS
* @throws LESSCompilerException if problems occur
*/
String compile(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean force)
throws LESSCompilerException;
String compile(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity,
boolean force) throws LESSCompilerException;
/**
* Compile a LESS resource.
......@@ -59,10 +61,11 @@ String compile(LESSResourceReference lessResourceReference, boolean includeSkinS
* @param includeSkinStyle include the main LESS file of the skin in order to have variables and mix-ins
* defined there
* @param skin includeSkinStyle of the skin where the LESS file is located
* @param useVelocity either or not the resource be parsed by Velocity before compiling it
* @param force force the computation, even if the output is already in the cache (not recommended)
* @return the generated CSS
* @throws LESSCompilerException if problems occur
*/
String compile(LESSResourceReference lessResourceReference, boolean includeSkinStyle, String skin,
boolean force) throws LESSCompilerException;
String compile(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity,
String skin, boolean force) throws LESSCompilerException;
}
......@@ -17,7 +17,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss;
package org.xwiki.lesscss.compiler;
import java.nio.file.Path;
......@@ -27,7 +27,7 @@
/**
* This component provides a LESS preprocessor (http://lesscss.org/) for CSS generation.
*
* @since 6.1M1
* @since 6.4M2
* @version $Id$
*/
@Role
......
......@@ -17,12 +17,12 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss;
package org.xwiki.lesscss.compiler;
/**
* Exception related to the LESS preprocessor.
*
* @since 6.1M1
* @since 6.4M2
* @version $Id$
*/
public class LESSCompilerException extends Exception
......
......@@ -17,7 +17,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss;
package org.xwiki.lesscss.compiler;
import org.xwiki.component.annotation.Role;
import org.xwiki.stability.Unstable;
......@@ -26,9 +26,9 @@
* This component provides a LESS preprocessor for the generation of CSS files from LESS sources located in the current
* skin directory.
*
* This component must cache the outputs of compilation in an instance of {@link org.xwiki.lesscss.LESSSkinFileCache}.
* This component must cache the outputs of compilation in an instance of {@link org.xwiki.lesscss.cache.LESSResourcesCache}.
*
* @since 6.1M1
* @since 6.4M2
* @version $Id$
* @deprecated use IntegratedLESSCompiler instead.
*/
......
......@@ -17,19 +17,19 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss;
package org.xwiki.lesscss.resources;
import org.xwiki.model.reference.ObjectPropertyReference;
import org.xwiki.stability.Unstable;
/**
* A reference to a LESS resource containing in the wiki.
* A reference to a LESS resource containing in an XObject property in the wiki.
*
* @since 6.4M2
* @version $Id$
*/
@Unstable
public class LESSEntityResourceReference implements LESSResourceReference
public class LESSObjectPropertyResourceReference implements LESSResourceReference
{
private ObjectPropertyReference objectPropertyReference;
......@@ -37,7 +37,7 @@ public class LESSEntityResourceReference implements LESSResourceReference
* Constructor.
* @param objectPropertyReference reference to the property of an XObject storing some LESS code
*/
public LESSEntityResourceReference(ObjectPropertyReference objectPropertyReference)
public LESSObjectPropertyResourceReference(ObjectPropertyReference objectPropertyReference)
{
this.objectPropertyReference = objectPropertyReference;
}
......@@ -53,12 +53,18 @@ public ObjectPropertyReference getObjectPropertyReference()
@Override
public boolean equals(Object o)
{
if (o instanceof LESSObjectPropertyResourceReference) {
LESSObjectPropertyResourceReference lessObjectPropertyResourceReference =
(LESSObjectPropertyResourceReference) o;
return objectPropertyReference.equals(lessObjectPropertyResourceReference.objectPropertyReference);
}
return false;
}
@Override
public int hashCode()
{
return 1;
return objectPropertyReference.hashCode();
}
}
......@@ -17,9 +17,10 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss;
package org.xwiki.lesscss.resources;
import org.xwiki.component.annotation.Role;
import org.xwiki.lesscss.compiler.LESSCompilerException;
import org.xwiki.stability.Unstable;
/**
......@@ -37,7 +38,7 @@ public interface LESSResourceContentReader
* @param lessResourceReference a reference to a LESS resource
* @param skin skin used for the compilation
* @return the content
* @throws LESSCompilerException if problem occurs
* @throws org.xwiki.lesscss.compiler.LESSCompilerException if problem occurs
*/
String getContent(LESSResourceReference lessResourceReference, String skin) throws LESSCompilerException;
}
......@@ -17,7 +17,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss;
package org.xwiki.lesscss.resources;
import org.xwiki.stability.Unstable;
......
......@@ -17,7 +17,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss;
package org.xwiki.lesscss.resources;
import org.xwiki.component.annotation.Role;
import org.xwiki.stability.Unstable;
......
......@@ -17,7 +17,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss;
package org.xwiki.lesscss.resources;
/**
* A reference to a skin file located in the "less" directory.
......
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.lesscss.skin;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.stability.Unstable;
/**
* A specialized implementation of {@link SkinReference} for any skin stored as a document in the wiki.
*
* @since 6.4M2
* @version $Id$
*/
@Unstable
public class DocumentSkinReference implements SkinReference
{
private DocumentReference skinDocument;
/**
* Construct a new document skin reference.
* @param skinDocument reference to the skin document
*/
public DocumentSkinReference(DocumentReference skinDocument)
{
this.skinDocument = skinDocument;
}
/**
* @return the skin document
*/
public DocumentReference getSkinDocument()
{
return skinDocument;
}
@Override
public boolean equals(Object o) {
if (o instanceof DocumentSkinReference) {
DocumentSkinReference documentSkinReference = (DocumentSkinReference) o;
return skinDocument.equals(documentSkinReference.skinDocument);
}
return false;
};
@Override
public int hashCode() {
return skinDocument.hashCode();
}
@Override
public String toString()
{
return String.format("SkinDocument[%s]", skinDocument);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment