Beispiel #1
0
 public static void AddData(this ITag tag, string key, string value)
 {
     if (string.IsNullOrWhiteSpace(key))
     {
         throw new ArgumentException();
     }
     tag.AddAttribute($"data-{key}", value);
 }
Beispiel #2
0
 public static void AddTitle(this ITag tag, string title)
 {
     if (string.IsNullOrWhiteSpace(title))
     {
         throw new ArgumentException();
     }
     tag.AddAttribute("title", title);
 }
Beispiel #3
0
        public static void AddClasses(this ITag tag, params string[] classes)
        {
            var distinctClasses = classes.GroupBy(c => c)
                                  .Select(c => c.First())
                                  .Where(c => !string.IsNullOrWhiteSpace(c));

            tag.AddAttribute("class", string.Join(" ", distinctClasses));
        }
Beispiel #4
0
        public static void AddId(this ITag tag, string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("id can't be empty");
            }

            if (!id[0].IsLetter())
            {
                throw new ArgumentException("first id character must be a letter");
            }

            for (int i = 1; i < id.Length; i++)
            {
                if (!id[i].IsValidIdCharacter())
                {
                    throw new ArgumentException($"id cannot contain character {id[i]}");
                }
            }

            tag.AddAttribute("id", id);
        }