001/*
002 *  Copyright 2017 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.web.resources;
017
018import org.apache.cocoon.components.ContextHelper;
019import org.apache.cocoon.environment.Request;
020
021import org.ametys.plugins.core.ui.resources.AbstractAmetysSASSFunctionsProvider;
022
023import io.bit3.jsass.annotation.Name;
024import io.bit3.jsass.type.SassString;
025
026/**
027 * This helper provides function that will be directly injected into Sass file compilation. 
028 * Inherited methods are NOT injected. For this reason, method that must not be accessed from Sass have to be declared in the parent class AbstractAmetysSASSHelper
029 */
030public class AmetysSassFunctionsProvider extends AbstractAmetysSASSFunctionsProvider
031{
032    /**
033     * Resolve url path inside a skin
034     * @param skin The skin name.
035     * @param path the path relative to the current skin
036     * @return the absolute path
037     */
038    public SassString skinUrl(@Name("skin") String skin, @Name("path") String path)
039    {
040        Request request = ContextHelper.getRequest(_context);
041        String resourcePath = "/skins/" + skin + path;
042        SassString url = new SassString("url(\"" + request.getContextPath() + resourcePath + "\")", false);
043        return url;
044    }
045}