Permalink
Browse files

Added debug assemblies for System.Web.Mvc fixed an issue with method …

…selectors
  • Loading branch information...
1 parent 57cfa96 commit 9ec66d034f2d3ef66fe6ecc92e8aafc0f9aec1a8 @casualjim casualjim committed Mar 24, 2009
@@ -1,4 +1,5 @@
-<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -48,15 +49,15 @@
<ItemGroup>
<Reference Include="IronRuby, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\..\Users\jimmysch\dev\ironrubymvc\dependencies\IronRuby.dll</HintPath>
+ <HintPath>..\dependencies\IronRuby.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Scripting, Version=0.9.5.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\..\Users\jimmysch\dev\ironrubymvc\dependencies\Microsoft.Scripting.dll</HintPath>
+ <HintPath>..\dependencies\Microsoft.Scripting.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Scripting.Core, Version=0.9.5.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\..\Users\jimmysch\dev\ironrubymvc\dependencies\Microsoft.Scripting.Core.dll</HintPath>
+ <HintPath>..\dependencies\Microsoft.Scripting.Core.dll</HintPath>
<Aliases>dlr</Aliases>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
@@ -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<ControllerContext, string, TResult> ConvertProcToFunc<TResult>(Proc proc)
@@ -105,7 +105,7 @@ public ActionResult RedirectToRoute(Hash values)
[NonAction]
public ActionResult RedirectToAction(string actionName, Hash values)
- {
+ {
return RedirectToAction(actionName, values.ToRouteDictionary());
}
@@ -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
@@ -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);
}
/// <summary>
@@ -79,11 +79,18 @@
<Reference Include="System.configuration" />
<Reference Include="System.Web" />
<Reference Include="System.Data" />
- <Reference Include="System.Web.Abstractions">
+ <Reference Include="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\dependencies\System.Web.Abstractions.dll</HintPath>
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
- <Reference Include="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
- <Reference Include="System.Web.Routing">
+ <Reference Include="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\dependencies\System.Web.Mvc.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\dependencies\System.Web.Routing.dll</HintPath>
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
@@ -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<br />")
end
@@ -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
Oops, something went wrong.

0 comments on commit 9ec66d0

Please sign in to comment.