-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUrlExtensions.cs
More file actions
53 lines (48 loc) · 2.45 KB
/
UrlExtensions.cs
File metadata and controls
53 lines (48 loc) · 2.45 KB
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
using System;
using System.Web.Mvc;
namespace Spark.Example.MultiPageMvcWithRequireJs.Controllers
{
/// <summary>
/// Extension methods for <see cref="UrlHelper"/>.
/// </summary>
public static class UrlExtensions
{
private static readonly String ReleaseContent = "Content-" + Application.Version;
private static readonly String DebugContent = "Content";
/// <summary>
/// Get the script folder's base url.
/// </summary>
/// <param name="url">The <see cref="UrlHelper"/> instance to extend.</param>
public static String GetScriptBase(this UrlHelper url)
{
return url.Content("~/" + (url.RequestContext.HttpContext.IsDebuggingEnabled ? DebugContent : ReleaseContent) + "/js/");
}
/// <summary>
/// Get the script url based on the specified <paramref name="relativePath"/>.
/// </summary>
/// <param name="url">The <see cref="UrlHelper"/> instance to extend.</param>
/// <param name="relativePath">The relative script path from the base script folder.</param>
public static String Script(this UrlHelper url, String relativePath)
{
return url.Content("~/" + (url.RequestContext.HttpContext.IsDebuggingEnabled ? DebugContent : ReleaseContent) + "/js/" + relativePath);
}
/// <summary>
/// Get the stylesheet url based on the specified <paramref name="relativePath"/>.
/// </summary>
/// <param name="url">The <see cref="UrlHelper"/> instance to extend.</param>
/// <param name="relativePath">The relative stylesheet path from the base stylesheet folder.</param>
public static String StyleSheet(this UrlHelper url, String relativePath)
{
return url.Content("~/" + (url.RequestContext.HttpContext.IsDebuggingEnabled ? DebugContent : ReleaseContent) + "/css/" + relativePath);
}
/// <summary>
/// Get the image url based on the specified <paramref name="relativePath"/>.
/// </summary>
/// <param name="url">The <see cref="UrlHelper"/> instance to extend.</param>
/// <param name="relativePath">The relative image path from the base image folder.</param>
public static String Image(this UrlHelper url, String relativePath)
{
return url.Content("~/" + (url.RequestContext.HttpContext.IsDebuggingEnabled ? DebugContent : ReleaseContent) + "/img/" + relativePath);
}
}
}