• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java LessSource类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.github.sommeri.less4j.LessSource的典型用法代码示例。如果您正苦于以下问题:Java LessSource类的具体用法?Java LessSource怎么用?Java LessSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LessSource类属于com.github.sommeri.less4j包,在下文中一共展示了LessSource类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: source

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
private LessSource source(final String filename) throws StringSourceException {
  String[] files = {path + filename, filename };
  for (String file : files) {
    InputStream stream = getClass().getResourceAsStream(file);
    if (stream != null) {
      try {
        return new LessStrSource(
            new String(ByteStreams.toByteArray(stream), StandardCharsets.UTF_8), file);
      } catch (IOException ex) {
        log.debug("Can't read file: " + path, ex);
        throw new StringSourceException();
      } finally {
        Closeables.closeQuietly(stream);
      }
    }
  }
  throw new StringSourceException();
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:19,代码来源:LessStrSource.java


示例2: getLessStyleSheet

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
public static com.github.sommeri.less4j.core.ast.StyleSheet getLessStyleSheet(LessSource source) throws ParseException {
	
	ANTLRParser parser = new ANTLRParser();
	
	ANTLRParser.ParseResult result;
	ProblemsHandler problemsHandler = new ProblemsHandler();
	com.github.sommeri.less4j.core.ast.StyleSheet lessStyleSheet;
	ASTBuilder astBuilder = new ASTBuilder(problemsHandler);
	try {
		
		result = parser.parseStyleSheet(source.getContent(), source);

		lessStyleSheet = astBuilder.parseStyleSheet(result.getTree());			

	} catch (FileNotFound | CannotReadFile | BugHappened ex) {
		throw new ParseException(ex);
	}
	return lessStyleSheet;
}
 
开发者ID:dmazinanian,项目名称:css-analyser,代码行数:20,代码来源:LessCSSParser.java


示例3: relativeSource

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
@Override
public LessResource relativeSource(final String filename) throws LessSource.FileNotFound,
                                                                 LessSource.CannotReadFile,
                                                                 LessSource.StringSourceException {
    final Path relativePath = path.getParent().resolve(filename);
    return new LessResource(relativePath);
}
 
开发者ID:hpe-idol,项目名称:find,代码行数:8,代码来源:LessResource.java


示例4: sendResource

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
@Override
protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException {
    try {
        // compile less to css
        log.trace("Send css for '{}'", resourceUrl);
        LessSource.URLSource source = new LessSource.URLSource(resourceUrl);
        String content = source.getContent();
        String result = sourceMap.get(content);
        if (result == null) {
            ThreadUnsafeLessCompiler compiler = new ThreadUnsafeLessCompiler();
            LessCompiler.Configuration configuration = new LessCompiler.Configuration();
            configuration.setCompressing(minify);
            LessCompiler.CompilationResult compilationResult = compiler.compile(resourceUrl, configuration);
            for (LessCompiler.Problem warning : compilationResult.getWarnings()) {
                log.warn("Line: {}, Character: {}, Message: {} ", warning.getLine(), warning.getCharacter(), warning.getMessage());
            }
            result = compilationResult.getCss();

            if (routeContext.getApplication().getPippoSettings().isProd()) {
                sourceMap.put(content, result);
            }
        }

        // send css
        routeContext.getResponse().contentType("text/css");
        routeContext.getResponse().ok().send(result);
    } catch (Exception e) {
        throw new PippoRuntimeException(e);
    }
}
 
开发者ID:decebals,项目名称:pippo,代码行数:31,代码来源:LessResourceHandler.java


示例5: process

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
@Override
public String process(final String filename, final String source, final Config conf)
    throws Exception {
  String path = filename;
  try {
    LessCompiler compiler = new ThreadUnsafeLessCompiler();
    LessSource src = new LessStrSource(source, path);

    CompilationResult result = compiler.compile(src, lessConf(conf));

    result.getWarnings().forEach(warn -> {
      log.warn("{}:{}:{}:{}: {}", path, warn.getType(), warn.getLine(),
          warn.getCharacter(), warn.getMessage());
    });

    if (path.endsWith(".map")) {
      return result.getSourceMap();
    } else {
      return result.getCss();
    }
  } catch (Less4jException ex) {
    List<AssetProblem> problems = ex.getErrors().stream()
        .map(it -> new AssetProblem(path, it.getLine(), it.getCharacter(), it.getMessage(), null))
        .collect(Collectors.toList());
    throw new AssetException(name(), problems);
  }
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:28,代码来源:Less.java


示例6: parseCSSString

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
@Override
public StyleSheet parseCSSString(String css) throws ParseException {
	
	com.github.sommeri.less4j.core.ast.StyleSheet lessStyleSheet = getLessStyleSheet(new LessSource.StringSource(css));
	
	try {
		
		LessStyleSheetAdapter adapter = new LessStyleSheetAdapter(lessStyleSheet);
		return adapter.getAdaptedStyleSheet();
		
	} catch (RuntimeException ex) {
		throw new ParseException(ex);
	}	
}
 
开发者ID:dmazinanian,项目名称:css-analyser,代码行数:15,代码来源:LessCSSParser.java


示例7: getLessParserFromStyleSheet

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
public static com.github.sommeri.less4j.core.ast.StyleSheet getLessParserFromStyleSheet(StyleSheet styleSheet) throws ParseException {

		if (styleSheet.getFilePath() == null) {
			return getLessStyleSheet(new LessSource.StringSource(styleSheet.toString()));
		} else {
			return getLessStyleSheet(new ModifiedLessFileSource(new File(styleSheet.getFilePath())));
		}
		
	}
 
开发者ID:dmazinanian,项目名称:css-analyser,代码行数:10,代码来源:LessCSSParser.java


示例8: getAdaptedStyleSheet

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
public StyleSheet getAdaptedStyleSheet() {
	StyleSheet ourStyleSheet = new StyleSheet();
	LessSource source = lessStyleSheet.getSource();
	if ((source instanceof FileSource || source instanceof URLSource) && source.getURI() != null) {
		ourStyleSheet.setPath(source.getURI().toString());
	} else if (source instanceof ModifiedLessFileSource) {
		ourStyleSheet.setPath(((ModifiedLessFileSource) source).getInputFile().getAbsolutePath());
	}
	adapt(ourStyleSheet);
	return ourStyleSheet;
}
 
开发者ID:dmazinanian,项目名称:css-analyser,代码行数:12,代码来源:LessStyleSheetAdapter.java


示例9: compileStyleSheetUsingLess4J

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
public static StyleSheet compileStyleSheetUsingLess4J(String filePath) throws ParseException {
	/*
	 * This is weird, however, it seems that when we make changes to
	 * the AST of the Less style sheet, it cannot compile because, for instance,
	 * it cannot find Mixin declarations. 
	 * For the moment, the naive approach is to parse it again.
	 */
	Configuration options = new Configuration();
	LessSource source = new FileSource(new File(filePath));
	
	/*
	 * Got from Less4j code
	 */
	ANTLRParser.ParseResult result = null;
	try {
		result = new ANTLRParser().parseStyleSheet(source.getContent(), source);
	} catch (FileNotFound | CannotReadFile ex) {
		throw new ParseException(ex);
	}

	if (result.hasErrors()) {
		CompilationResult compilationResult = new CompilationResult("Errors during parsing phase, partial result is not available.");
		throw new ParseException(new Less4jException(result.getErrors(), compilationResult));
	}

	ProblemsHandler problemsHandler = new ProblemsHandler();
	ASTBuilder astBuilder = new ASTBuilder(problemsHandler);
	LessToCssCompiler compiler = new LessToCssCompiler(problemsHandler, options);
	com.github.sommeri.less4j.core.ast.StyleSheet lessStyleSheet = astBuilder.parseStyleSheet(result.getTree());
	ASTCssNode cssStyleSheet = compiler.compileToCss(lessStyleSheet, source, options);
	
	// Adapt to our style sheet
	LessStyleSheetAdapter adapter = new LessStyleSheetAdapter(cssStyleSheet);
	StyleSheet resultingStyleSheet = adapter.getAdaptedStyleSheet();
	return resultingStyleSheet;
}
 
开发者ID:dmazinanian,项目名称:css-analyser,代码行数:37,代码来源:LessHelper.java


示例10: getCallingSelectors

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
public List<Selector> getCallingSelectors() {

		if (callingSelectors == null) {

			List<Selector> selectorsToReturn = new ArrayList<>();

			List<LessMixinCall> mixinCallInfo = queryHandler.getMixinCallInfo();
			List<List<ASTCssNode>> parentsList = getParentRuleSets(mixinCallInfo, new HashSet<>());

			if (parentsList.size() == 0)
				return selectorsToReturn;

			for (List<ASTCssNode> parents : parentsList) {
				LessPrinter printer = new LessPrinter();
				ASTCssNode rootNode = parents.get(parents.size() - 1);

				try {
					String stringOfRootNode = printer.getStringForNode(rootNode);		
					StyleSheet lessStyleSheet = LessCSSParser.getLessStyleSheet(new LessSource.StringSource(stringOfRootNode));
					ca.concordia.cssanalyser.cssmodel.StyleSheet compileLESSStyleSheet = LessHelper.compileLESSStyleSheet(lessStyleSheet);
					if (compileLESSStyleSheet.getAllSelectors().iterator().hasNext()) {
						Selector callingSelector = compileLESSStyleSheet.getAllSelectors().iterator().next();
						callingSelector.removeDeclaration(callingSelector.getDeclarations().iterator().next());
						selectorsToReturn.add(callingSelector);
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			callingSelectors = selectorsToReturn;
			
		}

		return callingSelectors;
	}
 
开发者ID:dmazinanian,项目名称:css-analyser,代码行数:36,代码来源:LessMixinCall.java


示例11: getContent

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
@Override
public String getContent() throws LessSource.FileNotFound, LessSource.CannotReadFile {
    return getAndCacheContent();
}
 
开发者ID:hpe-idol,项目名称:find,代码行数:5,代码来源:LessResource.java


示例12: getBytes

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
@Override
public byte[] getBytes() throws LessSource.FileNotFound, LessSource.CannotReadFile {
    return getAndCacheContent().getBytes();
}
 
开发者ID:hpe-idol,项目名称:find,代码行数:5,代码来源:LessResource.java


示例13: relativeSource

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
@Override
public LessSource relativeSource(final String filename) throws StringSourceException {
  return source(spath(filename));
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:5,代码来源:LessStrSource.java


示例14: compileLESSStyleSheet

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
/**
 * Compiles a given less style sheet to a {@link StyleSheet} object
 * @param lessStyleSheetToCompile
 * @param forceReadingFromAST Force the method to read from the AST.
 * otherwise, the method will first try to read from the source
 * (using {@link com.github.sommeri.less4j.core.ast.StyleSheet#getSource()}
 * of the style sheet being compiled.
 * @return Pure CSS represented in our model
 * @throws Less4jException
 */
public static StyleSheet compileLESSStyleSheet(com.github.sommeri.less4j.core.ast.StyleSheet lessStyleSheetToCompile, boolean forceReadingFromAST) throws Exception {
	try {

		String filePath = "";
		
		if (!forceReadingFromAST) {
			LessSource source = lessStyleSheetToCompile.getSource();
			if (source instanceof FileSource) {
				FileSource fileSource = (FileSource) source;
				if (fileSource.getURI() != null) {
					filePath = fileSource.getURI().toString();
				} else {
					if (source instanceof ModifiedLessFileSource) {
						ModifiedLessFileSource modifiedLessFileSource = (ModifiedLessFileSource) source;
						filePath = modifiedLessFileSource.getInputFile().getAbsolutePath();
					}
				}
			} else if (source instanceof URLSource) {
				URLSource urlSource = (URLSource) source;
				filePath = urlSource.getURI().toString();
			}
		}
		
		if ("".equals(filePath) || forceReadingFromAST) {
			File tempFile = File.createTempFile("lessToCompile", "less");
			LessPrinter lessPrinter = new LessPrinter();	
			String lessCSSFileAsString = lessPrinter.getString(lessStyleSheetToCompile);
			IOHelper.writeStringToFile(lessCSSFileAsString, tempFile.getAbsolutePath());
			filePath = tempFile.getAbsolutePath();
		}

		StyleSheet resultingStyleSheet = //compileStyleSheetUsingLess4J(filePath);
				compileStyleSheetOnWindowsUsingLessJS(filePath);

		resultingStyleSheet.setPath(filePath + ".css");

		return resultingStyleSheet;
		
	} catch (Exception e) {
		System.err.println(e);
	}

	return null;
}
 
开发者ID:dmazinanian,项目名称:css-analyser,代码行数:55,代码来源:LessHelper.java


示例15: getLessNodeFromLessString

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
public static ASTCssNode getLessNodeFromLessString(String nodeString) throws ParseException {
	String fakeSelectorString = ".fake { " + nodeString + "}" ;
	com.github.sommeri.less4j.core.ast.StyleSheet root = LessCSSParser.getLessStyleSheet(new LessSource.StringSource(fakeSelectorString));
	ASTCssNode resultingNode = root.getChilds().get(0).getChilds().get(1).getChilds().get(1); // :)
	return resultingNode;
}
 
开发者ID:dmazinanian,项目名称:css-analyser,代码行数:7,代码来源:LessHelper.java


示例16: replaceImports

import com.github.sommeri.less4j.LessSource; //导入依赖的package包/类
static String replaceImports(File lessFile, boolean onlyImportLessFiles) throws IOException {
	try {
		StyleSheet lessStyleSheet = LessCSSParser.getLessStyleSheet(new ModifiedLessFileSource(lessFile));
		List<Import> allImports = getAllImports(lessStyleSheet);
		String toReturn = IOHelper.readFileToString(lessFile.getAbsolutePath());
		for(Import importNode : allImports) {
			try {

				String url = getURLFromImportStatement(importNode);	

				if (!"".equals(url)) {
					if (!onlyImportLessFiles && url.endsWith(".css"))
						continue;
					if (url.contains("@{")) {
						LOGGER.warn("In {} (line {}) URL expression has to be evaluated because it needs string interpolation",
										lessFile.getAbsolutePath(),
										importNode.getSourceLine());
					} else {
						// Inline!
						File importedFile = new File(url);
						if (!importedFile.isAbsolute()) {
							importedFile = new File(url);
							url = lessFile.getParentFile().getAbsolutePath() + File.separator + url;
						}
						
						if (!importedFile.exists()) {
							if (url.toLowerCase().lastIndexOf(".less") != url.length() - 5) {
								importedFile = new File(url + ".less");
							}
							if (!onlyImportLessFiles && !importedFile.exists()) {
								if (url.toLowerCase().lastIndexOf(".css") != url.length() - 4) {
									importedFile = new File(url + ".css");
								}
							}
						}

						if (importedFile.exists()) {
							String importedFileText = replaceImports(importedFile, onlyImportLessFiles);
							try {
								StyleSheet replacedImportsImportedStyleSheet = LessCSSParser.getLessStyleSheet(new LessSource.StringSource(importedFileText));
								lessStyleSheet.addMemberAfter(replacedImportsImportedStyleSheet, importNode);
							} catch (RuntimeException rte) {
								LOGGER.warn(lessFile.getAbsolutePath());
								rte.printStackTrace();
							}
							lessStyleSheet.removeMember(importNode);
							toReturn = (new LessPrinter()).getString(lessStyleSheet);
						} else {
							LOGGER.warn("In {} (line {}), imported file {} does not exist",
											lessFile.getAbsolutePath(),
											importNode.getSourceLine(),
											url);
						}
					}
				}

			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
		return toReturn;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return "";
}
 
开发者ID:dmazinanian,项目名称:css-analyser,代码行数:67,代码来源:ImportInliner.java



注:本文中的com.github.sommeri.less4j.LessSource类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OrderInvestigationListVoAssembler类代码示例发布时间:2022-05-15
下一篇:
Java OperationResponse类代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap