You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SassCompiler.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2000-2013 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.sass;
  17. import java.io.File;
  18. import java.io.FileNotFoundException;
  19. import java.io.FileWriter;
  20. import java.io.IOException;
  21. import com.vaadin.sass.internal.ScssStylesheet;
  22. public class SassCompiler {
  23. public static void main(String[] args) throws Exception {
  24. String input = null;
  25. String output = null;
  26. if (args.length < 1 || args.length > 2) {
  27. System.out
  28. .println("usage: SassCompile <scss file to compile> <css file to write>");
  29. return;
  30. }
  31. File in = new File(args[0]);
  32. if (!in.canRead()) {
  33. System.err.println(in.getCanonicalPath() + " could not be read!");
  34. return;
  35. }
  36. input = in.getCanonicalPath();
  37. if (args.length == 2) {
  38. output = args[1];
  39. }
  40. // You can set the resolver; if none is set, VaadinResolver will be used
  41. // ScssStylesheet.setStylesheetResolvers(new VaadinResolver());
  42. ScssStylesheet scss = ScssStylesheet.get(input);
  43. if(scss == null){
  44. System.err.println("The scss file " + input
  45. + " could not be found.");
  46. return;
  47. }
  48. scss.compile();
  49. if (output == null) {
  50. System.out.println(scss.toString());
  51. } else {
  52. writeFile(output, scss.toString());
  53. }
  54. }
  55. public static void writeFile(String filename, String output)
  56. throws IOException {
  57. File file = new File(filename);
  58. FileWriter writer = new FileWriter(file);
  59. writer.write(output);
  60. writer.close();
  61. }
  62. }