Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added support for both pascal casing and underscored action method na…

…mes.
  • Loading branch information...
commit 57cfa96ae7ce03c55e25eeb74a20d1500760b414 1 parent 2ac5678
@casualjim casualjim authored
Showing with 23 additions and 35 deletions.
  1. +13 −10 IronRubyMvc/Controllers/RubyActionMethodSelector.cs
  2. +2 −3 IronRubyMvc/Controllers/RubyController.cs
  3. +4 −0 IronRubyMvc/Controllers/controller.rb
  4. +0 −8 IronRubyMvc/Core/IRubyEngine.cs
  5. +3 −13 IronRubyMvc/Core/RubyEngine.cs
  6. +1 −1  IronRubyMvc/System.Web.Mvc.IronRuby.csproj
  7. BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.Libraries.dll
  8. BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.Libraries.pdb
  9. BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.dll
  10. BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.pdb
  11. BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.Core.dll
  12. BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.Core.pdb
  13. BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.ExtensionAttribute.dll
  14. BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.ExtensionAttribute.pdb
  15. BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.dll
  16. BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.pdb
  17. BIN  dependencies/IronRuby.Libraries.Yaml.dll
  18. BIN  dependencies/IronRuby.Libraries.Yaml.pdb
  19. BIN  dependencies/IronRuby.Libraries.dll
  20. BIN  dependencies/IronRuby.Libraries.pdb
  21. BIN  dependencies/IronRuby.dll
  22. BIN  dependencies/IronRuby.pdb
  23. BIN  dependencies/Microsoft.Scripting.Core.dll
  24. BIN  dependencies/Microsoft.Scripting.Core.pdb
  25. BIN  dependencies/Microsoft.Scripting.ExtensionAttribute.dll
  26. BIN  dependencies/Microsoft.Scripting.ExtensionAttribute.pdb
  27. BIN  dependencies/Microsoft.Scripting.dll
  28. BIN  dependencies/Microsoft.Scripting.pdb
View
23 IronRubyMvc/Controllers/RubyActionMethodSelector.cs
@@ -53,12 +53,12 @@ private void PopulateLookupTables(IEnumerable<string> methodNames)
{
var methodAliases = (Hash)_rubyEngine.CallMethod(ControllerClass, "name_selectors");
AliasedMethods = methodAliases.Map(pair => KeyValuePairFor(pair));
- NonAliasedMethods = methodNames.Where(method => AliasedMethods.DoesNotContain(pair => String.Equals(pair.Key, method, StringComparison.OrdinalIgnoreCase)));
+ NonAliasedMethods = methodNames.Where(method => AliasedMethods.DoesNotContain(pair => String.Equals(pair.Key, method.Underscore(), StringComparison.OrdinalIgnoreCase) || String.Equals(pair.Key, method.Pascalize(), StringComparison.OrdinalIgnoreCase)));
}
- private KeyValuePair<string, PredicateList> KeyValuePairFor(KeyValuePair<object, object> pair)
+ private static KeyValuePair<string, PredicateList> KeyValuePairFor(KeyValuePair<object, object> pair)
{
- return new KeyValuePair<string, PredicateList>(pair.Key.ToString(), new PredicateList(_rubyEngine, (RubyArray) pair.Value));
+ return new KeyValuePair<string, PredicateList>(pair.Key.ToString(), new PredicateList((RubyArray) pair.Value));
}
private static AmbiguousMatchException CreateAmbiguousMatchException(string actionName)
@@ -70,7 +70,7 @@ public string FindActionMethod(ControllerContext controllerContext, string actio
{
PopulateLookupTables(controllerContext); // dynamic languages can add methods at runtime
var methodsMatchingName = GetMatchingAliasedMethods(controllerContext, actionName);
- methodsMatchingName.AddRange(NonAliasedMethods.Where(name => String.Equals(name, actionName, StringComparison.OrdinalIgnoreCase)));
+ methodsMatchingName.AddRange(NonAliasedMethods.Where(name => String.Equals(name, actionName.Underscore(), StringComparison.OrdinalIgnoreCase) || String.Equals(name, actionName.Pascalize(), StringComparison.OrdinalIgnoreCase)));
var finalMethods = RunSelectionFilters(controllerContext, methodsMatchingName);
switch (finalMethods.Count)
@@ -104,7 +104,7 @@ private List<string> GetMatchingAliasedMethods(ControllerContext controllerConte
private List<string> RunSelectionFilters(ControllerContext controllerContext, IEnumerable<string> matchingMethods)
{
var filtersDescriptions = (Hash) _rubyEngine.CallMethod(ControllerClass, "method_selectors");
- var filters = filtersDescriptions.Where(pair => matchingMethods.Contains(pair.Key.ToString())).Map(pair => KeyValuePairFor(pair));
+ var filters = filtersDescriptions.Where(pair => matchingMethods.Contains(pair.Key.ToString().Underscore()) || matchingMethods.Contains(pair.Key.ToString().Pascalize())).Map(pair => KeyValuePairFor(pair));
return filters.Count() == 0
? new List<string>(matchingMethods)
@@ -120,11 +120,9 @@ public class PredicateList : IEnumerable<Func<ControllerContext, string, bool>>
{
private readonly RubyArray _items;
private readonly List<Func<ControllerContext, string, bool>> _predicates = new List<Func<ControllerContext, string, bool>>();
- private readonly IRubyEngine _rubyEngine;
- public PredicateList(IRubyEngine rubyEngine, RubyArray items)
+ public PredicateList(RubyArray items)
{
- _rubyEngine = rubyEngine;
_items = items;
Populate();
}
@@ -136,7 +134,7 @@ private void Populate()
private void Add(Proc proc)
{
- _predicates.Add(_rubyEngine.ConvertProcToFunc<bool>(proc));
+ _predicates.Add(ConvertProcToFunc<bool>(proc));
}
public bool IsValid(ControllerContext context, string name)
@@ -146,7 +144,12 @@ public bool IsValid(ControllerContext context, string name)
public bool IsValidForAction(ControllerContext context, string name)
{
- return _predicates.Any(predicate => predicate(context, name));
+ return _predicates.Any(predicate => predicate(context, name.Underscore())|| predicate(context, name.Pascalize()));
+ }
+
+ public Func<ControllerContext, string, TResult> ConvertProcToFunc<TResult>(Proc proc)
+ {
+ return (context, name) => (TResult)proc.Call(context, name);
}
#region Implementation of IEnumerable
View
5 IronRubyMvc/Controllers/RubyController.cs
@@ -49,7 +49,6 @@ private void PopulateParams()
_params =
new Dictionary<object, object>(ControllerContext.RouteData.Values.Count +
request.QueryString.Count + request.Form.Count);
-
PopulateParamsWithRouteData();
PopulateParamsWithQueryStringData(request);
@@ -146,12 +145,12 @@ public new ViewResult View(string viewName, string masterName, object model)
vdd["__scriptRuntime"] = ((RubyEngine) _engine).Runtime;
_engine.CallMethod(this, "fill_view_data");
-
foreach (var entry in _viewData)
vdd[Convert.ToString(entry.Key, CultureInfo.InvariantCulture)] = entry.Value;
-
+
var hash = model as Hash;
vdd.Model = (hash != null) ? new HashWrapper(hash) : model;
+ ModelState.ForEach(pair => vdd.ModelState.Add(pair.Key.ToString(), pair.Value));
return new ViewResult {ViewName = viewName, MasterName = masterName, ViewData = vdd, TempData = TempData};
}
View
4 IronRubyMvc/Controllers/controller.rb
@@ -230,6 +230,10 @@ class Controller < System::Web::Mvc::IronRuby::Controllers::RubyController
def fill_view_data
instance_variables.each { |varname| view_data.add(varname[1..-1], instance_variable_get(varname.to_sym)) }
end
+
+ def post?
+ controller_context.http_context.request.http_method.to_s.downcase.to_sym == :post
+ end
end
View
8 IronRubyMvc/Core/IRubyEngine.cs
@@ -30,14 +30,6 @@ public interface IRubyEngine
RubyController ConfigureController(RubyClass rubyClass, RequestContext requestContext);
/// <summary>
- /// Converts a proc object to a .NET Func.
- /// </summary>
- /// <typeparam name="TResult">The type of the result.</typeparam>
- /// <param name="proc">The proc.</param>
- /// <returns></returns>
- Func<ControllerContext, string, TResult> ConvertProcToFunc<TResult>(Proc proc);
-
- /// <summary>
/// Calls the method.
/// </summary>
/// <param name="receiver">The receiver.</param>
View
16 IronRubyMvc/Core/RubyEngine.cs
@@ -9,6 +9,7 @@
using System.Web.Mvc.IronRuby.Extensions;
using System.Web.Mvc.IronRuby.ViewEngine;
using System.Web.Routing;
+using System.Web.Security;
using IronRuby;
using IronRuby.Builtins;
using IronRuby.Runtime;
@@ -126,17 +127,6 @@ public RubyController ConfigureController(RubyClass rubyClass, RequestContext re
return controller;
}
- /// <summary>
- /// Converts a proc object to a .NET Func.
- /// </summary>
- /// <typeparam name="TResult">The type of the result.</typeparam>
- /// <param name="proc">The proc.</param>
- /// <returns></returns>
- public Func<ControllerContext, string, TResult> ConvertProcToFunc<TResult>(Proc proc)
- {
- return (context, name) => (TResult) proc.Call(context, name);
- }
-
public string GetMethodName(object receiver, string message)
{
var methodNames = Operations.GetMemberNames(receiver);
@@ -156,7 +146,7 @@ public string GetMethodName(object receiver, string message)
/// <returns></returns>
public object CallMethod(object receiver, string message, params object[] args)
{
- return Operations.InvokeMember(receiver, GetMethodName(receiver, message), args);
+ return Operations.InvokeMember(receiver, GetMethodName(receiver, message));
}
/// <summary>
@@ -271,7 +261,7 @@ private void Initialize()
Context = Ruby.GetExecutionContext(Engine);
CurrentScope = Engine.CreateScope();
Operations = Engine.CreateOperations();
- LoadAssemblies(typeof (object), typeof (Uri), typeof (HttpResponseBase), typeof (RouteTable), typeof (Controller), typeof (RubyController));
+ LoadAssemblies(typeof (object), typeof (Uri), typeof (HttpResponseBase), typeof(MembershipCreateStatus), typeof (RouteTable), typeof (Controller), typeof (RubyController));
AddLoadPaths();
DefineReadOnlyGlobalVariable(Constants.SCRIPT_RUNTIME_VARIABLE, Engine);
RequireControllerFile();
View
2  IronRubyMvc/System.Web.Mvc.IronRuby.csproj
@@ -20,7 +20,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
- <OutputPath>..\IronRubyMvcLibrarySpecs\bin\</OutputPath>
+ <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
View
BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.Libraries.dll
Binary file not shown
View
BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.Libraries.pdb
Binary file not shown
View
BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.dll
Binary file not shown
View
BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.pdb
Binary file not shown
View
BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.Core.dll
Binary file not shown
View
BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.Core.pdb
Binary file not shown
View
BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.ExtensionAttribute.dll
Binary file not shown
View
BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.ExtensionAttribute.pdb
Binary file not shown
View
BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.dll
Binary file not shown
View
BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.pdb
Binary file not shown
View
BIN  dependencies/IronRuby.Libraries.Yaml.dll
Binary file not shown
View
BIN  dependencies/IronRuby.Libraries.Yaml.pdb
Binary file not shown
View
BIN  dependencies/IronRuby.Libraries.dll
Binary file not shown
View
BIN  dependencies/IronRuby.Libraries.pdb
Binary file not shown
View
BIN  dependencies/IronRuby.dll
Binary file not shown
View
BIN  dependencies/IronRuby.pdb
Binary file not shown
View
BIN  dependencies/Microsoft.Scripting.Core.dll
Binary file not shown
View
BIN  dependencies/Microsoft.Scripting.Core.pdb
Binary file not shown
View
BIN  dependencies/Microsoft.Scripting.ExtensionAttribute.dll
Binary file not shown
View
BIN  dependencies/Microsoft.Scripting.ExtensionAttribute.pdb
Binary file not shown
View
BIN  dependencies/Microsoft.Scripting.dll
Binary file not shown
View
BIN  dependencies/Microsoft.Scripting.pdb
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.