Ejemplo n.º 1
0
        /// <summary>
        /// Transforms the content of the given string.
        /// </summary>
        /// <param name="input">The input string to transform.</param>
        /// <param name="path">The path to the given input string to transform.</param>
        /// <param name="cruncher">The cruncher that is running the transform.</param>
        /// <returns>The transformed string.</returns>
        public string Transform(string input, string path, CruncherBase cruncher)
        {
            try
            {
                var options = new LibSass.Compiler.Options.SassOptions
                {
                    InputPath        = path,
                    OutputStyle      = LibSass.Compiler.Options.SassOutputStyle.Expanded,
                    Precision        = 5,
                    IsIndentedSyntax = System.IO.Path.GetExtension(path).Equals(".sass", StringComparison.OrdinalIgnoreCase)
                };
                var compiler = new LibSass.Compiler.SassCompiler(options);
                var result   = compiler.Compile();

                foreach (var file in result.IncludedFiles)
                {
                    cruncher.AddFileMonitor(file, "not empty");
                }

                return(result.Output);
            }
            catch (Exception ex)
            {
                throw new SassAndScssCompilingException(ex.Message, ex.InnerException);
            }
        }
        /// <summary>
        /// Transforms the content of the given string.
        /// </summary>
        /// <param name="input">The input string to transform.</param>
        /// <param name="path">The path to the given input string to transform.</param>
        /// <param name="cruncher">The cruncher that is running the transform.</param>
        /// <returns>The transformed string.</returns>
        public string Transform(string input, string path, CruncherBase cruncher)
        {
            using (CoffeeScriptCompiler coffeeScriptCompiler = new CoffeeScriptCompiler(CruncherConfiguration.Instance.JsEngineFunc))
            {
                input = coffeeScriptCompiler.Compile(input);
            }

            return input;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Transforms the content of the given string.
        /// </summary>
        /// <param name="input">The input string to transform.</param>
        /// <param name="path">The path to the given input string to transform.</param>
        /// <param name="cruncher">The cruncher that is running the transform.</param>
        /// <returns>The transformed string.</returns>
        public string Transform(string input, string path, CruncherBase cruncher)
        {
            using (CoffeeScriptCompiler coffeeScriptCompiler = new CoffeeScriptCompiler(CruncherConfiguration.Instance.JsEngineFunc))
            {
                input = coffeeScriptCompiler.Compile(input);
            }

            return(input);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Transforms the content of the given string by replacing relative paths.
 /// </summary>
 /// <param name="input">The input string to transform.</param>
 /// <param name="path">The path to the given input string to transform.</param>
 /// <param name="cruncher">The cruncher that is running the transform.</param>
 /// <returns>The transformed string.</returns>
 public string Transform(string input, string path, CruncherBase cruncher)
 {
     try
     {
         return(this.RewritePaths(input, path));
     }
     catch
     {
         return(input);
     }
 }
 /// <summary>
 /// Transforms the content of the given string by replacing relative paths. 
 /// </summary>
 /// <param name="input">The input string to transform.</param>
 /// <param name="path">The path to the given input string to transform.</param>
 /// <param name="cruncher">The cruncher that is running the transform.</param>
 /// <returns>The transformed string.</returns>
 public string Transform(string input, string path, CruncherBase cruncher)
 {
     try
     {
         return this.RewritePaths(input, path);
     }
     catch
     {
         return input;
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Transforms the content of the given string.
        /// </summary>
        /// <param name="input">The input string to transform.</param>
        /// <param name="path">The path to the given input string to transform.</param>
        /// <param name="cruncher">The cruncher that is running the transform.</param>
        /// <returns>The transformed string.</returns>
        public string Transform(string input, string path, CruncherBase cruncher)
        {
            // Unfortunately there's no way I know of pulling a list of imports out of
            // Sass so we have to do a manual loop to get the list of file dependencies.
            // This should only happen once though.
            if (cruncher.Options.CacheFiles)
            {
                this.AddImportsToFileMonitors(input, cruncher);
            }

            SassCompiler compiler = new SassCompiler();
            return compiler.CompileSass(input, path);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Transforms the content of the given string.
        /// </summary>
        /// <param name="input">The input string to transform.</param>
        /// <param name="path">The path to the given input string to transform.</param>
        /// <param name="cruncher">The cruncher that is running the transform.</param>
        /// <returns>The transformed string.</returns>
        public string Transform(string input, string path, CruncherBase cruncher)
        {
            // Unfortunately there's no way I know of pulling a list of imports out of
            // Sass so we have to do a manual loop to get the list of file dependencies.
            // This should only happen once though.
            if (cruncher.Options.CacheFiles)
            {
                this.AddImportsToFileMonitors(input, cruncher);
            }

            SassCompiler compiler = new SassCompiler();

            return(compiler.CompileSass(input, path));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Transforms the content of the given string from Less into CSS.
        /// </summary>
        /// <param name="input">The input string to transform.</param>
        /// <param name="path">The path to the given input string to transform.</param>
        /// <param name="cruncher">The cruncher that is running the transform.</param>
        /// <returns>The transformed string.</returns>
        public string Transform(string input, string path, CruncherBase cruncher)
        {
            // The standard engine returns a FileNotFoundExecption so I've rolled my own path resolver.
            Parser parser = new Parser();
            DotLessPathResolver dotLessPathResolver = new DotLessPathResolver(path);
            FileReader          fileReader          = new FileReader(dotLessPathResolver);

            parser.Importer = new Importer(fileReader);
            ILessEngine lessEngine = new LessEngine(parser);

            try
            {
                string result = lessEngine.TransformToCss(input, path);

                if (cruncher.Options.CacheFiles)
                {
                    // Add each import as a file dependency so that the cache will clean itself.
                    IEnumerable <string> imports    = lessEngine.GetImports();
                    IList <string>       enumerable = imports as IList <string> ?? imports.ToList();

                    if (enumerable.Any())
                    {
                        foreach (string import in enumerable)
                        {
                            if (!import.Contains("://"))
                            {
                                string filePath =
                                    HostingEnvironment.MapPath(
                                        VirtualPathUtility.Combine(dotLessPathResolver.CurrentFileDirectory, import));

                                cruncher.AddFileMonitor(filePath, "not empty");
                            }
                        }
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw new LessCompilingException(ex.Message, ex.InnerException);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Parses the string for CSS imports and replaces them with the referenced CSS.
        /// </summary>
        /// <param name="sass">
        /// The SASS to parse for import statements.
        /// </param>
        /// <param name="cruncher">The cruncher that is running the transform.</param>
        private void AddImportsToFileMonitors(string sass, CruncherBase cruncher)
        {
            // Check for imports and parse if necessary.
            if (!sass.Contains("@import", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            // Recursively parse the sass for imports.
            foreach (Match match in ImportsRegex.Matches(sass))
            {
                // Recursively parse the sass for imports.
                GroupCollection   groups       = match.Groups;
                CaptureCollection fileCaptures = groups["filename"].Captures;

                if (fileCaptures.Count > 0)
                {
                    string fileName = fileCaptures[0].ToString();

                    if (!fileName.Contains("://"))
                    {
                        // Check and add the @import the match.
                        FileInfo fileInfo =
                            new FileInfo(Path.GetFullPath(Path.Combine(cruncher.Options.RootFolder, fileName)));

                        // Read the file.
                        if (fileInfo.Exists)
                        {
                            string file = fileInfo.FullName;

                            using (StreamReader reader = new StreamReader(file))
                            {
                                // Recursively check the children.
                                this.AddImportsToFileMonitors(reader.ReadToEnd(), cruncher);
                            }

                            // Cache if applicable.
                            cruncher.AddFileMonitor(file, "not empty");
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Parses the string for CSS imports and replaces them with the referenced CSS.
        /// </summary>
        /// <param name="sass">
        /// The SASS to parse for import statements.
        /// </param>
        /// <param name="cruncher">The cruncher that is running the transform.</param>
        private void AddImportsToFileMonitors(string sass, CruncherBase cruncher)
        {
            // Check for imports and parse if necessary.
            if (!sass.Contains("@import", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            // Recursively parse the sass for imports.
            foreach (Match match in ImportsRegex.Matches(sass))
            {
                // Recursively parse the sass for imports.
                GroupCollection groups = match.Groups;
                CaptureCollection fileCaptures = groups["filename"].Captures;

                if (fileCaptures.Count > 0)
                {
                    string fileName = fileCaptures[0].ToString();

                    if (!fileName.Contains("://"))
                    {
                        // Check and add the @import the match.
                        FileInfo fileInfo =
                            new FileInfo(Path.GetFullPath(Path.Combine(cruncher.Options.RootFolder, fileName)));

                        // Read the file.
                        if (fileInfo.Exists)
                        {
                            string file = fileInfo.FullName;

                            using (StreamReader reader = new StreamReader(file))
                            {
                                // Recursively check the children.
                                this.AddImportsToFileMonitors(reader.ReadToEnd(), cruncher);
                            }

                            // Cache if applicable.
                            cruncher.AddFileMonitor(file, "not empty");
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Transforms the content of the given string from Less into CSS. 
        /// </summary>
        /// <param name="input">The input string to transform.</param>
        /// <param name="path">The path to the given input string to transform.</param>
        /// <param name="cruncher">The cruncher that is running the transform.</param>
        /// <returns>The transformed string.</returns>
        public string Transform(string input, string path, CruncherBase cruncher)
        {
            // The standard engine returns a FileNotFoundExecption so I've rolled my own path resolver.
            Parser parser = new Parser();
            DotLessPathResolver dotLessPathResolver = new DotLessPathResolver(path);
            FileReader fileReader = new FileReader(dotLessPathResolver);
            parser.Importer = new Importer(fileReader);
            ILessEngine lessEngine = new LessEngine(parser);

            try
            {
                string result = lessEngine.TransformToCss(input, path);

                if (cruncher.Options.CacheFiles)
                {
                    // Add each import as a file dependency so that the cache will clean itself.
                    IEnumerable<string> imports = lessEngine.GetImports();
                    IList<string> enumerable = imports as IList<string> ?? imports.ToList();

                    if (enumerable.Any())
                    {
                        foreach (string import in enumerable)
                        {
                            if (!import.Contains(Uri.SchemeDelimiter))
                            {
                                string filePath =
                                    HostingEnvironment.MapPath(VirtualPathUtility.Combine(dotLessPathResolver.CurrentFileDirectory, import));

                                cruncher.AddFileMonitor(filePath, "not empty");
                            }
                        }
                    }
                }

                return result;
            }
            catch (Exception ex)
            {
                throw new LessCompilingException(ex.Message, ex.InnerException);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Transforms the content of the given string.
        /// </summary>
        /// <param name="input">The input string to transform.</param>
        /// <param name="path">The path to the given input string to transform.</param>
        /// <param name="cruncher">The cruncher that is running the transform.</param>
        /// <returns>The transformed string.</returns>
        public string Transform(string input, string path, CruncherBase cruncher)
        {
            CoffeeScriptCompiler coffeeScriptCompiler = new CoffeeScriptCompiler();

            return(coffeeScriptCompiler.Compile(input));
        }