Permalink
Browse files

Added link helper and select helper

  • Loading branch information...
1 parent 04f8d8e commit 9aab80d583f89f9d0ff48b4c94c0fd036065ec89 @casualjim casualjim committed Mar 26, 2009
View
@@ -20,4 +20,5 @@ IronRubyMvc/Controllers/._controller.rb
IronRubyMvc/Core/._RubyEngine.cs
dependencies/IronRuby.Tests.exe
dependencies/IronRuby.Tests.pdb
-IronRubyMvcLibrarySpecs/bin/*.*
+IronRubyMvcLibrarySpecs/bin/*.*
+ParamsBinder.cs
@@ -3,6 +3,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
+using IronRuby.Builtins;
#endregion
@@ -211,5 +212,27 @@ internal static TSource[] ToArray<TSource>(this IEnumerable<TSource> collection)
return result;
}
+ internal static IEnumerable<SelectListItem> ToSelectListItemList(this IEnumerable collection)
+ {
+ var result = new List<SelectListItem>();
+
+ collection.ForEach(item =>
+ {
+ var hash = (Hash) item;
+ var li = new SelectListItem();
+ hash.ForEach((key, value) =>
+ {
+ if (key.ToString() == "text")
+ li.Text = value.ToString();
+ if (key.ToString() == "value")
+ li.Value = value.ToString();
+ if (key.ToString() == "selected")
+ li.Selected = (bool) value;
+ });
+ result.Add(li);
+ });
+ return result;
+ }
+
}
}
@@ -0,0 +1,78 @@
+using System.Collections.Generic;
+using System.Web.Mvc.Html;
+using System.Web.Mvc.IronRuby.Extensions;
+using System.Web.Routing;
+using IronRuby.Builtins;
+
+namespace System.Web.Mvc.IronRuby.Helpers
+{
+ public partial class RubyHtmlHelper
+ {
+ public string ActionLink(string linkText, Hash values)
+ {
+ return _helper.RouteLink(linkText, values.ToRouteDictionary());
+ }
+
+ public string ActionLink(string linkText, string actionName, Hash values)
+ {
+ return _helper.ActionLink(linkText, actionName, values.ToRouteDictionary());
+ }
+
+ public string ActionLink(string linkText, string actionName, string controllerName)
+ {
+ return _helper.ActionLink(linkText, actionName, controllerName);
+ }
+
+ public string ActionLink(string linkText, string actionName)
+ {
+ return _helper.ActionLink(linkText, actionName);
+ }
+
+ public string ActionLink(string linkText, string actionName, Hash routeValues, Hash htmlAttributes)
+ {
+ return _helper.ActionLink(linkText, actionName, routeValues.ToRouteDictionary(), htmlAttributes.ToDictionary());
+ }
+
+ public string ActionLink(string linkText, string actionName, string controllerName, Hash routeValues, Hash htmlAttributes)
+ {
+ return _helper.ActionLink(linkText, actionName, controllerName, routeValues.ToRouteDictionary(), htmlAttributes.ToDictionary());
+ }
+
+
+ public string ActionLink(string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, Hash routeValues, Hash htmlAttributes)
+ {
+ return _helper.ActionLink(linkText, actionName, controllerName, protocol, hostName, fragment, routeValues.ToRouteDictionary(), htmlAttributes.ToDictionary());
+ }
+
+ public string RouteLink(string linkText, Hash routeValues)
+ {
+ return _helper.RouteLink(linkText, routeValues.ToRouteDictionary());
+ }
+
+ public string RouteLink(string linkText, string routeName, Hash routeValues)
+ {
+ return _helper.RouteLink(linkText, routeName, routeValues.ToRouteDictionary());
+ }
+
+ public string RouteLink(string linkText, Hash routeValues, Hash htmlAttributes)
+ {
+ return _helper.RouteLink(linkText, routeValues.ToRouteDictionary(), htmlAttributes.ToDictionary());
+ }
+
+ public string RouteLink(string linkText, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
+ {
+ return _helper.RouteLink(linkText, null /* routeName */, routeValues, htmlAttributes);
+ }
+
+ public string RouteLink(string linkText, string routeName, Hash routeValues, Hash htmlAttributes)
+ {
+ return _helper.RouteLink(linkText, routeName, routeValues.ToRouteDictionary(), htmlAttributes.ToDictionary());
+ }
+
+
+ public string RouteLink(string linkText, string routeName, string protocol, string hostName, string fragment, Hash routeValues, Hash htmlAttributes)
+ {
+ return _helper.RouteLink(linkText, routeName, protocol, hostName, fragment, routeValues.ToRouteDictionary(), htmlAttributes.ToDictionary());
+ }
+ }
+}
@@ -0,0 +1,58 @@
+#region Usings
+
+using System.Web.Mvc.Html;
+using System.Web.Mvc.IronRuby.Extensions;
+using IronRuby.Builtins;
+
+#endregion
+
+namespace System.Web.Mvc.IronRuby.Helpers
+{
+ public partial class RubyHtmlHelper
+ {
+ public string DropDownList(string name, string optionLabel)
+ {
+ return _helper.DropDownList(name, optionLabel);
+ }
+
+ public string DropDownList(string name, RubyArray selectList, string optionLabel)
+ {
+ return _helper.DropDownList(name, selectList.ToSelectListItemList(), optionLabel);
+ }
+
+ public string DropDownList(string name, RubyArray selectList, string optionLabel, Hash htmlAttributes)
+ {
+ return _helper.DropDownList(name, selectList.ToSelectListItemList(), optionLabel, htmlAttributes.ToDictionary());
+ }
+
+ public string DropDownList(string name)
+ {
+ return _helper.DropDownList(name);
+ }
+
+ public string DropDownList(string name, RubyArray selectList)
+ {
+ return _helper.DropDownList(name, selectList.ToSelectListItemList());
+ }
+
+ public string DropDownList(string name, RubyArray selectList, Hash htmlAttributes)
+ {
+ return _helper.DropDownList(name, selectList.ToSelectListItemList(), htmlAttributes.ToDictionary());
+ }
+
+ public string ListBox(string name)
+ {
+ return _helper.ListBox(name);
+ }
+
+ public string ListBox(string name, RubyArray selectList)
+ {
+ return _helper.ListBox(name, selectList.ToSelectListItemList());
+ }
+
+ public string ListBox(string name, RubyArray selectList, Hash htmlAttributes)
+ {
+ return _helper.ListBox(name, selectList.ToSelectListItemList(), htmlAttributes.ToDictionary());
+ }
+ }
+}

0 comments on commit 9aab80d

Please sign in to comment.