Exemplo n.º 1
0
        private static IEnumerable <string> CompileImpl(ILessEngine engine, string inputFilePath, string outputFilePath)
        {
            var currentDir = Directory.GetCurrentDirectory();

            try
            {
                Console.WriteLine("{0} -> {1}", inputFilePath, outputFilePath);
                var directoryPath = Path.GetDirectoryName(inputFilePath);
                var source        = new dotless.Core.Input.FileReader().GetFileContents(inputFilePath);
                Directory.SetCurrentDirectory(directoryPath);
                var css = engine.TransformToCss(source, inputFilePath);
                File.WriteAllText(outputFilePath, css);
                Console.WriteLine("[Done]");

                var files = new List <string>();
                files.Add(inputFilePath);
                foreach (var file in engine.GetImports())
                {
                    files.Add(Path.Combine(directoryPath, Path.ChangeExtension(file, "less")));
                }
                engine.ResetImports();
                return(files);
            }
            catch (IOException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Console.WriteLine("[FAILED]");
                Console.WriteLine("Compilation failed: {0}", ex.Message);
                Console.WriteLine(ex.StackTrace);
                return(null);
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDir);
            }
        }
Exemplo n.º 2
0
 public void ResetImports()
 {
     Underlying.ResetImports();
 }
Exemplo n.º 3
0
        private static IEnumerable<string> CompileImpl(ILessEngine engine, string inputFilePath, string outputFilePath, StringBuilder sb, bool silent)
        {
            try
            {
                if (!silent)
                {
                    sb.AppendFormat("{0} -> {1}\n", inputFilePath, outputFilePath);
                }

                var directoryPath = Path.GetDirectoryName(inputFilePath);
                var source = new dotless.Core.Input.FileReader(directoryPath).GetFileContents(inputFilePath);
                var css = engine.TransformToCss(source, inputFilePath);
                File.WriteAllText(outputFilePath, css);

                if (!silent)
                {
                    sb.AppendLine("[Done]");
                }

                var files = new List<string>();
                files.Add(inputFilePath);
                foreach (var file in engine.GetImports())
                {
                    files.Add(Path.Combine(directoryPath, Path.ChangeExtension(file, "less")));
                }
                engine.ResetImports();
                return files;
            }
            catch (IOException)
            {
                throw;
            }
            catch (Exception ex)
            {
                if (silent)
                {
                    // Need to know the file now
                    sb.AppendFormat("{0} -> {1}\n", inputFilePath, outputFilePath);
                }

                sb.AppendLine("[FAILED]");
                sb.AppendFormat("Compilation failed: {0}\n", ex.Message);
                sb.AppendLine(ex.StackTrace);
                return null;
            }
        }
Exemplo n.º 4
0
        private static IEnumerable<string> CompileImpl(ILessEngine engine, string inputFilePath, string outputFilePath)
        {
            var currentDir = Directory.GetCurrentDirectory();
            try
            {
                Console.WriteLine("{0} -> {1}", inputFilePath, outputFilePath);
                var directoryPath = Path.GetDirectoryName(inputFilePath);
                var source = new dotless.Core.Input.FileReader().GetFileContents(inputFilePath);
                Directory.SetCurrentDirectory(directoryPath);
                var css = engine.TransformToCss(source, inputFilePath);
                File.WriteAllText(outputFilePath, css);
                Console.WriteLine("[Done]");

                var files = new List<string>();
                files.Add(inputFilePath);
                foreach (var file in engine.GetImports())
                    files.Add(Path.Combine(directoryPath, Path.ChangeExtension(file, "less")));
                engine.ResetImports();
                return files;
            }
            catch (IOException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Console.WriteLine("[FAILED]");
                Console.WriteLine("Compilation failed: {0}", ex.Message);
                Console.WriteLine(ex.StackTrace);
                return null;
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDir);
            }
        }