Skip to content

Add Handlebars View Engine #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions Carter.HtmlNegotiator.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Carter.HtmlNegotiator", "src\Carter.HtmlNegotiator\Carter.HtmlNegotiator.csproj", "{486553EF-81DD-401C-AA24-A7A360DDC1F7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Carter.HtmlNegotiator.Sample", "sample\Carter.HtmlNegotiator.Sample\Carter.HtmlNegotiator.Sample.csproj", "{00A6A897-5C02-46E6-B333-8F605BE4145A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Carter", "dependencies\Carter\src\Carter\Carter.csproj", "{8D717F79-9A5C-45FE-8B39-86A651563ADB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Carter.HtmlNegotiator.Tests", "src\Carter.HtmlNegotiator.Tests\Carter.HtmlNegotiator.Tests.csproj", "{A6631AB5-2720-4DBC-A2F7-D00E8A70F9F0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{486553EF-81DD-401C-AA24-A7A360DDC1F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{486553EF-81DD-401C-AA24-A7A360DDC1F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{486553EF-81DD-401C-AA24-A7A360DDC1F7}.Debug|x64.ActiveCfg = Debug|Any CPU
{486553EF-81DD-401C-AA24-A7A360DDC1F7}.Debug|x64.Build.0 = Debug|Any CPU
{486553EF-81DD-401C-AA24-A7A360DDC1F7}.Debug|x86.ActiveCfg = Debug|Any CPU
{486553EF-81DD-401C-AA24-A7A360DDC1F7}.Debug|x86.Build.0 = Debug|Any CPU
{486553EF-81DD-401C-AA24-A7A360DDC1F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{486553EF-81DD-401C-AA24-A7A360DDC1F7}.Release|Any CPU.Build.0 = Release|Any CPU
{486553EF-81DD-401C-AA24-A7A360DDC1F7}.Release|x64.ActiveCfg = Release|Any CPU
{486553EF-81DD-401C-AA24-A7A360DDC1F7}.Release|x64.Build.0 = Release|Any CPU
{486553EF-81DD-401C-AA24-A7A360DDC1F7}.Release|x86.ActiveCfg = Release|Any CPU
{486553EF-81DD-401C-AA24-A7A360DDC1F7}.Release|x86.Build.0 = Release|Any CPU
{00A6A897-5C02-46E6-B333-8F605BE4145A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00A6A897-5C02-46E6-B333-8F605BE4145A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00A6A897-5C02-46E6-B333-8F605BE4145A}.Debug|x64.ActiveCfg = Debug|Any CPU
{00A6A897-5C02-46E6-B333-8F605BE4145A}.Debug|x64.Build.0 = Debug|Any CPU
{00A6A897-5C02-46E6-B333-8F605BE4145A}.Debug|x86.ActiveCfg = Debug|Any CPU
{00A6A897-5C02-46E6-B333-8F605BE4145A}.Debug|x86.Build.0 = Debug|Any CPU
{00A6A897-5C02-46E6-B333-8F605BE4145A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00A6A897-5C02-46E6-B333-8F605BE4145A}.Release|Any CPU.Build.0 = Release|Any CPU
{00A6A897-5C02-46E6-B333-8F605BE4145A}.Release|x64.ActiveCfg = Release|Any CPU
{00A6A897-5C02-46E6-B333-8F605BE4145A}.Release|x64.Build.0 = Release|Any CPU
{00A6A897-5C02-46E6-B333-8F605BE4145A}.Release|x86.ActiveCfg = Release|Any CPU
{00A6A897-5C02-46E6-B333-8F605BE4145A}.Release|x86.Build.0 = Release|Any CPU
{8D717F79-9A5C-45FE-8B39-86A651563ADB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D717F79-9A5C-45FE-8B39-86A651563ADB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D717F79-9A5C-45FE-8B39-86A651563ADB}.Debug|x64.ActiveCfg = Debug|Any CPU
{8D717F79-9A5C-45FE-8B39-86A651563ADB}.Debug|x64.Build.0 = Debug|Any CPU
{8D717F79-9A5C-45FE-8B39-86A651563ADB}.Debug|x86.ActiveCfg = Debug|Any CPU
{8D717F79-9A5C-45FE-8B39-86A651563ADB}.Debug|x86.Build.0 = Debug|Any CPU
{8D717F79-9A5C-45FE-8B39-86A651563ADB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D717F79-9A5C-45FE-8B39-86A651563ADB}.Release|Any CPU.Build.0 = Release|Any CPU
{8D717F79-9A5C-45FE-8B39-86A651563ADB}.Release|x64.ActiveCfg = Release|Any CPU
{8D717F79-9A5C-45FE-8B39-86A651563ADB}.Release|x64.Build.0 = Release|Any CPU
{8D717F79-9A5C-45FE-8B39-86A651563ADB}.Release|x86.ActiveCfg = Release|Any CPU
{8D717F79-9A5C-45FE-8B39-86A651563ADB}.Release|x86.Build.0 = Release|Any CPU
{A6631AB5-2720-4DBC-A2F7-D00E8A70F9F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A6631AB5-2720-4DBC-A2F7-D00E8A70F9F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6631AB5-2720-4DBC-A2F7-D00E8A70F9F0}.Debug|x64.ActiveCfg = Debug|Any CPU
{A6631AB5-2720-4DBC-A2F7-D00E8A70F9F0}.Debug|x64.Build.0 = Debug|Any CPU
{A6631AB5-2720-4DBC-A2F7-D00E8A70F9F0}.Debug|x86.ActiveCfg = Debug|Any CPU
{A6631AB5-2720-4DBC-A2F7-D00E8A70F9F0}.Debug|x86.Build.0 = Debug|Any CPU
{A6631AB5-2720-4DBC-A2F7-D00E8A70F9F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6631AB5-2720-4DBC-A2F7-D00E8A70F9F0}.Release|Any CPU.Build.0 = Release|Any CPU
{A6631AB5-2720-4DBC-A2F7-D00E8A70F9F0}.Release|x64.ActiveCfg = Release|Any CPU
{A6631AB5-2720-4DBC-A2F7-D00E8A70F9F0}.Release|x64.Build.0 = Release|Any CPU
{A6631AB5-2720-4DBC-A2F7-D00E8A70F9F0}.Release|x86.ActiveCfg = Release|Any CPU
{A6631AB5-2720-4DBC-A2F7-D00E8A70F9F0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion dependencies/Carter
Submodule Carter updated 172 files
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\dependencies\Carter\src\Carter\Carter.csproj" />
<ProjectReference Include="..\..\src\Carter.HtmlNegotiator\Carter.HtmlNegotiator.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\css" />
<Folder Include="wwwroot\js" />
</ItemGroup>

<ItemGroup>
<Content Remove="wwwroot\css\style.css" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions sample/Carter.HtmlNegotiator.Sample/Features/Home/Echo.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{#*inline "content"}}
<div class="container">
<h3>Echo: {{Message}}</h3>
</div>
{{/inline}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Carter.HtmlNegotiator.Sample.Features.Home
{
public class EchoViewModel
{
public string Message { get; set; }
}
}
25 changes: 25 additions & 0 deletions sample/Carter.HtmlNegotiator.Sample/Features/Home/HomeModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Carter.Request;
using Carter.Response;

namespace Carter.HtmlNegotiator.Sample.Features.Home
{
public class HomeModule : CarterModule
{
public HomeModule()
{
Get("/", (request, response) => response.Negotiate(new
{
Title = "Welcome To Carter",
Message = "Hello From Carter!"
}));

Get("/echo", (request, response) => response
.WithView("Echo.hbs")
.Negotiate(new EchoViewModel
{
Message = request.Query.As<string>("msg")
})
);
}
}
}
5 changes: 5 additions & 0 deletions sample/Carter.HtmlNegotiator.Sample/Features/Home/Index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{#*inline "content"}}
<div class="container">
<h1 class="mt-5">{{Message}}</h1>
</div>
{{/inline}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="container">
<span class="text-muted">Footer content here.</span>
</div>
48 changes: 48 additions & 0 deletions sample/Carter.HtmlNegotiator.Sample/Features/Shared/Layout.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!doctype html>
<html lang="en" class="h-100">
<head>
<title>
{{#if title}}
{{title}}
{{else}}
Base Page Title
{{/if}}
</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}

.container {
width: auto;
max-width: 680px;
padding: 0 15px;
}

.footer {
background-color: #f5f5f5;
}
</style>
</head>
<body class="d-flex flex-column h-100">
<main role="main" class="flex-shrink-0">
{{> content}}
</main>
<footer class="footer mt-auto py-3">
{{> Footer }}
</footer>
{{> Scripts }}
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
26 changes: 26 additions & 0 deletions sample/Carter.HtmlNegotiator.Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Carter.HtmlNegotiator.Sample
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
31 changes: 31 additions & 0 deletions sample/Carter.HtmlNegotiator.Sample/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Carter.HtmlNegotiator.Sample
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddCarter();
services.AddHtmlNegotiator();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(builder => builder.MapCarter());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
10 changes: 10 additions & 0 deletions sample/Carter.HtmlNegotiator.Sample/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
27 changes: 27 additions & 0 deletions src/Carter.HtmlNegotiator.Tests/Carter.HtmlNegotiator.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Shouldly" Version="4.0.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Carter.HtmlNegotiator\Carter.HtmlNegotiator.csproj" />
</ItemGroup>

</Project>
Loading