Skip to content

Commit a7203c8

Browse files
author
richard
committed
Extend THe HTML Negotiator
* Add support for multiple view engines * Make the view locations configurable
1 parent 748b09c commit a7203c8

40 files changed

+962
-50
lines changed

.gitignore

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Created by .ignore support plugin (hsz.mobi)
2-
### VisualStudio template
31
## Ignore Visual Studio temporary files, build results, and
42
## files generated by popular Visual Studio add-ons.
53
##
@@ -26,11 +24,14 @@ bld/
2624
[Oo]bj/
2725
[Ll]og/
2826

29-
# Visual Studio 2015 cache/options directory
27+
# Visual Studio 2015/2017 cache/options directory
3028
.vs/
3129
# Uncomment if you have tasks that create the project's static files in wwwroot
3230
#wwwroot/
3331

32+
# Visual Studio 2017 auto generated files
33+
Generated\ Files/
34+
3435
# MSTest test Results
3536
[Tt]est[Rr]esult*/
3637
[Bb]uild[Ll]og.*
@@ -51,16 +52,21 @@ BenchmarkDotNet.Artifacts/
5152
project.lock.json
5253
project.fragment.lock.json
5354
artifacts/
54-
**/Properties/launchSettings.json
5555

56+
# StyleCop
57+
StyleCopReport.xml
58+
59+
# Files built by Visual Studio
5660
*_i.c
5761
*_p.c
58-
*_i.h
62+
*_h.h
5963
*.ilk
6064
*.meta
6165
*.obj
66+
*.iobj
6267
*.pch
6368
*.pdb
69+
*.ipdb
6470
*.pgc
6571
*.pgd
6672
*.rsp
@@ -214,6 +220,10 @@ ClientBin/
214220
*.publishsettings
215221
orleans.codegen.cs
216222

223+
# Including strong name files can present a security risk
224+
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
225+
#*.snk
226+
217227
# Since there are multiple workflows, uncomment next line to ignore bower_components
218228
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
219229
#bower_components/
@@ -228,6 +238,8 @@ _UpgradeReport_Files/
228238
Backup*/
229239
UpgradeLog*.XML
230240
UpgradeLog*.htm
241+
ServiceFabricBackup/
242+
*.rptproj.bak
231243

232244
# SQL Server files
233245
*.mdf
@@ -238,6 +250,7 @@ UpgradeLog*.htm
238250
*.rdl.data
239251
*.bim.layout
240252
*.bim_*.settings
253+
*.rptproj.rsuser
241254

242255
# Microsoft Fakes
243256
FakesAssemblies/
@@ -249,9 +262,6 @@ FakesAssemblies/
249262
.ntvs_analysis.dat
250263
node_modules/
251264

252-
# Typescript v1 declaration files
253-
typings/
254-
255265
# Visual Studio 6 build log
256266
*.plg
257267

@@ -306,4 +316,17 @@ __pycache__/
306316
# OpenCover UI analysis results
307317
OpenCover/
308318

319+
# Azure Stream Analytics local run output
320+
ASALocalRun/
321+
322+
# MSBuild Binary and Structured Log
323+
*.binlog
324+
325+
# NVidia Nsight GPU debugger configuration file
326+
*.nvuser
327+
328+
# MFractors (Xamarin productivity tool) working folder
329+
.mfractor/
309330

331+
# Local History for Visual Studio
332+
.localhistory/

