001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.tools.sass;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    import com.liferay.portal.servlet.filters.dynamiccss.RTLCSSUtil;
019    import com.liferay.portal.tools.SassToCssBuilder;
020    
021    /**
022     * @author Minhchau Dang
023     * @author Shuyang Zhou
024     */
025    public class SassString implements SassFragment {
026    
027            public SassString(String fileName, String sassContent) throws Exception {
028                    String cssContent = SassExecutorUtil.parse(
029                            fileName, SassToCssBuilder.parseStaticTokens(sassContent));
030    
031                    if (fileName.contains("_rtl")) {
032                            _ltrContent = StringPool.BLANK;
033                            _rtlContent = cssContent;
034                    }
035                    else {
036                            _ltrContent = cssContent;
037    
038                            if (!RTLCSSUtil.isExcludedPath(fileName)) {
039                                    _rtlContent = RTLCSSUtil.getRtlCss(fileName, cssContent);
040                            }
041                            else {
042                                    _rtlContent = null;
043                            }
044                    }
045            }
046    
047            @Override
048            public String getLtrContent() {
049                    return _ltrContent;
050            }
051    
052            @Override
053            public String getRtlContent() {
054                    return _rtlContent;
055            }
056    
057            private final String _ltrContent;
058            private final String _rtlContent;
059    
060    }