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

Java Compiler类代码示例

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

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



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

示例1: compressJs

import io.bit3.jsass.Compiler; //导入依赖的package包/类
private void compressJs(String sourceName, InputStream in, OutputStream out) throws IOException
{
    CompilerOptions options = new CompilerOptions();
    CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);

    SourceFile input = SourceFile.fromInputStream(sourceName, in, Charset.forName("UTF-8"));

    com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
    compiler.compile(Collections.EMPTY_LIST, Collections.singletonList(input), options);

    if (compiler.hasErrors())
    {
        throw new EvaluatorException(compiler.getErrors()[0].description);
    }

    String compressed = compiler.toSource();
    IOUtils.copy(new StringReader(compressed), out);
}
 
开发者ID:touwolf,项目名称:kasije,代码行数:19,代码来源:ResourcesManagerImpl.java


示例2: cssFromSass

import io.bit3.jsass.Compiler; //导入依赖的package包/类
private File cssFromSass(File source) throws IOException
{
    String sourceName = source.getName();

    int lastDotIndex = sourceName.lastIndexOf(SASS_SUFFIX);
    String cssName = sourceName.substring(0, lastDotIndex) + CSS_SUFFIX;
    File cssFile = new File(source.getParentFile(), cssName);

    //ONLY FROM CACHE IF WAS MODIFIED AFTER SASS FILE
    if (cssFile.exists() && source.lastModified() <= cssFile.lastModified())
    {
        List<String> lines = IOUtils.readLines(new FileInputStream(cssFile));
        if (lines != null && !lines.isEmpty())
        {
            return cssFile;
        }
    }

    if (!cssFile.exists() && !cssFile.createNewFile())
    {
        LOG.log(Level.SEVERE, "Could not create: {0} to compile sass", cssFile.getAbsolutePath());
        return null;
    }

    Compiler compiler = new Compiler();
    Options options = new Options();//TODO: options
    try
    {
        Output output = compiler.compileFile(source.toURI(), cssFile.toURI(), options);
        IOUtils.copy(new StringReader(output.getCss()), new FileOutputStream(cssFile));

        return cssFile;
    }
    catch (CompilationException ex)
    {
        LOG.log(Level.SEVERE, "Error compiling SASS: {0}", ex.getMessage());
        return null;
    }
}
 
开发者ID:touwolf,项目名称:kasije,代码行数:40,代码来源:ResourcesManagerImpl.java


示例3: compiler

import io.bit3.jsass.Compiler; //导入依赖的package包/类
@Override public void compiler(String rurl, Writer output, @Nonnull ParameterInfoImpl params, @Nonnull IResourceDependencyList rdl) throws Exception {
	/*
	 * Define resolvers: these resolve "filenames" in the scss to resources in the webapp.
	 */
	String basePath;
	int pos = rurl.lastIndexOf('/');
	if(pos == -1) {
		basePath = "";
	} else {
		basePath = rurl.substring(pos + 1);
	}

	JSassResolver jsr = new JSassResolver(params, basePath, rdl);

	Import file = jsr.resolve(rurl, "");
	if(null == file)
		throw new ThingyNotFoundException("The sass/scss file " + rurl + " could not be found");

	File out = File.createTempFile("sass-out-", ".css");
	System.out.println("out " + out);

	Options opt = new Options();
	opt.setImporters(Collections.singletonList(jsr));
	opt.setOutputStyle(OutputStyle.EXPANDED);
	opt.setIndent("\t");
	opt.setLinefeed("\n");
	opt.setSourceMapEmbed(true);
	opt.setSourceComments(false);

	boolean isSass = rurl.toLowerCase().endsWith(".sass");
	opt.setIsIndentedSyntaxSrc(isSass);

	StringContext fc = new StringContext(file.getContents(), file.getImportUri(), out.toURI(), opt);
	Compiler co = new Compiler();
	Output res = co.compile(fc);
	String css = res.getCss();
	output.write(css);
	out.delete();
	jsr.close();
}
 
开发者ID:fjalvingh,项目名称:domui,代码行数:41,代码来源:JSassCompiler.java


示例4: sassify

import io.bit3.jsass.Compiler; //导入依赖的package包/类
private static void sassify(File sassFile) {
    final File outputFile = getOutputFile(sassFile, Suffix.CSS);

    final URI inputURI = sassFile.toURI();
    final URI outputURI = outputFile.toURI();

    final Compiler compiler = new Compiler();
    try {
      final Output output = compiler.compileFile(inputURI, outputURI, new Options());
      FileUtils.writeStringToFile(outputFile, output.getCss(), Default.ENCODING.toString());
      logPreprocess(sassFile, outputFile);
    } catch (CompilationException | IOException e) {
        LOG.error("Failed to preprocess SASS file", e);
    }
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:16,代码来源:MinificationUtils.java


示例5: getCompiledStylesheet

import io.bit3.jsass.Compiler; //导入依赖的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 = "scssService.compiledStylesheets", 
		key = "T(fr.openwide.core.wicket.more.css.scss.service.ScssServiceImpl).getCacheKey(#scope, #path)",
		beforeInvocation = true,
		condition= "#checkCacheEntryUpToDate && !(caches.?[name=='scssService.compiledStylesheets'][0]?.get(T(fr.openwide.core.wicket.more.css.scss.service.ScssServiceImpl).getCacheKey(#scope, #path))?.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 = "scssService.compiledStylesheets",
		key = "T(fr.openwide.core.wicket.more.css.scss.service.ScssServiceImpl).getCacheKey(#scope, #path)")
public ScssStylesheetInformation getCompiledStylesheet(Class<?> scope, String path, boolean checkCacheEntryUpToDate)
		throws ServiceException {
	String scssPath = getFullPath(scope, path);
	
	try {
		JSassScopeAwareImporter importer = new JSassScopeAwareImporter(SCOPES);
		importer.addSourceUri(scssPath);
		
		Compiler compiler = new Compiler();
		Options options = new Options();
		options.setOutputStyle(OutputStyle.EXPANDED);
		options.setIndent("\t");
		options.getImporters().add(importer);
		
		ClassPathResource scssCpr = new ClassPathResource(scssPath);
		
		Context fileContext = new StringContext(IOUtils.toString(scssCpr.getInputStream()), new URI("classpath", "/" + scssPath, null), null, options);
		Output output = compiler.compile(fileContext);
		// Write result
		ScssStylesheetInformation compiledStylesheet = new ScssStylesheetInformation(scssPath, output.getCss());
		
		for (String sourceUri : importer.getSourceUris()) {
			ClassPathResource cpr = new ClassPathResource(sourceUri);
			compiledStylesheet.addImportedStylesheet(new ScssStylesheetInformation(sourceUri, cpr.lastModified()));
		}
		
		return compiledStylesheet;
	} catch (RuntimeException | IOException | URISyntaxException | CompilationException e) {
		throw new ServiceException(String.format("Error compiling %1$s", scssPath), e);
	}
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:42,代码来源:ScssServiceImpl.java


示例6: process

import io.bit3.jsass.Compiler; //导入依赖的package包/类
@Override
public String process(final String filename, final String source, final Config conf, final ClassLoader loader)
    throws Exception {
  String syntax = get("syntax");
  String importer = get("importer").toString().toUpperCase();
  Function<String, URI> resolver;
  if("FILE".equals(importer)) {
    resolver = FS;
  } else {
    resolver = CP.apply(loader);
  }
  OutputStyle style = OutputStyle.valueOf(get("style").toString().toUpperCase());

  Options options = new Options();
  options.setIsIndentedSyntaxSrc("sass".equals(syntax));
  options.getImporters().add(new SassImporter(syntax, resolver));
  options.setOutputStyle(style);
  options.setIndent(get("indent"));
  options.setLinefeed(get("linefeed"));
  options.setOmitSourceMapUrl(get("omitSourceMapUrl"));
  options.setPrecision(get("precision"));
  options.setSourceComments(get("sourceComments"));

  String sourcemap = get("sourcemap");
  if ("inline".equals(sourcemap)) {
    options.setSourceMapEmbed(true);
  } else if ("file".equals(sourcemap)) {
    options.setSourceMapFile(URI.create(filename + ".map"));
  }
  try {
    URI input = URI.create(filename);
    StringContext ctx = new StringContext(source, input, null, options);
    Output output = new Compiler().compile(ctx);
    return filename.endsWith(".map") ? output.getSourceMap() : output.getCss();
  } catch (CompilationException x) {
    Matcher matcher = LOCATION.matcher(x.getErrorJson());
    Map<String, Integer> location = new HashMap<>();
    while (matcher.find()) {
      location.put(matcher.group(1), Integer.parseInt(matcher.group(2)));
    }
    int line = location.getOrDefault("line", -1);
    int column = location.getOrDefault("column", -1);
    throw new AssetException(name(),
        new AssetProblem(Optional.ofNullable(x.getErrorFile()).orElse(filename), line, column,
            x.getErrorText(), null));
  }
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:48,代码来源:Sass.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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