Пример #1
0
        static void Main(string[] args)
        {
            //- creating an simple A link, with id and class

            var link = new Tag("a","Click for oblivion!", href:"http://somewhere/far/away", id:"starlink", @class:"starred");

            Dump(link);

            //- the same thing but now via shorthand - the . denotes an class and the # a id

            var linkshorthand = new Tag("a.starlink#starred","Click for oblivion!", href:"http://somewhere/far/away");

            Dump(linkshorthand);

            //- creating an UL with child LI

            var nested = new Tag("ul",
                new Tag("li", "Look im an li!", @class:"hello", id:"hello"),
                new Tag("li", "Look im another li!", @class:"awesome"));

            Dump(nested);

            //- creating two sibling breaks

            var siblings = new Tag("br");
            siblings += new Tag("br");

            Dump(siblings);

            // doing the same thing but lazy via string implicit string conversion

            Tag lazysiblings = "hr";
            lazysiblings += "hr";
            lazysiblings += (Tag)"hr.rainbow" + (Tag)"hr.doublerainbow";

            Dump(lazysiblings);

            //- or create a image with class pretty and id main, and set the src to google and add a rainbow

            var lazyWithAttributes = ((Tag)"img.pretty#main").Attr("src","http://www.lolcats.com") + "hr.rainbow";
            Dump(lazyWithAttributes);

            //- some more samples

            var linq = new []{ "Coffee","Crack", "Energy drink"};

            var
            html =
                new Tag("ul.starred#main",
                   	new Tag("li.fav",  content: "CONTENT", name: "MYNAME", type: "MYTYPE"),
                    new Tag("li.fav", "CONTENT", name: "MYNAME"));

            html +=
                new Tag("div.CLASS#ID",content: "CONTENT", id: "myid", name:"NAME", href:"HREF",
                        target:"TARGET", title:"TITLE", style:"asd", alt:"ALT", src:"SRC");

            html += "hr.CLASS";
            html += new Tag("ul#toplist",
                    from
                        stimulant
                    in
                        linq
                    select
                        new Tag("li",stimulant, @class:(stimulant=="Crack"?"illegal":"ok")));

            Dump(html);

            Tag divwithclass = ".someclasss";
            Dump(divwithclass);

            Tag divwithid = "#someid";
            Dump(divwithid);
        }
Пример #2
0
 static void Dump(Tag t)
 {
     Console.WriteLine (t);
 }