Example #1
0
        /// <summary>
        /// Attempts to compile a less file into css.
        /// </summary>
        /// <param name="engine">The dotless engine.</param>
        /// <param name="inputFilePath">The input less file.</param>
        /// <param name="outputFilePath">The output css file.</param>
        /// <returns>The return code. 0 is success; otherwise, value is failure.</returns>
        private int CompileImpl(ILessEngine engine, string inputFilePath, string outputFilePath)
        {
            engine = new FixImportPathDecorator(engine);
            var currentDir = Directory.GetCurrentDirectory();

            try
            {
                Log.LogMessage("Compiling less from \"{0}\" to \"{1}\".", inputFilePath, outputFilePath);
                var directoryPath = Path.GetDirectoryName(inputFilePath);
                var fileReader    = new dotless.Core.Input.FileReader();
                var source        = fileReader.GetFileContents(inputFilePath);
                Directory.SetCurrentDirectory(directoryPath);
                var css = engine.TransformToCss(source, inputFilePath);

                File.WriteAllText(outputFilePath, css);

                if (!engine.LastTransformationSuccessful)
                {
                    Log.LogError("Failed: Compiling less from \"{0}\" to \"{1}\".", inputFilePath, outputFilePath);
                    return(-5);
                }
                else
                {
                    Log.LogMessage("Success: Compiled less from \"{0}\" to \"{1}\".", inputFilePath, outputFilePath);
                }

                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(0);
            }
            catch (Exception ex)
            {
                Log.LogError("Failed: Compiling less from \"{0}\" to \"{1}\".", inputFilePath, outputFilePath);
                Log.LogError("Compilation failed: {0}", ex.ToString());
                return(-3);
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDir);
            }
        }
Example #2
0
        /// <summary>
        /// Attempts to compile a less file into css.
        /// </summary>
        /// <param name="engine">The dotless engine.</param>
        /// <param name="inputFilePath">The input less file.</param>
        /// <param name="outputFilePath">The output css file.</param>
        /// <returns>The return code. 0 is success; otherwise, value is failure.</returns>
        private int CompileImpl(ILessEngine engine, string inputFilePath, string outputFilePath)
        {
            engine = new FixImportPathDecorator(engine);
            var currentDir = Directory.GetCurrentDirectory();
            try
            {
                Log.LogMessage("Compiling less from \"{0}\" to \"{1}\".", inputFilePath, outputFilePath);
                var directoryPath = Path.GetDirectoryName(inputFilePath);
                var fileReader = new dotless.Core.Input.FileReader();
                var source = fileReader.GetFileContents(inputFilePath);
                Directory.SetCurrentDirectory(directoryPath);
                var css = engine.TransformToCss(source, inputFilePath);

                File.WriteAllText(outputFilePath, css);

                if (!engine.LastTransformationSuccessful)
                {
                    Log.LogError("Failed: Compiling less from \"{0}\" to \"{1}\".", inputFilePath, outputFilePath);
                    return -5;
                }
                else
                {
                    Log.LogMessage("Success: Compiled less from \"{0}\" to \"{1}\".", inputFilePath, outputFilePath);
                }

                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 0;
            }
            catch (Exception ex)
            {
                Log.LogError("Failed: Compiling less from \"{0}\" to \"{1}\".", inputFilePath, outputFilePath);
                Log.LogError("Compilation failed: {0}", ex.ToString());
                return -3;
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDir);
            }
        }