Skip to content

Commit

Permalink
Allow changing the name of the enum global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
c0shea committed May 4, 2018
1 parent 0678c2c commit d93ddbd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
16 changes: 15 additions & 1 deletion src/WebHelpers.Mvc5/Enum/EnumHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class EnumHandler : IHttpHandler
{
private static readonly TimeSpan CacheFor = TimeSpan.FromDays(7);
private static readonly Lazy<string> JavaScript = new Lazy<string>(GetJavaScript);
private static string _globalVariableName = "Enums";

/// <summary>
/// Gets a value indicating whether another request can use the <see cref="IHttpHandler"/> instance.
Expand All @@ -35,6 +36,16 @@ public class EnumHandler : IHttpHandler
// ReSharper disable once MemberCanBePrivate.Global
public static EnumCollection EnumsToExpose { get; } = new EnumCollection();

/// <summary>
/// Allows you change the name of the global variable that is created for the enums.
/// It is Enums by default.
/// </summary>
public static string GlobalVariableName
{
get => _globalVariableName;
set => _globalVariableName = value ?? throw new ArgumentNullException(nameof(value));
}

/// <summary>
/// Handles a HTTP request.
/// </summary>
Expand Down Expand Up @@ -66,7 +77,10 @@ private static void SetCachingHeaders(HttpContext context, string output)

private static string GetJavaScript()
{
var sb = new StringBuilder("window.Enums = Object.freeze({");
var sb = new StringBuilder("window.");
sb.Append(GlobalVariableName);
sb.Append(" = Object.freeze({");

var enumsFound = GetTypesWithExposeAttribute();

for (int i = 0; i < enumsFound.Count; i++)
Expand Down
7 changes: 3 additions & 4 deletions src/WebHelpers.Mvc5/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand All @@ -10,7 +9,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WebHelpers.Mvc5")]
[assembly: AssemblyCopyright("Copyright © 2017 Connor O'Shea")]
[assembly: AssemblyCopyright("Copyright © 2018 Connor O'Shea")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
8 changes: 4 additions & 4 deletions src/WebHelpers.Mvc5/WebHelpers.Mvc5.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<package>
<metadata>
<id>WebHelpers.Mvc5</id>
<version>1.2.0</version>
<version>1.3.0</version>
<title>WebHelpers.Mvc5</title>
<authors>Connor O'Shea</authors>
<owners>Connor O'Shea</owners>
<licenseUrl>https://github.com/c0shea/WebHelpers.Mvc5/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/c0shea/WebHelpers.Mvc5</projectUrl>
<iconUrl>https://raw.githubusercontent.com/c0shea/WebHelpers.Mvc5/master/NuGet%20Package%20Icon.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A collection of helpers for ASP.NET MVC5.</description>
<copyright>Copyright 2017</copyright>
<tags>AspNet Mvc AspNetMvc Helpers Extensions</tags>
<description>A collection of helpers, like sharing enums with JavaScript and version query parameters, for ASP.NET MVC5.</description>
<copyright>Copyright 2018</copyright>
<tags>AspNet Mvc AspNetMvc Helpers Extensions Enums</tags>
<dependencies>
<dependency id="Microsoft.AspNet.Mvc" version="5.2.3" />
<dependency id="Microsoft.AspNet.Web.Optimization" version="1.1.3" />
Expand Down

0 comments on commit d93ddbd

Please sign in to comment.