Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Pulled output determination from FubuRegistry into its own subexpression

Allows extension methods to hang off of OutputDeterminationExpression for custom output types
  • Loading branch information...
commit c3e80097114a46b981048a277e80154e52cf2abd 1 parent 2f50b6f
@joshuaflanagan authored
View
5 changelog.txt
@@ -6,4 +6,7 @@ IViewAttachmentStrategy.Find renamed to IViewsForActionFilter.Apply
FubuRegistry.Apply renamed to FubuRegistry.ApplyConvention
FubuRegistry.Urls renamed to FubuRegistry.UrlRegistry
-IUrlsCategoryConvention renamed to IUrlRegistrationConvention
+IUrlsCategoryConvention renamed to IUrlRegistrationConvention
+
+FubuRegistry.HtmlOuputIf, JsonOutputIf moved to FubuRegistry.Output.ToHtml, .ToJson
+FubuRegistry.OutputIs moved to FubuRegistry.Output.To
View
1  src/FubuMVC.Core/FubuMVC.Core.csproj
@@ -113,6 +113,7 @@
<Compile Include="Models\MapFromWebPathFamily.cs" />
<Compile Include="Models\ModelBindingAttributes.cs" />
<Compile Include="Models\ResolveConnectionStringFamily.cs" />
+ <Compile Include="OutputDeterminationExpression.cs" />
<Compile Include="Registration\Conventions\ContinuationHandlerConvention.cs" />
<Compile Include="Registration\Conventions\RouteConstraintPolicy.cs" />
<Compile Include="Registration\DSL\ModelsExpression.cs" />
View
47 src/FubuMVC.Core/FubuRegistry.Expressions.cs
@@ -3,9 +3,7 @@
using FubuMVC.Core.Diagnostics;
using FubuMVC.Core.Models;
using FubuMVC.Core.Registration;
-using FubuMVC.Core.Registration.Conventions;
using FubuMVC.Core.Registration.DSL;
-using FubuMVC.Core.Registration.Nodes;
using FubuMVC.Core.Runtime;
using FubuMVC.Core.Security;
using FubuMVC.Core.SessionState;
@@ -24,19 +22,7 @@ public interface IRegistryModification
public partial class FubuRegistry
{
public RouteConventionExpression Routes { get { return new RouteConventionExpression(_routeResolver, this); } }
- public ActionCallFilterExpression JsonOutputIf { get { return output(call => call.OutputToJson()); } }
-
- public ActionCallFilterExpression HtmlOutputIf
- {
- get
- {
- return output(call => call.Append(new RenderTextNode<string>
- {
- MimeType = MimeType.Html
- }));
- }
- }
-
+ public OutputDeterminationExpression Output { get{ return new OutputDeterminationExpression(this);}}
public ViewExpression Views { get { return new ViewExpression(_viewAttacher); } }
public UrlRegistryExpression UrlRegistry { get { return new UrlRegistryExpression(convention => _urlConventions.Add(convention), _urls); } }
@@ -59,36 +45,11 @@ public void ApplyConvention<TConvention>()
}
public void ApplyConvention<TConvention>(TConvention convention)
- where TConvention : IConfigurationAction, new()
+ where TConvention : IConfigurationAction
{
_conventions.Add(convention);
}
- private ActionCallFilterExpression output(Action<ActionCall> configure)
- {
- var modification = new ActionCallModification(configure);
- _conventions.Add(modification);
-
- modification.Filters.Excludes += call => call.HasOutputBehavior();
-
- return new ActionCallFilterExpression(modification.Filters);
- }
-
- public ActionCallFilterExpression OutputIs(Func<ActionCall, OutputNode> func)
- {
- return output(action =>
- {
- OutputNode node = func(action);
- action.Append(node);
- });
- }
-
- public ActionCallFilterExpression OutputIs<T>() where T : OutputNode, new()
- {
- return output(action => action.Append(new T()));
- }
-
-
public ChainedBehaviorExpression HomeIs()
{
return Route(string.Empty);
@@ -164,8 +125,6 @@ private void setupServices(BehaviorGraph graph)
graph.Services.SetServiceIfNone<IViewActivator, NulloViewActivator>();
}
- #region Nested type: RegistryImport
-
public class RegistryImport
{
public string Prefix { get; set; }
@@ -176,7 +135,5 @@ public void ImportInto(BehaviorGraph graph)
graph.Import(Registry.BuildGraph(), Prefix);
}
}
-
- #endregion
}
}
View
8 src/FubuMVC.Core/FubuRegistry.cs
@@ -47,11 +47,11 @@ public FubuRegistry()
Policies.Add<WebFormsEndpointPolicy>();
Policies.Add<ContinuationHandlerConvention>();
- HtmlOutputIf.CallMatches(x => x.Method.HasCustomAttribute<HtmlEndpointAttribute>());
- JsonOutputIf.CallMatches(x => x.Method.HasCustomAttribute<JsonEndpointAttribute>());
+ Output.ToHtml.WhenCallMatches(x => x.Method.HasCustomAttribute<HtmlEndpointAttribute>());
+ Output.ToJson.WhenCallMatches(x => x.Method.HasCustomAttribute<JsonEndpointAttribute>());
- OutputIs<RenderHtmlDocumentNode>().WhenTheOutputModelIs<HtmlDocument>();
- OutputIs<RenderHtmlTagNode>().WhenTheOutputModelIs<HtmlTag>();
+ Output.To<RenderHtmlDocumentNode>().WhenTheOutputModelIs<HtmlDocument>();
+ Output.To<RenderHtmlTagNode>().WhenTheOutputModelIs<HtmlTag>();
_conventions.Add(_viewAttacher);
}
View
55 src/FubuMVC.Core/OutputDeterminationExpression.cs
@@ -0,0 +1,55 @@
+using System;
+using FubuMVC.Core.Registration.Conventions;
+using FubuMVC.Core.Registration.DSL;
+using FubuMVC.Core.Registration.Nodes;
+using FubuMVC.Core.Runtime;
+
+namespace FubuMVC.Core
+{
+ public class OutputDeterminationExpression
+ {
+ private readonly FubuRegistry _registry;
+
+ public OutputDeterminationExpression(FubuRegistry registry)
+ {
+ _registry = registry;
+ }
+
+ public ActionCallFilterExpression ToJson { get { return output(call => call.Append(new RenderJsonNode(call.OutputType()))); } }
+
+ public ActionCallFilterExpression ToHtml
+ {
+ get
+ {
+ return output(call => call.Append(new RenderTextNode<string>
+ {
+ MimeType = MimeType.Html
+ }));
+ }
+ }
+
+ public ActionCallFilterExpression To(Func<ActionCall, OutputNode> func)
+ {
+ return output(action =>
+ {
+ OutputNode node = func(action);
+ action.Append(node);
+ });
+ }
+
+ public ActionCallFilterExpression To<T>() where T : OutputNode, new()
+ {
+ return output(action => action.Append(new T()));
+ }
+
+ private ActionCallFilterExpression output(Action<ActionCall> configure)
+ {
+ var modification = new ActionCallModification(configure);
+ _registry.ApplyConvention(modification);
+
+ modification.Filters.Excludes += call => call.HasOutputBehavior();
+
+ return new ActionCallFilterExpression(modification.Filters);
+ }
+ }
+}
View
4 src/FubuMVC.Core/Registration/DSL/ActionCallFilterExpression.cs
@@ -15,10 +15,10 @@ public ActionCallFilterExpression(CompositeFilter<ActionCall> filter)
public ActionCallFilterExpression WhenTheOutputModelIs<T>()
{
- return CallMatches(call => call.OutputType().CanBeCastTo<T>());
+ return WhenCallMatches(call => call.OutputType().CanBeCastTo<T>());
}
- public ActionCallFilterExpression CallMatches(Func<ActionCall, bool> func)
+ public ActionCallFilterExpression WhenCallMatches(Func<ActionCall, bool> func)
{
_filter.Includes += func;
View
7 src/FubuMVC.Core/Registration/Nodes/ActionCall.cs
@@ -148,12 +148,5 @@ public override int GetHashCode()
(Method != null ? Method.GetHashCode() : 0);
}
}
-
- public void OutputToJson()
- {
- // TODO -- throw exception if this is called and there is no output
- var json = new RenderJsonNode(OutputType());
- Append(json);
- }
}
}
View
2  src/FubuMVC.Tests/Registration/ActionCallTester.cs
@@ -29,7 +29,7 @@ public void SetUp()
public void append_json()
{
action = ActionCall.For<ControllerTarget>(x => x.OneInOneOut(null));
- action.OutputToJson();
+ action.Append(new RenderJsonNode(action.OutputType()));
action.Next.ShouldBeOfType<RenderJsonNode>().ModelType.ShouldEqual(action.OutputType());
}
View
8 src/FubuMVC.Tests/Registration/Conventions/OutputIntegratedAttachmentTester.cs
@@ -12,8 +12,6 @@ namespace FubuMVC.Tests.Registration.Conventions
[TestFixture]
public class OutputIntegratedAttachmentTester
{
- #region Setup/Teardown
-
[SetUp]
public void SetUp()
{
@@ -22,15 +20,13 @@ public void SetUp()
x.Applies.ToThisAssembly();
x.Actions.IncludeTypesImplementing<JsonOutputAttachmentTesterController>();
- x.HtmlOutputIf.CallMatches(
+ x.Output.ToHtml.WhenCallMatches(
call => call.OutputType() == typeof (string) && call.Method.Name.ToLower().Contains("html"));
- x.JsonOutputIf.WhenTheOutputModelIs<CrudReport>().WhenTheOutputModelIs<ContinuationClass>();
+ x.Output.ToJson.WhenTheOutputModelIs<CrudReport>().WhenTheOutputModelIs<ContinuationClass>();
})
.BuildGraph();
}
- #endregion
-
private BehaviorGraph graph;
[Test]
View
2  src/FubuMVC.Tests/Registration/Expressions/ActionCallFilterExpressionTester.cs
@@ -29,7 +29,7 @@ public void SetUp()
[Test]
public void specify_a_filter_by_action_call()
{
- expression.CallMatches(call => call == action1);
+ expression.WhenCallMatches(call => call == action1);
filter.Matches(action1).ShouldBeTrue();
filter.Matches(action2).ShouldBeFalse();
}
Please sign in to comment.
Something went wrong with that request. Please try again.