示例#1
0
        /// <summary>
        ///  Imports a less file and puts the root into the import node
        /// </summary>
        protected bool ImportLessFile(string lessPath, Import import)
        {
            string contents, file = null;

            if (IsEmbeddedResource(lessPath))
            {
                contents = ResourceLoader.GetResource(lessPath, FileReader, out file);
                if (contents == null)
                {
                    return(false);
                }
            }
            else
            {
                string fullName = lessPath;
                if (!string.IsNullOrEmpty(CurrentDirectory))
                {
                    fullName = CurrentDirectory.Replace(@"\", "/").TrimEnd('/') + '/' + lessPath;
                }

                bool fileExists = FileReader.DoesFileExist(fullName);
                if (!fileExists && !fullName.EndsWith(".less"))
                {
                    fullName  += ".less";
                    fileExists = FileReader.DoesFileExist(fullName);
                }

                if (!fileExists)
                {
                    return(false);
                }

                contents = FileReader.GetFileContents(fullName);

                file = fullName;
            }

            _paths.Add(Path.GetDirectoryName(import.Path));

            try
            {
                if (!string.IsNullOrEmpty(file))
                {
                    Imports.Add(file);
                }
                import.InnerRoot = Parser().Parse(contents, lessPath);
            }
            catch
            {
                Imports.Remove(file);
                throw;
            }
            finally
            {
                _paths.RemoveAt(_paths.Count - 1);
            }

            return(true);
        }
示例#2
0
        /// <summary>
        ///  Imports a css file from an embedded resource and puts the contents into the import node
        /// </summary>
        /// <param name="file"></param>
        /// <param name="import"></param>
        /// <returns></returns>
        private bool ImportEmbeddedCssContents(string file, Import import)
        {
            string content = ResourceLoader.GetResource(file, FileReader, out file);

            if (content == null)
            {
                return(false);
            }
            import.InnerContent = content;
            return(true);
        }
示例#3
0
        /// <summary>
        ///  Imports a less file and puts the root into the import node
        /// </summary>
        protected bool ImportLessFile(string currentPath, string lessPath, Import import)
        {
            string contents, file = null;

            if (IsEmbeddedResource(lessPath))
            {
                contents = ResourceLoader.GetResource(currentPath, lessPath, FileReader, out file);
                if (contents == null)
                {
                    return(false);
                }
            }
            else
            {
                string fileName;
                bool   fileExists = FileReader.DoesFileExist(currentPath, lessPath, out fileName);
                if (!fileExists && !lessPath.EndsWith(".less"))
                {
                    lessPath  += ".less";
                    fileExists = FileReader.DoesFileExist(currentPath, lessPath, out fileName);
                }

                if (!fileExists)
                {
                    return(false);
                }

                contents = FileReader.GetFileContents(null, fileName);

                file = lessPath;
            }

            _paths.Add(Path.GetDirectoryName(import.Path));

            try
            {
                if (!string.IsNullOrEmpty(file))
                {
                    Imports.Add(file);
                }
                import.InnerRoot = Parser().Parse(contents, lessPath, currentPath);
            }
            catch
            {
                Imports.Remove(file);
                throw;
            }
            finally
            {
                _paths.RemoveAt(_paths.Count - 1);
            }

            return(true);
        }