diff --git a/IronRubyMvc.Tests/IronRubyMvcLibrary.Tests.csproj b/IronRubyMvc.Tests/IronRubyMvcLibrary.Tests.csproj index f321a30..1d3b57d 100644 --- a/IronRubyMvc.Tests/IronRubyMvcLibrary.Tests.csproj +++ b/IronRubyMvc.Tests/IronRubyMvcLibrary.Tests.csproj @@ -1,4 +1,5 @@ - + + Debug AnyCPU @@ -48,15 +49,15 @@ False - ..\..\..\Users\jimmysch\dev\ironrubymvc\dependencies\IronRuby.dll + ..\dependencies\IronRuby.dll False - ..\..\..\Users\jimmysch\dev\ironrubymvc\dependencies\Microsoft.Scripting.dll + ..\dependencies\Microsoft.Scripting.dll False - ..\..\..\Users\jimmysch\dev\ironrubymvc\dependencies\Microsoft.Scripting.Core.dll + ..\dependencies\Microsoft.Scripting.Core.dll dlr diff --git a/IronRubyMvc/Controllers/RubyActionMethodSelector.cs b/IronRubyMvc/Controllers/RubyActionMethodSelector.cs index 46f42e7..5bcddb7 100644 --- a/IronRubyMvc/Controllers/RubyActionMethodSelector.cs +++ b/IronRubyMvc/Controllers/RubyActionMethodSelector.cs @@ -144,7 +144,23 @@ public bool IsValid(ControllerContext context, string name) public bool IsValidForAction(ControllerContext context, string name) { - return _predicates.Any(predicate => predicate(context, name.Underscore())|| predicate(context, name.Pascalize())); + var result = false; + foreach (var list in _predicates) + { + if(list(context, name)) + { + result = true; + break; + } + } + return result; +// var result = _predicates.Any(predicate => +// { +// var result1 = predicate(context, name.Underscore()); +// var result2 = predicate(context, name.Pascalize()); +// return result1 || result2; +// }); +// return result; } public Func ConvertProcToFunc(Proc proc) diff --git a/IronRubyMvc/Controllers/RubyController.cs b/IronRubyMvc/Controllers/RubyController.cs index f6ce9ba..4166092 100644 --- a/IronRubyMvc/Controllers/RubyController.cs +++ b/IronRubyMvc/Controllers/RubyController.cs @@ -105,7 +105,7 @@ public ActionResult RedirectToRoute(Hash values) [NonAction] public ActionResult RedirectToAction(string actionName, Hash values) - { + { return RedirectToAction(actionName, values.ToRouteDictionary()); } diff --git a/IronRubyMvc/Controllers/controller.rb b/IronRubyMvc/Controllers/controller.rb index b3844d3..ad8b47f 100644 --- a/IronRubyMvc/Controllers/controller.rb +++ b/IronRubyMvc/Controllers/controller.rb @@ -1,3 +1,8 @@ +def debugger + require 'mscorlib' + System::Diagnostics::Debugger.break +end + module IronRubyMvc module Controllers @@ -15,6 +20,7 @@ def initialize(before_action=nil, after_action=nil) end def on_action_executing(context) + debugger before_action.call(context) unless before_action.nil? end diff --git a/IronRubyMvc/Core/RubyEngine.cs b/IronRubyMvc/Core/RubyEngine.cs index 4646670..e6acf1a 100644 --- a/IronRubyMvc/Core/RubyEngine.cs +++ b/IronRubyMvc/Core/RubyEngine.cs @@ -5,6 +5,7 @@ using System.IO; using System.Reflection; using System.Text; +using System.Web.Hosting; using System.Web.Mvc.IronRuby.Controllers; using System.Web.Mvc.IronRuby.Extensions; using System.Web.Mvc.IronRuby.ViewEngine; @@ -269,7 +270,10 @@ private void Initialize() private void RequireControllerFile() { - RequireRubyFile(Constants.RUBYCONTROLLER_FILE, ReaderType.AssemblyResource); +// Engine.RequireRubyFile(@"C:\tools\ironruby\ironrubymvc\IronRubyMvc\Controllers\controller.rb"); +// RequireRubyFile("~/Controllers/controller.rb", ReaderType.File); + Engine.RequireRubyFile(HostingEnvironment.MapPath("~/Controllers/controller.rb")); +// RequireRubyFile(Constants.RUBYCONTROLLER_FILE, ReaderType.AssemblyResource); } /// diff --git a/IronRubyMvc/System.Web.Mvc.IronRuby.csproj b/IronRubyMvc/System.Web.Mvc.IronRuby.csproj index 17c7a2d..e4ef50f 100644 --- a/IronRubyMvc/System.Web.Mvc.IronRuby.csproj +++ b/IronRubyMvc/System.Web.Mvc.IronRuby.csproj @@ -79,11 +79,18 @@ - + + False + ..\dependencies\System.Web.Abstractions.dll 3.5 - - + + False + ..\dependencies\System.Web.Mvc.dll + + + False + ..\dependencies\System.Web.Routing.dll 3.5 diff --git a/IronRubyMvcWeb/Controllers/HomeController.rb b/IronRubyMvcWeb/Controllers/HomeController.rb index 1fdbbaa..a8870da 100644 --- a/IronRubyMvcWeb/Controllers/HomeController.rb +++ b/IronRubyMvcWeb/Controllers/HomeController.rb @@ -44,6 +44,14 @@ def raise_error raise "This is supposed to happen" end + def validation + view + end + + def validate + view 'validation' + end + def method_filter(context) context.request_context.http_context.response.write("From method filter
") end diff --git a/IronRubyMvcWeb/Controllers/controller.rb b/IronRubyMvcWeb/Controllers/controller.rb new file mode 100644 index 0000000..ac08834 --- /dev/null +++ b/IronRubyMvcWeb/Controllers/controller.rb @@ -0,0 +1,255 @@ +def debugger + System::Diagnostics::Debugger.break if System::Diagnostics::Debugger.launch +end + +module IronRubyMvc + + module Controllers + + module Filters + + class RubyProcActionFilter < System::Web::Mvc::IronRuby::Controllers::RubyActionFilter + + attr_accessor :before_action, :after_action + + def initialize(before_action=nil, after_action=nil) + raise ArgumentError.new("You need to provide either a before or an after action") if before_action.nil? && after_action.nil? + @before_action = before_action + @after_action = after_action + end + + def on_action_executing(context) + before_action.call(context) unless before_action.nil? + end + + def on_action_executed(context) + after_action.call(context) unless after_action.nil? + end + end + + class RubyProcAuthorizationFilter < System::Web::Mvc::IronRuby::Controllers::RubyAuthorizationFilter + + attr_accessor :authorize + + def initialize(authorize) + @authorize = authorize + end + + def on_authorization(context) + authorize.call(context) + end + + end + + class RubyProcExceptionFilter < System::Web::Mvc::IronRuby::Controllers::RubyExceptionFilter + + attr_accessor :on_exception + + def initialize(on_exception) + @on_exception = on_exception + end + + def on_exception(context) + on_exception.call(context) + end + + end + + class RubyProcResultFilter < System::Web::Mvc::IronRuby::Controllers::RubyResultFilter + + attr_accessor :before_result, :after_result + + def initialize(before_result = nil, after_result=nil) + @before_result = before_result + @after_result = after_result + end + + def on_result_executing(context) + before_result.call(context) unless before_result.nil? + end + + def on_result_executed(context) + after_result.call(context) unless after_result.nil? + end + end + + module ClassMethods + + def before_action(name, method_name=nil, &b) + impl = create_from_name(method_name) if method_name.is_a?(Symbol) or method_name.is_a?(String) + filter(name, RubyProcActionFilter.new(impl || b, nil)) + end + + def after_action(name, method_name=nil, &b) + impl = create_from_name(method_name) if method_name.is_a?(Symbol) or method_name.is_a?(String) + filter(name, RubyProcActionFilter.new(nil, impl || b)) + end + + def around_action(name, options={}, &b) + options[:before] ||= b if block_given? + options[:after] ||= b if block_given? + options[:before] ||= create_from_name(options[:before]) if options[:before].is_a?(Symbol) or options[:before].is_a?(String) + options[:after] ||= create_from_name(options[:after]) if options[:after].is_a?(Symbol) or options[:after].is_a?(String) + filter(name, RubyProcActionFilter.new(options[:before], options[:after])) + end + + def authorized_action(name, method_name=nil, &b) + impl = create_from_name(method_name) if method_name.is_a?(Symbol) or method_name.is_a?(String) + filter(name, RubyProcAuthorizationFilter.new(impl || b)) + end + + def exception_action(name, method_name=nil, &b) + impl = create_from_name(method_name) if method_name.is_a?(Symbol) or method_name.is_a?(String) + filter(name, RubyProcExceptionFilter.new(b)) + end + + def before_result(name, method_name=nil, options={}, &b) + impl = create_from_name(method_name) if method_name.is_a?(Symbol) or method_name.is_a?(String) + filter(name, RubyProcResultFilter.new(b)) + end + + def after_result(name, method_name=nil, options={}, &b) + impl = create_from_name(method_name) if method_name.is_a?(Symbol) or method_name.is_a?(String) + filter(name, RubyProcResultFilter.new(nil, b)) + end + + def around_result(name, method_name=nil, options={}, &b) + options[:before] ||= b if block_given? + options[:after] ||= b if block_given? + options[:before] ||= create_from_name(options[:before]) if options[:before].is_a?(Symbol) or options[:before].is_a?(String) + options[:after] ||= create_from_name(options[:after]) if options[:after].is_a?(Symbol) or options[:after].is_a?(String) + filter(name, RubyProcResultFilter.new(options[:before], options[:after])) + end + + def filter(name, options=nil) + @action_filters ||= {} + klass = nil + klass = name.new if name.is_a? Class + klass = options.new if options.is_a? Class + klass = Object.const_get(options.to_s.split('_').map {|word| word = word.capitalize }.join('')) if options.is_a?(Symbol) or options.is_a?(String) + klass ||= options + name = :controller if name.nil? or name.is_a?(Class) + @action_filters[name.to_sym] ||= [] + @action_filters[name.to_sym] << klass + end + + def action_filters + @action_filters ||= {} + @action_filters + end + + private + def create_from_name(name) + lambda {|context| context.controller.send(name.to_sym, context) } + end + + end + + def self.included(base) + base.extend(ClassMethods) + end + + end + + module Selectors + + module ClassMethods + + def method_selector(name, selector) + key = name.to_s.to_sym + method_selectors[key] ||= [] + method_selectors[key] << selector unless selector.nil? + method_selectors[key].uniq! + method_selectors[key] + end + + def alias_action(name, act_name) + fn = Proc.new do |controller_context, action_name| + !!/^#{action_name.to_s}$/i.match(act_name.to_s) + end + name_selector(name, fn) + end + + def name_selector(name, selector) + key = name.to_s.to_sym + name_selectors[key] ||= [] + name_selectors[key] << selector if block_given? + name_selectors[key].uniq! + name_selectors[key] + end + + def non_action(name) + fn = lambda { |context, action_name| return false } + method_selector name, fn + end + + def name_selectors + @name_selectors ||= {} + @name_selectors + end + + def method_selectors + @method_selectors ||= {} + @method_selectors + end + + end + + def self.included(base) + base.extend(ClassMethods) + end + + module AcceptVerbs + + module ClassMethods + + def accept_verbs(name, *verbs) + fn = lambda { |context, action_name| + return verbs.include?(context.http_context.request.http_method.to_s.downcase.to_sym) + } + method_selector(name, fn) + end + + end + + def self.included(base) + base.extend(ClassMethods) + end + end + end + + + + end + + #module Controllers + + class Controller < System::Web::Mvc::IronRuby::Controllers::RubyController + + + include Controllers::Filters + include Controllers::Selectors + include Controllers::Selectors::AcceptVerbs + + 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 + + #end + + + +end + +#alias longer namespaces for convenience +Controller = IronRubyMvc::Controller +ActionFilter = System::Web::Mvc::IronRuby::Controllers::RubyActionFilter +AuthorizationFilter = System::Web::Mvc::IronRuby::Controllers::RubyAuthorizationFilter +ExceptionFilter = System::Web::Mvc::IronRuby::Controllers::RubyExceptionFilter +ResultFilter = System::Web::Mvc::IronRuby::Controllers::RubyResultFilter \ No newline at end of file diff --git a/IronRubyMvcWeb/IronRubyMvcWeb.csproj b/IronRubyMvcWeb/IronRubyMvcWeb.csproj index 4adf449..7b355dc 100644 --- a/IronRubyMvcWeb/IronRubyMvcWeb.csproj +++ b/IronRubyMvcWeb/IronRubyMvcWeb.csproj @@ -64,8 +64,13 @@ ..\dependencies\System.Web.Abstractions.dll 3.5
- - + + False + ..\dependencies\System.Web.Mvc.dll + + + False + ..\dependencies\System.Web.Routing.dll 3.5 @@ -127,6 +132,7 @@ + @@ -136,6 +142,7 @@ + diff --git a/IronRubyMvcWeb/Views/Home/Validation.aspx b/IronRubyMvcWeb/Views/Home/Validation.aspx new file mode 100644 index 0000000..33a75cb --- /dev/null +++ b/IronRubyMvcWeb/Views/Home/Validation.aspx @@ -0,0 +1,19 @@ +<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %> +<%@ Import Namespace="System.Web.Mvc.Html"%> + + + + + + Validation + + +
+ <% Html.BeginForm("validate", "home"); %> +

Username: <%= Html.TextBox("username", ViewData["username"]) %>

+

Password: <%= Html.Password("password", ViewData["password"]) %>

+

+ <% Html.EndForm(); %> +
+ + diff --git a/IronRubyMvcWeb/Web.config b/IronRubyMvcWeb/Web.config index 1cdf12e..3005bab 100644 --- a/IronRubyMvcWeb/Web.config +++ b/IronRubyMvcWeb/Web.config @@ -38,7 +38,6 @@ - diff --git a/dependencies/System.Web.Abstractions.dll b/dependencies/System.Web.Abstractions.dll new file mode 100644 index 0000000..7f1e927 Binary files /dev/null and b/dependencies/System.Web.Abstractions.dll differ diff --git a/dependencies/System.Web.Mvc.dll b/dependencies/System.Web.Mvc.dll index 8d88deb..12e46fe 100644 Binary files a/dependencies/System.Web.Mvc.dll and b/dependencies/System.Web.Mvc.dll differ diff --git a/dependencies/System.Web.Mvc.pdb b/dependencies/System.Web.Mvc.pdb new file mode 100644 index 0000000..705e3f4 Binary files /dev/null and b/dependencies/System.Web.Mvc.pdb differ