Testing WP-Syntax

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
public static class StylesheetExtensions
{
    public static string Stylesheet(this HtmlHelper helper, string file)
    {
        return Stylesheet(helper, new string[] { file }, null);
    }
 
    public static string Stylesheet(this HtmlHelper helper, string file, object htmlAttributes)
    {
        return Stylesheet(helper, new string[] { file }, new RouteValueDictionary(htmlAttributes));
    }
 
    public static string Stylesheet(this HtmlHelper helper, string file, RouteValueDictionary htmlAttributes)
    {
        return Stylesheet(helper, new string[] { file }, htmlAttributes);
    }
 
    public static string Stylesheet(this HtmlHelper helper, string[] files)
    {
        return Stylesheet(helper, files, null);
    }
 
    public static string Stylesheet(this HtmlHelper helper, string[] files, object htmlAttributes)
    {
        return Stylesheet(helper, files, new RouteValueDictionary(htmlAttributes));
    }
 
    public static string Stylesheet(this HtmlHelper helper, string[] files, RouteValueDictionary htmlAttributes)
    {
        StringBuilder output = new StringBuilder();
        foreach (var file in files)
        {
            TagBuilder link = new TagBuilder("link");
            link.MergeAttribute("rel", "stylesheet");
            link.MergeAttribute("type", "text/css");
            string absoluteFile = "/Content/css/" + file;
            link.MergeAttribute("href", absoluteFile);
            link.MergeAttributes(htmlAttributes); 
            output.Append(link.ToString(TagRenderMode.SelfClosing));
        }
        return output.ToString();
    }
}

1 Response to “Testing WP-Syntax”


Leave a Reply