@Override public String generateUrl(String cssResultLocation) { return URIUtils.addSuffix(cssResultLocation, Constants.SOURCE_MAP_SUFFIX); } }
public static File changeSuffix(File file, String dottedSuffix) { if (file == null) return null; String filename = changeSuffix(file.toString(), dottedSuffix); return new File(filename); }
@Override public URI getURI() { try { String path = getInputFile().toString(); path = URIUtils.convertPlatformSeparatorToUri(path); return new URI(path); } catch (URISyntaxException e) { return null; } }
public static String relativize(File from, File to) { URI fromURI = from.toURI(); URI toURI = to.toURI(); String relative = getRelativePath(fromURI.toString(), toURI.toString(), URIUtils.URI_FILE_SEPARATOR); relative = convertUriToPlatformSeparator(relative); return relative; }
String normalizedTargetPath = normalizeNoEndSeparator(targetPath, pathSeparator); String normalizedBasePath = normalizeNoEndSeparator(basePath, pathSeparator); relative.append(safeSubstring(normalizedTargetPath, common.length())); return relative.toString();
private Expression extractUrlParameter(HiddenTokenAwareTree token, String function, String text) { if (text == null) return null; if (text.length() <= function.length() + 2) return new CssString(token, "", ""); String string = text.substring(function.length() + 1, text.length() - 1); if (!URIUtils.isQuotedUrl(string)) return new CssString(token, string, ""); String quote = String.valueOf(string.charAt(0)); return new CssString(token, string.substring(1, string.length() - 1), quote); }
@Override public String printSourceName(LessSource source) { if (source == null) return ""; File file = source instanceof LessSource.FileSource ? ((LessSource.FileSource) source).getInputFile() : null; if (file == null) { String name = source.getName(); return name == null ? "" : name; } if (rootInputFile == null) { return file.getPath(); } File absoluteRoot = rootInputFile.getAbsoluteFile(); File absoluteFile = file.getAbsoluteFile(); if (sameFile(absoluteRoot, absoluteFile)) return ""; return URIUtils.relativize(absoluteRoot.getParentFile(), absoluteFile); }
private String toSourceName(LessSource source) { if (configuration.isRelativizePaths()) { return URIUtils.relativizeSourceURIs(cssDestination, source); } else { return source.getURI() == null ? null : source.getURI().toString(); } }
public static String relativizeSourceURIs(LessSource from, LessSource to) { if (to == null) return null; URI toURI = to.getURI(); if (toURI == null) return to.getName(); String toURIAsString = toURI.toString(); if (from == null) return toURIAsString; URI fromURI = from.getURI(); if (fromURI == null) return toURIAsString; String fromURIAsString = fromURI.toString(); return getRelativePath(fromURIAsString, toURIAsString, URIUtils.URI_FILE_SEPARATOR); }
private String toOutputFilename(String outputDirectory, String inputFilename, String dottedSuffix) { String filename = URIUtils.changeSuffix(inputFilename, dottedSuffix); if (outputDirectory == null || outputDirectory.isEmpty()) { return filename; } if (!outputDirectory.endsWith(SEPARATOR)) { outputDirectory += SEPARATOR; } return outputDirectory + new File(filename).getName(); }
private String singleModeMapFilename(String cssFileName, boolean generateSourceMap) { return !generateSourceMap || cssFileName==null? null: URIUtils.addSuffix(cssFileName, Constants.SOURCE_MAP_SUFFIX); }
public static FileSource changeSuffix(FileSource source, String dottedSuffix) { if (source == null) return null; return new LessSource.FileSource(changeSuffix(source.getInputFile(), dottedSuffix)); }
private String getCssResultLocationName(Configuration options, LessSource source) { LessSource location = options.getCssResultLocation(); String name = location == null ? null : location.getName(); if (name == null) name = URIUtils.changeSuffix(source.getName(), Constants.CSS_SUFFIX); return name; }
private CompilationResult createCompilationResult(ASTCssNode cssStyleSheet, LessSource lessSource, List<VariableDeclaration> externalVariables, Collection<LessSource> additionalSourceFiles, Configuration options) { LessSource cssDestination = options == null ? null : options.getCssResultLocation(); if (cssDestination == null) { String guessedCssName = URIUtils.changeSuffix(lessSource.getName(), Constants.CSS_SUFFIX); URI guessedURI = URIUtils.changeSuffix(lessSource.getURI(), Constants.CSS_SUFFIX); cssDestination = new LessSource.StringSource("", guessedCssName, guessedURI); } CssPrinter builder = new CssPrinter(lessSource, cssDestination, extractSources(externalVariables), additionalSourceFiles, options); builder.append(cssStyleSheet); StringBuilder css = builder.toCss(); String sourceMap = builder.toSourceMap(); handleSourceMapLink(cssStyleSheet, css, options, lessSource, sourceMap); CompilationResult compilationResult = new CompilationResult(css.toString(), sourceMap, problemsHandler.getWarnings()); return compilationResult; }