Carter.HtmlNegotiator.sln

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26124.0
5+
MinimumVisualStudioVersion = 15.0.26124.0
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Carter.HtmlNegotiator", "src\Carter.HtmlNegotiator.csproj", "{0DBC4DD8-CC92-4C36-A6CA-ABEE717458CA}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dependencies", "dependencies", "{7B61769A-8EB6-4752-AF80-7F15558B2C76}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Carter", "Carter", "{C6E6F2C4-A88C-4E9D-9183-D3EB572423DE}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Carter", "dependencies\Carter\src\Carter.csproj", "{E5B3E5AF-CA11-42EA-A9D0-72147B457AA3}"
13+
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Carter.HtmlNegotiator.Sample", "sample\Carter.HtmlNegotiator.Sample.csproj", "{C0D65C1D-698E-4601-98D2-D0BA4E5C0F47}"
15+
EndProject
16+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{520CAA77-64DE-43BF-B173-6E1A8F3A40B9}"
17+
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HtmlNegotiator.Tests", "tests\HtmlNegotiator.Tests\HtmlNegotiator.Tests.csproj", "{A398FEB7-7F6E-4C98-9DA8-A35BE8D76C53}"
19+
EndProject
20+
Global
21+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
22+
Debug|Any CPU = Debug|Any CPU
23+
Debug|x64 = Debug|x64
24+
Debug|x86 = Debug|x86
25+
Release|Any CPU = Release|Any CPU
26+
Release|x64 = Release|x64
27+
Release|x86 = Release|x86
28+
EndGlobalSection
29+
GlobalSection(SolutionProperties) = preSolution
30+
HideSolutionNode = FALSE
31+
EndGlobalSection
32+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
33+
{0DBC4DD8-CC92-4C36-A6CA-ABEE717458CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34+
{0DBC4DD8-CC92-4C36-A6CA-ABEE717458CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
35+
{0DBC4DD8-CC92-4C36-A6CA-ABEE717458CA}.Debug|x64.ActiveCfg = Debug|Any CPU
36+
{0DBC4DD8-CC92-4C36-A6CA-ABEE717458CA}.Debug|x64.Build.0 = Debug|Any CPU
37+
{0DBC4DD8-CC92-4C36-A6CA-ABEE717458CA}.Debug|x86.ActiveCfg = Debug|Any CPU
38+
{0DBC4DD8-CC92-4C36-A6CA-ABEE717458CA}.Debug|x86.Build.0 = Debug|Any CPU
39+
{0DBC4DD8-CC92-4C36-A6CA-ABEE717458CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{0DBC4DD8-CC92-4C36-A6CA-ABEE717458CA}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{0DBC4DD8-CC92-4C36-A6CA-ABEE717458CA}.Release|x64.ActiveCfg = Release|Any CPU
42+
{0DBC4DD8-CC92-4C36-A6CA-ABEE717458CA}.Release|x64.Build.0 = Release|Any CPU
43+
{0DBC4DD8-CC92-4C36-A6CA-ABEE717458CA}.Release|x86.ActiveCfg = Release|Any CPU
44+
{0DBC4DD8-CC92-4C36-A6CA-ABEE717458CA}.Release|x86.Build.0 = Release|Any CPU
45+
{E5B3E5AF-CA11-42EA-A9D0-72147B457AA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46+
{E5B3E5AF-CA11-42EA-A9D0-72147B457AA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
47+
{E5B3E5AF-CA11-42EA-A9D0-72147B457AA3}.Debug|x64.ActiveCfg = Debug|Any CPU
48+
{E5B3E5AF-CA11-42EA-A9D0-72147B457AA3}.Debug|x64.Build.0 = Debug|Any CPU
49+
{E5B3E5AF-CA11-42EA-A9D0-72147B457AA3}.Debug|x86.ActiveCfg = Debug|Any CPU
50+
{E5B3E5AF-CA11-42EA-A9D0-72147B457AA3}.Debug|x86.Build.0 = Debug|Any CPU
51+
{E5B3E5AF-CA11-42EA-A9D0-72147B457AA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
52+
{E5B3E5AF-CA11-42EA-A9D0-72147B457AA3}.Release|Any CPU.Build.0 = Release|Any CPU
53+
{E5B3E5AF-CA11-42EA-A9D0-72147B457AA3}.Release|x64.ActiveCfg = Release|Any CPU
54+
{E5B3E5AF-CA11-42EA-A9D0-72147B457AA3}.Release|x64.Build.0 = Release|Any CPU
55+
{E5B3E5AF-CA11-42EA-A9D0-72147B457AA3}.Release|x86.ActiveCfg = Release|Any CPU
56+
{E5B3E5AF-CA11-42EA-A9D0-72147B457AA3}.Release|x86.Build.0 = Release|Any CPU
57+
{C0D65C1D-698E-4601-98D2-D0BA4E5C0F47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
58+
{C0D65C1D-698E-4601-98D2-D0BA4E5C0F47}.Debug|Any CPU.Build.0 = Debug|Any CPU
59+
{C0D65C1D-698E-4601-98D2-D0BA4E5C0F47}.Debug|x64.ActiveCfg = Debug|Any CPU
60+
{C0D65C1D-698E-4601-98D2-D0BA4E5C0F47}.Debug|x64.Build.0 = Debug|Any CPU
61+
{C0D65C1D-698E-4601-98D2-D0BA4E5C0F47}.Debug|x86.ActiveCfg = Debug|Any CPU
62+
{C0D65C1D-698E-4601-98D2-D0BA4E5C0F47}.Debug|x86.Build.0 = Debug|Any CPU
63+
{C0D65C1D-698E-4601-98D2-D0BA4E5C0F47}.Release|Any CPU.ActiveCfg = Release|Any CPU
64+
{C0D65C1D-698E-4601-98D2-D0BA4E5C0F47}.Release|Any CPU.Build.0 = Release|Any CPU
65+
{C0D65C1D-698E-4601-98D2-D0BA4E5C0F47}.Release|x64.ActiveCfg = Release|Any CPU
66+
{C0D65C1D-698E-4601-98D2-D0BA4E5C0F47}.Release|x64.Build.0 = Release|Any CPU
67+
{C0D65C1D-698E-4601-98D2-D0BA4E5C0F47}.Release|x86.ActiveCfg = Release|Any CPU
68+
{C0D65C1D-698E-4601-98D2-D0BA4E5C0F47}.Release|x86.Build.0 = Release|Any CPU
69+
{A398FEB7-7F6E-4C98-9DA8-A35BE8D76C53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
70+
{A398FEB7-7F6E-4C98-9DA8-A35BE8D76C53}.Debug|Any CPU.Build.0 = Debug|Any CPU
71+
{A398FEB7-7F6E-4C98-9DA8-A35BE8D76C53}.Debug|x64.ActiveCfg = Debug|Any CPU
72+
{A398FEB7-7F6E-4C98-9DA8-A35BE8D76C53}.Debug|x64.Build.0 = Debug|Any CPU
73+
{A398FEB7-7F6E-4C98-9DA8-A35BE8D76C53}.Debug|x86.ActiveCfg = Debug|Any CPU
74+
{A398FEB7-7F6E-4C98-9DA8-A35BE8D76C53}.Debug|x86.Build.0 = Debug|Any CPU
75+
{A398FEB7-7F6E-4C98-9DA8-A35BE8D76C53}.Release|Any CPU.ActiveCfg = Release|Any CPU
76+
{A398FEB7-7F6E-4C98-9DA8-A35BE8D76C53}.Release|Any CPU.Build.0 = Release|Any CPU
77+
{A398FEB7-7F6E-4C98-9DA8-A35BE8D76C53}.Release|x64.ActiveCfg = Release|Any CPU
78+
{A398FEB7-7F6E-4C98-9DA8-A35BE8D76C53}.Release|x64.Build.0 = Release|Any CPU
79+
{A398FEB7-7F6E-4C98-9DA8-A35BE8D76C53}.Release|x86.ActiveCfg = Release|Any CPU
80+
{A398FEB7-7F6E-4C98-9DA8-A35BE8D76C53}.Release|x86.Build.0 = Release|Any CPU
81+
EndGlobalSection
82+
GlobalSection(NestedProjects) = preSolution
83+
{C6E6F2C4-A88C-4E9D-9183-D3EB572423DE} = {7B61769A-8EB6-4752-AF80-7F15558B2C76}
84+
{E5B3E5AF-CA11-42EA-A9D0-72147B457AA3} = {C6E6F2C4-A88C-4E9D-9183-D3EB572423DE}
85+
{A398FEB7-7F6E-4C98-9DA8-A35BE8D76C53} = {520CAA77-64DE-43BF-B173-6E1A8F3A40B9}
86+
EndGlobalSection
87+
EndGlobal

dependencies/Carter

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<AssemblyName>Carter.HtmlNegotiator.Sample</AssemblyName>
5+
<OutputType>Exe</OutputType>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.1.0" />
10+
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.1.0" />
11+
<PackageReference Include="Carter" Version="3.7.0" />
12+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
13+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.1.1" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\dependencies\Carter\src\Carter.csproj" />
18+
<ProjectReference Include="..\src\Carter.HtmlNegotiator.csproj" />
19+
</ItemGroup>
20+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Carter.HtmlNegotiator.Sample.Features.MyFeature
2+
{
3+
using ViewModels;
4+
5+
public class MyFeatureModule : CarterModule
6+
{
7+
public MyFeatureModule() : base("/myfeature")
8+
{
9+
Get("/",
10+
async (req, res, routeData) =>
11+
{
12+
await res.AsHtml("index", new MyViewModel{Title = "Hello World!", Message = "Hello from a Custom View Location"});
13+
});
14+
}
15+
}
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>{{title}}</title>
5+
</head>
6+
<body>
7+
<h1>{{message}}</h1>
8+
</body>
9+
</html>

sample/Modules/AnotherModule.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Carter.HtmlNegotiator.Sample.Modules
2+
{
3+
using ViewModels;
4+
5+
public class AnotherModule : CarterModule
6+
{
7+
public AnotherModule() : base("/another")
8+
{
9+
Get("/",
10+
async (req, res, routeData) =>
11+
{
12+
await res.AsHtml("index", new MyViewModel{Title = "Hello World!", Message = "Hello from Another Module!"});
13+
});
14+
}
15+
}
16+
}

sample/Modules/HomeModule.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Carter.HtmlNegotiator.Sample.Modules
2+
{
3+
using Carter;
4+
using ViewModels;
5+
6+
public class HomeModule : CarterModule
7+
{
8+
public HomeModule()
9+
{
10+
Get("/",
11+
async (req, res, routeData) =>
12+
{
13+
await res.AsHtml("index",new MyViewModel{Title = "Hello World!", Message = "Hello from Carter.HtmlNegotiator!"});
14+
});
15+
16+
Get("/custom",
17+
async (req, res, routeData) =>
18+
{
19+
await res.AsHtml("myView", new MyViewModel{Title = "Custom View!", Message = "Hello from a custom view name!"});
20+
});
21+
}
22+
}
23+
}

sample/Program.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Carter.HtmlNegotiator.Sample
2+
{
3+
using System.IO;
4+
using Microsoft.AspNetCore.Hosting;
5+
6+
public class Program
7+
{
8+
public static void Main(string[] args)
9+
{
10+
var host = new WebHostBuilder()
11+
.UseContentRoot(Directory.GetCurrentDirectory())
12+
.UseKestrel()
13+
.UseStartup<Startup>()
14+
.Build();
15+
16+
host.Run();
17+
}
18+
}
19+
}

sample/Startup.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace Carter.HtmlNegotiator.Sample
2+
{
3+
using Carter;
4+
using Microsoft.AspNetCore.Builder;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Logging;
7+
8+
public class Startup
9+
{
10+
public void ConfigureServices(IServiceCollection services)
11+
{
12+
services.AddHtmlNegotiator(with =>
13+
with.ViewLocation(ctx => $"features/{ctx.ModuleName}/views/{ctx.ViewName}"));
14+
services.AddCarter();
15+
}
16+
17+
public void Configure(IApplicationBuilder app, ILoggerFactory logging)
18+
{
19+
logging.AddConsole();
20+
logging.AddDebug();
21+
22+
app.UseCarter();
23+
}
24+
}
25+
}

sample/ViewModels/MyViewModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Carter.HtmlNegotiator.Sample.ViewModels
2+
{
3+
public class MyViewModel
4+
{
5+
public string Title { get; set; }
6+
public string Message { get; set; }
7+
}
8+
}

sample/Views/.DS_Store

6 KB
Binary file not shown.

sample/Views/Another/index.hbs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>{{title}}</title>
5+
</head>
6+
<body>
7+
<h1>{{message}}</h1>
8+
</body>
9+
</html>

sample/Views/Home/index.hbs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>{{title}}</title>
5+
</head>
6+
<body>
7+
<h1>{{message}}</h1>
8+
</body>
9+
</html>

sample/Views/Home/myView.hbs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>{{title}}</title>
5+
</head>
6+
<body>
7+
<h1>{{message}}</h1>
8+
</body>
9+
</html>

src/AmbiguousViewsException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Carter.HtmlNegotiator
2+
{
3+
using System;
4+
5+
public class AmbiguousViewsException : Exception
6+
{
7+
public AmbiguousViewsException(string message) : base(message) {}
8+
}
9+
}

0 commit comments

Comments
 (0)