Permalink
Browse files

Accidentally ran R# clean up code on the project :-S. Added the ajax …

…helper to the view engine
  • Loading branch information...
1 parent db205c9 commit 4f9355dd09c1af364e50d7f5f6addf270bd969c6 @casualjim casualjim committed Mar 26, 2009
@@ -11,7 +11,6 @@ namespace System.Web.Mvc.IronRuby.Controllers
{
public class RubyActionDescriptor : ActionDescriptor
{
- public IRubyEngine RubyEngine { get; set; }
private readonly string _actionName;
private readonly ControllerDescriptor _controllerDescriptor;
@@ -22,6 +21,8 @@ public RubyActionDescriptor(string actionName, ControllerDescriptor controllerDe
_controllerDescriptor = controllerDescriptor;
}
+ public IRubyEngine RubyEngine { get; set; }
+
public override string ActionName
{
get { return _actionName; }
@@ -1,7 +1,5 @@
#region Usings
-
-
#endregion
namespace System.Web.Mvc.IronRuby.Controllers
@@ -51,9 +51,13 @@ private void PopulateLookupTables(ControllerContext controllerContext)
private void PopulateLookupTables(IEnumerable<string> methodNames)
{
- var methodAliases = (Hash)_rubyEngine.CallMethod(ControllerClass, "name_selectors");
+ 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.Underscore(), StringComparison.OrdinalIgnoreCase) || String.Equals(pair.Key, method.Pascalize(), 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 static KeyValuePair<string, PredicateList> KeyValuePairFor(KeyValuePair<object, object> pair)
@@ -70,7 +74,9 @@ 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.Underscore(), StringComparison.OrdinalIgnoreCase) || String.Equals(name, actionName.Pascalize(), 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,18 +110,20 @@ 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().Underscore()) || matchingMethods.Contains(pair.Key.ToString().Pascalize())).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)
: new List<string>(
- matchingMethods.Where(
- methodName => filters.All(filter => filter.Value.IsValid(controllerContext, methodName))
- )
- );
+ matchingMethods.Where(
+ methodName => filters.All(filter => filter.Value.IsValid(controllerContext, methodName))
+ )
+ );
}
}
-
+
public class PredicateList : IEnumerable<Func<ControllerContext, string, bool>>
{
private readonly RubyArray _items;
@@ -147,7 +155,7 @@ public bool IsValidForAction(ControllerContext context, string name)
var result = false;
foreach (var list in _predicates)
{
- if(list(context, name))
+ if (list(context, name))
{
result = true;
break;
@@ -165,7 +173,7 @@ public bool IsValidForAction(ControllerContext context, string name)
public Func<ControllerContext, string, TResult> ConvertProcToFunc<TResult>(Proc proc)
{
- return (context, name) => (TResult)proc.Call(context, name);
+ return (context, name) => (TResult) proc.Call(context, name);
}
#region Implementation of IEnumerable
@@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
-using System.Threading;
using System.Web.Mvc.IronRuby.Core;
using System.Web.Mvc.IronRuby.Extensions;
using System.Web.Mvc.IronRuby.Helpers;
@@ -75,7 +74,7 @@ private void PopulateParamsWithQueryStringData(HttpRequestBase request)
var symbolKey = SymbolTable.StringToId(key);
var value = request.QueryString[key];
_params[symbolKey] = value;
- ModelState.Add(key, CreateModelState(value) );
+ ModelState.Add(key, CreateModelState(value));
}
}
@@ -122,7 +121,7 @@ public ActionResult RedirectToRoute(Hash values)
[NonAction]
public ActionResult RedirectToAction(string actionName, Hash values)
- {
+ {
return RedirectToAction(actionName, values.ToRouteDictionary());
}
@@ -164,7 +163,7 @@ public new ViewResult View(string viewName, string masterName, object model)
_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));
@@ -65,7 +65,7 @@ public override ActionDescriptor FindAction(ControllerContext controllerContext,
actionName.EnsureArgumentNotNull("actionName");
var selectedName = _selector.FindActionMethod(controllerContext, actionName);
- return selectedName.IsNotNullOrBlank() ? new RubyActionDescriptor(selectedName, this, _engine ) : null;
+ return selectedName.IsNotNullOrBlank() ? new RubyActionDescriptor(selectedName, this, _engine) : null;
}
/// <summary>
@@ -1,6 +1,5 @@
#region Usings
-using System.Text;
using System.Web.Mvc.IronRuby.Core;
using System.Web.Mvc.IronRuby.Extensions;
using System.Web.Routing;
@@ -13,8 +12,8 @@ namespace System.Web.Mvc.IronRuby.Controllers
public class RubyControllerFactory : IControllerFactory
{
private readonly IRubyEngine _engine;
- private readonly IPathProvider _pathProvider;
private readonly IControllerFactory _innerFactory;
+ private readonly IPathProvider _pathProvider;
internal RubyControllerFactory(IPathProvider pathProvider, IControllerFactory innerFactory, IRubyEngine engine)
{
@@ -86,7 +85,7 @@ private RubyController LoadController(RequestContext requestContext, string cont
private RubyController ConfigureController(RubyClass rubyClass, RequestContext requestContext)
{
var controller = _engine.CreateInstance<RubyController>(rubyClass);
- controller.InternalInitialize(new ControllerConfiguration { Context = requestContext, Engine = _engine, RubyClass = rubyClass });
+ controller.InternalInitialize(new ControllerConfiguration {Context = requestContext, Engine = _engine, RubyClass = rubyClass});
return controller;
}
@@ -1,7 +1,5 @@
#region Usings
-
-
#endregion
namespace System.Web.Mvc.IronRuby.Controllers
@@ -1,13 +1,17 @@
+#region Usings
+
using System.IO;
using System.Reflection;
using Microsoft.Scripting;
+#endregion
+
namespace System.Web.Mvc.IronRuby.Core
{
public class AssemblyStreamContentProvider : StreamContentProvider
{
- private readonly string _fileName;
private readonly Assembly _assembly;
+ private readonly string _fileName;
public AssemblyStreamContentProvider(string fileName, Assembly assembly)
{
@@ -2,23 +2,22 @@ namespace System.Web.Mvc.IronRuby.Core
{
internal class Constants
{
- public const string ControllerPascalPathFormat = @"~\Controllers\{0}Controller.rb";
- public const string ControllerUnderscorePathFormat = @"~\Controllers\{0}_controller.rb";
public const string ControllerclassFormat = "{0}Controller";
public const string ControllernameNameRegex = @"^(\w)+$";
+ public const string ControllerPascalPathFormat = @"~\Controllers\{0}Controller.rb";
public const string Controllers = "Controllers";
+ public const string ControllerUnderscorePathFormat = @"~\Controllers\{0}_controller.rb";
public const string Filters = "Filters";
public const string FiltersPascalPathFormat = @"~\Filters\{0}.rb";
public const string FiltersUnderscorePathFormat = @"~\Filters\{0}.rb";
- public const string Models = "Models";
- public const string RubycontrollerFile = "System.Web.Mvc.IronRuby.Controllers.controller.rb";
- public const string ScriptRuntimeVariable = "script_runtime";
-
public const string Helpers = "Helpers";
public const string HelpersPascalPathFormat = @"~\Filters\{0}.rb";
public const string HelpersUnderscorePathFormat = @"~\Filters\{0}.rb";
+ public const string Models = "Models";
+ public const string RubycontrollerFile = "System.Web.Mvc.IronRuby.Controllers.controller.rb";
+ public const string ScriptRuntimeVariable = "script_runtime";
}
}
@@ -5,5 +5,4 @@ public enum ReaderType
File,
AssemblyResource
}
-
}
@@ -3,8 +3,6 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
-using System.Web.Mvc.IronRuby.Controllers;
-using System.Web.Routing;
using IronRuby.Builtins;
using Microsoft.Scripting.Hosting;
@@ -142,7 +140,7 @@ public interface IRubyEngine
/// </summary>
/// <param name="path">The path.</param>
void RequireRubyFile(string path);
-
+
/// <summary>
/// Requires the ruby file.
/// </summary>
@@ -1,15 +1,11 @@
#region Usings
-
-
#endregion
namespace System.Web.Mvc.IronRuby.Core
{
public class RubyMvcApplication : HttpApplication
{
-
-
protected void Application_Start(object sender, EventArgs e)
{
RubyEngine.InitializeIronRubyMvc(new VirtualPathProvider(), "~/routes.rb");
@@ -23,6 +19,5 @@ protected virtual void OnStart()
{
// override this to provide start behavior
}
-
}
}
@@ -3,7 +3,6 @@
using System.Collections;
using System.Web.Mvc.IronRuby.Extensions;
using System.Web.Routing;
-using IronRuby.Builtins;
#endregion
@@ -61,7 +60,7 @@ public void MapRoute(string name, string url, IDictionary defaults, IDictionary
DataTokens = new RouteValueDictionary()
};
route.DataTokens["Namespaces"] = namespaces;
- _routes.Add(name, route );
+ _routes.Add(name, route);
}
// public void MapRoute(string name, string url, MutableString[] namespaces)
@@ -94,13 +93,15 @@ public void IgnoreRoute(string url)
public void IgnoreRoute(string url, IDictionary constraints)
{
var route = new IgnoreRouteInternal(url)
- {
- Constraints = constraints.ToRouteDictionary()
- };
+ {
+ Constraints = constraints.ToRouteDictionary()
+ };
_routes.Add(route);
}
+ #region Nested type: IgnoreRouteInternal
+
private sealed class IgnoreRouteInternal : Route
{
public IgnoreRouteInternal(string url)
@@ -115,5 +116,7 @@ public override VirtualPathData GetVirtualPath(RequestContext requestContext, Ro
return null;
}
}
+
+ #endregion
}
}
@@ -1,7 +1,11 @@
+#region Usings
+
using System.IO;
using System.Web.Hosting;
using Microsoft.Scripting;
+#endregion
+
namespace System.Web.Mvc.IronRuby.Core
{
public class VirtualPathStreamContentProvider : StreamContentProvider
@@ -60,14 +60,14 @@ internal static FilterInfo ToFilterInfo(this IDictionary<object, object> filterD
return filterInfo;
}
-
+
private static IEnumerable<TITarget> ToFilters<TITarget>(this IDictionary<object, object> filterDescriptions, string actionName)
where TITarget : class
{
var filters = new List<TITarget>();
var key = SymbolTable.StringToId(actionName);
var hasKey = filterDescriptions.ContainsKey(key);
- if(hasKey) filters.AddRange((filterDescriptions[key] as RubyArray).Cast<TITarget>());
+ if (hasKey) filters.AddRange((filterDescriptions[key] as RubyArray).Cast<TITarget>());
return filters;
}
@@ -90,7 +90,5 @@ internal static IEnumerable<IResultFilter> ToResultFilters(this IDictionary<obje
{
return filterDescriptions.ToFilters<IResultFilter>(actionName);
}
-
-
}
}
Oops, something went wrong.

0 comments on commit 4f9355d

Please sign in to comment.