コード例 #1
0
        /// <summary>
        /// Checks if the current file implements the html attribute interfaces and returns the appropriate html attributes
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private static IDictionary <string, string> GetHtmlAttributes(IClientDependencyFile file)
        {
            IDictionary <string, string> attributes = new Dictionary <string, string>();

            var htmlAttributes = file as IHaveHtmlAttributes;

            if (htmlAttributes != null)
            {
                var fileWithAttributes = htmlAttributes;
                attributes = fileWithAttributes.HtmlAttributes;

                var parsing = file as IRequiresHtmlAttributesParsing;
                if (parsing != null)
                {
                    //we need to parse the attributes into the dictionary
                    HtmlAttributesStringParser.ParseIntoDictionary(parsing.HtmlAttributesAsString, attributes);
                }
            }

            //now we must ensure that the correct js/css attribute exist!
            switch (file.DependencyType)
            {
            case ClientDependencyType.Javascript:
                if (!attributes.ContainsKey("type"))
                {
                    attributes.Add("type", "text/javascript");
                }
                if (attributes.ContainsKey("src"))
                {
                    attributes.Remove("src");
                }
                break;

            case ClientDependencyType.Css:
                if (!attributes.ContainsKey("type"))
                {
                    attributes.Add("type", "text/css");
                }
                if (!attributes.ContainsKey("rel"))
                {
                    attributes.Add("rel", "stylesheet");
                }
                if (attributes.ContainsKey("href"))
                {
                    attributes.Remove("href");
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            //just return an empty dictionary
            return(attributes);
        }
コード例 #2
0
        public void Parse_Normal_String()
        {
            const string attributes  = "media:print";
            var          destination = new Dictionary <string, string>();

            HtmlAttributesStringParser.ParseIntoDictionary(attributes, destination);

            Assert.AreEqual(1, destination.Count);
            Assert.AreEqual("print", destination.Last().Value);
            Assert.AreEqual("media", destination.Last().Key);
        }
コード例 #3
0
        public void Parse_Media_Query()
        {
            const string attributes  = "media:(max-width:560px)";
            var          destination = new Dictionary <string, string>();

            HtmlAttributesStringParser.ParseIntoDictionary(attributes, destination);

            Assert.AreEqual(1, destination.Count);
            Assert.AreEqual("(max-width:560px)", destination.Last().Value);
            Assert.AreEqual("media", destination.Last().Key);
        }
コード例 #4
0
        public void Parse_Delimited_String_With_Comma()
        {
            const string attributes  = "media:'print, projection'";
            var          destination = new Dictionary <string, string>();

            HtmlAttributesStringParser.ParseIntoDictionary(attributes, destination);

            Assert.AreEqual(1, destination.Count);
            Assert.AreEqual("print, projection", destination.Last().Value);
            Assert.AreEqual("media", destination.Last().Key);
        }
コード例 #5
0
        public void Ensure_No_Duplicates()
        {
            const string attributes  = "defer:true,async:true";
            var          destination = new Dictionary <string, string>();

            HtmlAttributesStringParser.ParseIntoDictionary(attributes, destination);

            Assert.AreEqual(2, destination.Count);
            Assert.AreEqual("defer", destination.First().Key);
            Assert.AreEqual("true", destination.First().Value);
            Assert.AreEqual("async", destination.Last().Key);
            Assert.AreEqual("true", destination.Last().Value);
        }