Beispiel #1
0
 @Override
 @RequestMapping(method = RequestMethod.GET)
 public File compileSass(
     @RequestParam(value = "variables", required = false) String variables,
     @RequestParam(value = "entrypoints", required = false) String entrypoints,
     @RequestParam(value = "output", required = false) String output)
     throws Exception {
   SCSSProcessorBase processor = null;
   File inputFile = writeInputStreamToFile(getClass().getResourceAsStream("/default-theme.zip"));
   try {
     Map<String, String> mapping = convertFields(variables);
     Map<String, String> entryPoints = convertFields(entrypoints);
     processor = new SCSSProcessorJsass(inputFile.getAbsolutePath(), mapping, entryPoints);
     processor.compileAll();
     if (response != null) {
       OutputStream outputStream = response.getOutputStream();
       if ("css".equals(output)) {
         serveCss(processor, outputStream, "theme.css");
       } else {
         serveZip(processor, outputStream, "theme.zip");
       }
       IOUtils.closeQuietly(outputStream);
       response.flushBuffer();
     }
   } finally {
     if (processor != null) processor.cleanup();
     if (inputFile.exists()) inputFile.delete();
   }
   return null;
 }
Beispiel #2
0
 private void serveZip(SCSSProcessorBase processor, OutputStream out, String outputFilename)
     throws ZipException, IOException {
   File exported = processor.exportZip();
   response.setContentType("application/zip");
   response.setHeader(
       "Content-Disposition", String.format("attachment; filename=compiled-%s", outputFilename));
   out.write(FileUtils.readFileToByteArray(exported));
 }