Skip to content

Commit

Permalink
finished removing the profiled views. Closes GH-907
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Aug 24, 2015
1 parent e0edb2c commit b468c2b
Show file tree
Hide file tree
Showing 16 changed files with 14 additions and 357 deletions.
6 changes: 0 additions & 6 deletions src/FubuMVC.Core/FubuMVC.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,6 @@
<Compile Include="Http\Owin\Readers\OwinRequestReader.cs" />
<Compile Include="Services\JasperServiceConfiguration.cs" />
<Compile Include="Services\JasperServiceRuntime.cs" />
<Compile Include="View\Attachment\ProfileViewBag.cs" />
<Compile Include="View\ImageTag.cs" />
<Compile Include="Runtime\IFubuRequestContext.cs" />
<Compile Include="Projections\AccessorProjection.cs" />
Expand Down Expand Up @@ -1074,12 +1073,7 @@
<Compile Include="Urls\IUrlRegistry.cs" />
<Compile Include="Security\Authorization\IAuthenticationContext.cs" />
<Compile Include="Security\Authorization\ISecurityContext.cs" />
<Compile Include="View\Attachment\DefaultProfile.cs" />
<Compile Include="View\Attachment\IViewProfile.cs" />
<Compile Include="View\Attachment\ProfileViewToken.cs" />
<Compile Include="View\Attachment\ViewBag.cs" />
<Compile Include="View\Attachment\ViewProfile.cs" />
<Compile Include="View\Attachment\ViewTokenExtensions.cs" />
<Compile Include="View\AutoImportModelNamespacesConvention.cs" />
<Compile Include="View\CommonViewNamespaces.cs" />
<Compile Include="View\IFubuView.cs" />
Expand Down
9 changes: 5 additions & 4 deletions src/FubuMVC.Core/Http/ConnegSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using FubuMVC.Core.Resources.Conneg;
using FubuMVC.Core.Runtime;
using FubuMVC.Core.Runtime.Formatters;
using FubuMVC.Core.View;
using FubuMVC.Core.View.Attachment;

namespace FubuMVC.Core.Http
Expand Down Expand Up @@ -50,7 +51,7 @@ public void ReadConnegGraph(BehaviorGraph graph)
_graph = ConnegGraph.Build(graph);
}

public void StoreViews(Task<IEnumerable<ProfileViewBag>> views)
public void StoreViews(Task<ViewBag> views)
{
_views = views;
}
Expand All @@ -67,11 +68,11 @@ public ConnegGraph Graph
}
}

public IEnumerable<ProfileViewBag> Views
public ViewBag Views
{
get
{
if (_views == null) return Enumerable.Empty<ProfileViewBag>();
if (_views == null) return new ViewBag(Enumerable.Empty<IViewToken>());

_views.Wait(5.Seconds());
return _views.Result;
Expand Down Expand Up @@ -103,7 +104,7 @@ public void ApplyRules(OutputNode node)

public readonly IList<IMimetypeCorrection> Corrections = new List<IMimetypeCorrection>();
private Task<ConnegGraph> _graph;
private Task<IEnumerable<ProfileViewBag>> _views;
private Task<ViewBag> _views;

public void InterpretQuerystring(CurrentMimeType mimeType, IHttpRequest request)
{
Expand Down
8 changes: 2 additions & 6 deletions src/FubuMVC.Core/Registration/BehaviorGraphBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,9 @@ private static void applySettings(ConfigGraph config, BehaviorGraph graph, IActi
config.Settings.Each(x => x.Alter(graph.Settings));

var viewSettings = graph.Settings.Get<ViewEngineSettings>();


var views = viewSettings.BuildViewBag(graph, diagnostics, files)
.ContinueWith(t =>
{
return viewSettings.Profiles(t.Result);
});

var views = viewSettings.BuildViewBag(graph, diagnostics, files);

var conneg = graph.Settings.Get<ConnegSettings>();

Expand Down
18 changes: 6 additions & 12 deletions src/FubuMVC.Core/Resources/Conneg/ViewAttachment.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using FubuMVC.Core.Http;
using FubuMVC.Core.Registration.Nodes;

Expand All @@ -9,19 +8,14 @@ public class ViewAttachment : ConnegRule
{
protected override DoNext applyOutputs(IOutputNode node, BehaviorChain chain, ConnegSettings settings)
{
var profileViewBags = settings.Views;
profileViewBags.Each(profile =>
var candidates = settings.Views.Where(x => x.ViewModel == node.ResourceType).ToArray();
if (candidates.Count() == 1)
{
var candidates = profile.Views.Where(x => x.ViewModel == node.ResourceType).ToArray();
if (candidates.Count() == 1)
if (!node.HasView())
{
if (!node.HasView())
{
node.AddView(candidates.Single());
}
node.AddView(candidates.Single());
}
});

}

return DoNext.Continue;
}
Expand Down
21 changes: 0 additions & 21 deletions src/FubuMVC.Core/View/Attachment/DefaultProfile.cs

This file was deleted.

10 changes: 0 additions & 10 deletions src/FubuMVC.Core/View/Attachment/IViewProfile.cs

This file was deleted.

18 changes: 0 additions & 18 deletions src/FubuMVC.Core/View/Attachment/ProfileViewBag.cs

This file was deleted.

54 changes: 0 additions & 54 deletions src/FubuMVC.Core/View/Attachment/ProfileViewToken.cs

This file was deleted.

32 changes: 0 additions & 32 deletions src/FubuMVC.Core/View/Attachment/ViewProfile.cs

This file was deleted.

17 changes: 0 additions & 17 deletions src/FubuMVC.Core/View/Attachment/ViewTokenExtensions.cs

This file was deleted.

63 changes: 0 additions & 63 deletions src/FubuMVC.Core/View/ViewEngineSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,70 +149,7 @@ public bool FolderShouldBeIgnored(string folder)
}


private readonly IList<Func<IViewToken, bool>> _defaultExcludes = new List<Func<IViewToken, bool>>();
private readonly IList<IViewProfile> _profiles = new List<IViewProfile>();


public IEnumerable<ProfileViewBag> Profiles(ViewBag views)
{
if (_profiles.Any())
{
foreach (var profile in _profiles)
{
yield return new ProfileViewBag(profile, views);
}

Func<IViewToken, bool> defaultFilter = x => !_defaultExcludes.Any(test => test(x));
var defaultProfile = new ViewProfile(Always.Flyweight, defaultFilter, x => x.Name());

yield return new ProfileViewBag(defaultProfile, views);
}
else
{
yield return new ProfileViewBag(new DefaultProfile(), views);
}
}

/// <summary>
/// Create an attachment profile based on a runtime condition. The original intent of view profiles
/// was to enable multiple views per action based on the detected device of the user (desktop, tablet, smartphone),
/// but is not limited to that functionality
/// </summary>
/// <param name="condition"></param>
/// <param name="filter"></param>
/// <param name="nameCorrection"></param>
/// <returns></returns>
public IViewProfile Profile(IConditional condition, Func<IViewToken, bool> filter,
Func<IViewToken, string> nameCorrection)
{
_defaultExcludes.Add(filter);
var profile = new ViewProfile(condition, filter, nameCorrection);
_profiles.Add(profile);

return profile;
}


/// <summary>
/// This creates a view profile for the view attachment. Used for scenarios like
/// attaching multiple views to the same chain for different devices.
/// </summary>
/// <typeparam name = "T"></typeparam>
/// <param name = "prefix"></param>
/// <example>
/// Profile<IsMobile>("m.") -- where "m" would mean look for views that are named "m.something"
/// </example>
/// <returns></returns>
public void Profile<T>(string prefix) where T : IConditional, new()
{
Func<IViewToken, string> naming = view =>
{
var name = view.Name();
return name.Substring(prefix.Length);
};

Profile(new T(), x => x.Name().StartsWith(prefix), naming);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public void FixtureSetUp()

_views = new Lazy<ViewBag>(() =>
{
var allViews = _host.Get<ConnegSettings>().Views.SelectMany(x => x.Views);
return new ViewBag(allViews);
return _host.Get<ConnegSettings>().Views;
});
}

Expand Down
3 changes: 0 additions & 3 deletions src/FubuMVC.Tests/FubuMVC.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,7 @@
<Compile Include="Urls\BasicUrlRegistrationScanningIntegrationTester.cs" />
<Compile Include="Urls\ChainUrlResolverTester.cs" />
<Compile Include="Urls\UrlRegistryIntegrationTester.cs" />
<Compile Include="View\Attachment\DefaultProfileTester.cs" />
<Compile Include="View\Attachment\ProfileViewTokenTester.cs" />
<Compile Include="View\Attachment\ViewExclusionTester.cs" />
<Compile Include="View\Attachment\ViewTokenExtensionsTester.cs" />
<Compile Include="View\AutoImportModelNamespacesConventionTester.cs" />
<Compile Include="View\CommonViewNamespaces_is_registered.cs" />
<Compile Include="View\FakeViews\Folder1\A.aspx.cs">
Expand Down
Loading

0 comments on commit b468c2b

Please sign in to comment.