示例#1
0
        public static string ResolvePath(StringValue item, ITextProvider text, DirectoryInfo currentDirectory)
        {
            var relativePath = text.GetText(item.Start, item.Length).Trim('\'', '"');
            var segments = relativePath.Split('/');
            if (segments.Length == 0)
                return null;

            var path = currentDirectory.FullName;
            for (int i = 0; i < (segments.Length - 1); i++)
                path = Path.Combine(path, segments[i]);

            var directory = new DirectoryInfo(Path.GetFullPath(path));
            if (!directory.Exists)
                return null;

            var filename = segments[segments.Length - 1];
            if (string.IsNullOrEmpty(Path.GetExtension(filename)))
                filename += ".scss";

            var files = directory.GetFiles("*" + filename);

            var comparer = StringComparer.OrdinalIgnoreCase;
            return files.Where(x => comparer.Equals(x.Name, filename) || comparer.Equals(x.Name, "_" + filename))
                .Select(x => x.FullName)
                .FirstOrDefault();
        }
示例#2
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (IsUrl(text, stream.Current))
            {
                Function = Children.AddCurrentAndAdvance(stream, SassClassifierType.SystemFunction);

                if (stream.Current.Type == TokenType.OpenFunctionBrace)
                    OpenBrace = Children.AddCurrentAndAdvance(stream, SassClassifierType.FunctionBrace);

                if ((stream.Current.Type == TokenType.String || stream.Current.Type == TokenType.BadString))
                {
                    Url = itemFactory.CreateSpecificParsed<StringValue>(this, text, stream);
                    if (Url != null)
                        Children.Add(Url);
                }
                else
                {
                    // not using string, so just consume everything until close of url()
                    while (!IsUrlTerminator(stream.Current.Type))
                    {
                        Children.AddCurrentAndAdvance(stream, SassClassifierType.String);
                    }
                }

                if (stream.Current.Type == TokenType.CloseFunctionBrace)
                    CloseBrace = Children.AddCurrentAndAdvance(stream, SassClassifierType.FunctionBrace);
            }

            return Children.Count > 0;
        }
示例#3
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.Identifier)
            {
                Name = Children.AddCurrentAndAdvance(stream, SassClassifierType.XmlDocumentationTag);

                if (stream.Current.Type == TokenType.Equal)
                    EqualSign = Children.AddCurrentAndAdvance(stream);

                if (stream.Current.Type == TokenType.String || stream.Current.Type == TokenType.BadString)
                    Value = itemFactory.CreateSpecificParsed<StringValue>(this, text, stream);
            }

            return Children.Count > 0;
        }
示例#4
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            if (stream.Current.Type == TokenType.String || stream.Current.Type == TokenType.BadString)
            {
                Filename = itemFactory.CreateSpecificParsed<StringValue>(this, text, stream);
                if (Filename != null)
                    Children.Add(Filename);

                if (stream.Current.Type == TokenType.NewLine)
                    Children.AddCurrentAndAdvance(stream);

                if (stream.Current.Type == TokenType.Comma)
                    Comma = Children.AddCurrentAndAdvance(stream, SassClassifierType.Punctuation);
            }

            return Children.Count > 0;
        }