Ejemplo n.º 1
0
 public static IList <AttributeToCss> FindEquivalent(IDomObject domobject, StyleClass styles)
 {
     return((from attributeRuleMatch in _linkedAttributes
             where domobject.HasAttribute(attributeRuleMatch.Key) && styles.Attributes.ContainsKey(attributeRuleMatch.Value)
             select new AttributeToCss
     {
         AttributeName = attributeRuleMatch.Key, CssValue = styles.Attributes[attributeRuleMatch.Value].Value
     }).ToList());
 }
        public static IList<AttributeToCss> FindEquivalent(IDomObject domobject, StyleClass styles)
        {

            return (from attributeRuleMatch in _linkedAttributes
                    where domobject.HasAttribute(attributeRuleMatch.Key) && styles.Attributes.ContainsKey(attributeRuleMatch.Value)
                    select new AttributeToCss
                        {
                            AttributeName = attributeRuleMatch.Key, CssValue = styles.Attributes[attributeRuleMatch.Value].Value
                        }).ToList();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Try get dependency reference from a "reference" element.
        /// </summary>
        ///
        /// <param name="parent">
        /// The parent.
        /// </param>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="scriptRef">
        /// The relative path to the file to analyze.
        /// </param>
        ///
        /// <returns>
        /// true if it succeeds, false if it fails.
        /// </returns>

        protected bool TryGetDependencyRef_CQ(ScriptRef parent, IDomObject element, out ScriptRef scriptRef)
        {
            bool noCombine = element.HasAttribute("nocombine");
            bool ignore    = element.HasAttribute("ignore");

            scriptRef = null;

            string options = element["options"];

            if (!string.IsNullOrEmpty(options))
            {
                var optList = options.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);


                ignore    = ignore || optList.Contains("ignore", StringComparer.CurrentCultureIgnoreCase);
                noCombine = noCombine || optList.Contains("nocombine", StringComparer.CurrentCultureIgnoreCase);
            }
            if (ignore)
            {
                return(false);
            }

            var depName = element["path"];

            string path;

            if (!TryResolvePath(parent.RelativePathRoot, depName, out path) && !IgnoreErrors)
            {
                throw new FileNotFoundException(String.Format("Unable to find dependency \"{0}\" in the file \"{1}\".", depName, parent.Path));
            }
            scriptRef = new ScriptRef
            {
                Path      = path,
                NoCombine = noCombine
            };

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Parse an HTML attribute construct: {x=["|']y["|]]} or just {x}) and add the attribute to the
        /// current element if successful. The placeholder should be tag opening construct but after the
        /// tag name. Upon exit it will be positioned after last character of attribute, or  positioned
        /// ON closing caret of tag opener if failed.
        /// </summary>
        ///
        /// <param name="html">
        /// The HTML
        /// </param>
        ///
        /// <returns>
        /// true if it succeeds, false if it fails.
        /// </returns>

        public bool GetTagAttribute(char[] html)
        {
            bool   finished  = false;
            int    step      = 0;
            string aName     = null;
            string aValue    = null;
            int    nameStart = -1;
            int    valStart  = -1;
            bool   isQuoted  = false;
            char   quoteChar = ' ';
            int    len       = html.Length;

            while (!finished && Pos < len)
            {
                char c = html[Pos];
                switch (step)
                {
                case 0:     // find name
                    if (CharacterData.IsType(c, CharacterType.HtmlTagNameStart))
                    {
                        step      = 1;
                        nameStart = Pos;
                        Pos++;
                    }
                    else if (CharacterData.IsType(c, CharacterType.HtmlTagAny))
                    {
                        finished = true;
                    }
                    else
                    {
                        Pos++;
                    }

                    break;

                case 1:
                    if (!CharacterData.IsType(c, CharacterType.HtmlTagNameExceptStart))
                    {
                        step  = 2;
                        aName = html.SubstringBetween(nameStart, Pos);
                    }
                    else
                    {
                        Pos++;
                    }
                    break;

                case 2:     // find value
                    if (CharacterData.IsType(c, CharacterType.HtmlSpace))
                    {
                        Pos++;
                        break;
                    }
                    else if (c == '=')
                    {
                        step = 3;
                        Pos++;
                    }
                    else
                    {
                        // anything else means new attribute
                        finished = true;
                        break;
                    }
                    break;

                case 3:     // find quote start
                    if (CharacterData.IsType(c, CharacterType.HtmlSpace))
                    {
                        Pos++;
                        break;
                    }
                    else
                    {
                        switch (c)
                        {
                        case '\\':
                        case '>':
                            finished = true;
                            break;

                        case '"':
                        case '\'':
                            isQuoted = true;
                            valStart = Pos + 1;
                            Pos++;
                            quoteChar = c;
                            step      = 4;
                            break;

                        default:
                            valStart = Pos;
                            step     = 4;
                            break;
                        }
                    }

                    break;

                case 4:     // parse the attribute until whitespace or closing quote
                    if ((isQuoted && c == quoteChar) ||
                        (!isQuoted && CharacterData.IsType(c, CharacterType.HtmlTagOpenerEnd)))
                    {
                        aValue = html.SubstringBetween(valStart, Pos);
                        if (isQuoted)
                        {
                            isQuoted = false;
                            Pos++;
                        }
                        finished = true;
                    }
                    else
                    {
                        Pos++;
                    }
                    break;
                }
            }
            if (aName != null)
            {
                // 12-15-11 - don't replace a valid attribute with a bad one

                if (!Element.HasAttribute(aName))
                {
                    if (aValue == null)
                    {
                        Element.SetAttribute(aName);
                    }
                    else
                    {
                        Element.SetAttribute(aName, aValue);
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }