/
HtmlHelperExtensions.cs
127 lines (104 loc) · 4.64 KB
/
HtmlHelperExtensions.cs
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
namespace System.Web.Mvc
{
public static class HtmlHelpers
{
const string pubDir = "content";
const string cssDir = "css";
const string imageDir = "images";
const string scriptDir = "js";
public static string Script(this HtmlHelper helper, ViewPage pg, string fileName)
{
return Script(helper, pg.SiteRoot(), fileName);
}
public static string Script(this HtmlHelper helper, ViewPage pg, string viewDir, string fileName)
{
return Script(helper, pg.SiteRoot(), viewDir, fileName);
}
public static string Script(this HtmlHelper helper, ViewUserControl pg, string fileName)
{
return Script(helper, pg.SiteRoot(), fileName);
}
public static string Script(this HtmlHelper helper, ViewUserControl pg, string viewDir, string fileName)
{
return Script(helper, pg.SiteRoot(), viewDir, fileName);
}
public static string Script(this HtmlHelper helper, ViewMasterPage pg, string fileName)
{
return Script(helper, pg.SiteRoot(), fileName);
}
public static string Script(this HtmlHelper helper, ViewMasterPage pg, string viewDir, string fileName)
{
return Script(helper, pg.SiteRoot(), viewDir, fileName);
}
public static string Script(this HtmlHelper helper, string root, string fileName)
{
return Script(helper, root, string.Empty, fileName);
}
public static string Script(this HtmlHelper helper, string root, string viewDir, string fileName)
{
if (!fileName.EndsWith(".js"))
fileName += ".js";
if (!string.IsNullOrEmpty(viewDir))
viewDir += "/";
var jsPath = string.Format("<script src='{0}/{1}/{2}/{3}{4}' ></script>\n", root, pubDir, scriptDir, viewDir, helper.AttributeEncode(fileName));
return jsPath;
}
public static string CSS(this HtmlHelper helper, ViewMasterPage pg, string fileName)
{
return CSS(helper, pg.SiteRoot(), fileName);
}
public static string CSS(this HtmlHelper helper, ViewPage pg, string fileName)
{
return CSS(helper, pg.SiteRoot(), fileName);
}
public static string CSS(this HtmlHelper helper, ViewUserControl pg, string fileName)
{
return CSS(helper, pg.SiteRoot(), fileName);
}
public static string CSS(this HtmlHelper helper, string root, string fileName)
{
return CSS(helper, root, fileName, "screen");
}
public static string CSS(this HtmlHelper helper, string root, string fileName, string media)
{
if (!fileName.EndsWith(".css"))
fileName += ".css";
var jsPath = string.Format("<link rel='stylesheet' type='text/css' href='{0}/{1}/{2}/{3}' media='{4}'/>\n", root, pubDir, cssDir, helper.AttributeEncode(fileName), media);
return jsPath;
}
public static string Image(this HtmlHelper helper, ViewPage pg, string fileName)
{
return Image(helper, pg.SiteRoot(), fileName);
}
public static string Image(this HtmlHelper helper, ViewMasterPage pg, string fileName)
{
return Image(helper, pg.SiteRoot(), fileName);
}
public static string Image(this HtmlHelper helper, ViewUserControl pg, string fileName)
{
return Image(helper, pg.SiteRoot(), fileName);
}
public static string Image(this HtmlHelper helper, ViewPage pg, string fileName, string attributes)
{
return Image(helper, pg.SiteRoot(), fileName, attributes);
}
public static string Image(this HtmlHelper helper, ViewMasterPage pg, string fileName, string attributes)
{
return Image(helper, pg.SiteRoot(), fileName, attributes);
}
public static string Image(this HtmlHelper helper, ViewUserControl pg, string fileName, string attributes)
{
return Image(helper, pg.SiteRoot(), fileName, attributes);
}
public static string Image(this HtmlHelper helper, string root, string fileName)
{
return Image(helper, root, fileName, "");
}
public static string Image(this HtmlHelper helper, string root, string fileName, string attributes)
{
fileName = string.Format("{0}/{1}/{2}/{3}", root, pubDir, imageDir, fileName);
return string.Format("<img src='{0}' '{1}' />", helper.AttributeEncode(fileName), helper.AttributeEncode(attributes));
}
}
}