当前位置: 首页>>代码示例>>Java>>正文


Java ThreadUnsafeLessCompiler类代码示例

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


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

示例1: sendResource

import com.github.sommeri.less4j.core.ThreadUnsafeLessCompiler; //导入依赖的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

示例2: process

import com.github.sommeri.less4j.core.ThreadUnsafeLessCompiler; //导入依赖的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

示例3: getCompiledStylesheet

import com.github.sommeri.less4j.core.ThreadUnsafeLessCompiler; //导入依赖的package包/类
@Override
// If checkCacheInvalidation is true and, before invocation, a cached value exists and is not up to date, we evict the cache entry. 
@CacheEvict(value = "lessCssService.compiledStylesheets", 
		key = "T(fr.openwide.core.wicket.more.css.lesscss.service.LessCssServiceImpl).getCacheKey(#lessInformation)",
		beforeInvocation = true,
		condition= "#checkCacheEntryUpToDate && !(caches.?[name=='lessCssService.compiledStylesheets'][0]?.get(T(fr.openwide.core.wicket.more.css.lesscss.service.LessCssServiceImpl).getCacheKey(#lessInformation))?.get()?.isUpToDate() ?: false)"
		)
// THEN, we check if a cached value exists. If it does, it is returned ; if not, the method is called. 
@Cacheable(value = "lessCssService.compiledStylesheets",
		key = "T(fr.openwide.core.wicket.more.css.lesscss.service.LessCssServiceImpl).getCacheKey(#lessInformation)")
public LessCssStylesheetInformation getCompiledStylesheet(LessCssStylesheetInformation lessInformation, boolean checkCacheEntryUpToDate)
		throws ServiceException {
	prepareRawStylesheet(lessInformation);
	try {
		Configuration configuration = new Configuration();
		if (propertyService != null && propertyService.isConfigurationTypeDevelopment()) {
			// on insère inline une source map
			// -> utile seulement si on a les outils adéquats pour l'exploiter
			configuration.getSourceMapConfiguration().setInline(true);
		} else {
			// on n'insère aucune information sur l'emplacement des fichiers
			configuration.getSourceMapConfiguration().setLinkSourceMap(false);
		}
		CompilationResult compilationResult = new ThreadUnsafeLessCompiler().compile(lessInformation.getSource(), configuration);
		
		LessCssStylesheetInformation compiledStylesheet = new LessCssStylesheetInformation(
				lessInformation, compilationResult.getCss()
		);
		
		List<Problem> warnings = compilationResult.getWarnings();
		if (!CollectionUtils.isEmpty(warnings)) {
			for (Problem warning : warnings) {
				LOGGER.warn(formatLess4jProblem(warning));
			}
		}
		
		return compiledStylesheet;
	} catch (Less4jException e) {
		List<Problem> errors = e.getErrors();
		if (!CollectionUtils.isEmpty(errors)) {
			for (Problem error : errors) {
				LOGGER.error(formatLess4jProblem(error));
			}
		}
		
		throw new ServiceException(String.format("Error compiling %1$s (scope: %2$s)",
				lessInformation.getName(), lessInformation.getScope()), e);
	}
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:50,代码来源:LessCssServiceImpl.java


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