Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinmoris committed Dec 22, 2017
2 parents 709fd27 + 57a7def commit 0c74843
Show file tree
Hide file tree
Showing 31 changed files with 504 additions and 36 deletions.
57 changes: 29 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ Giraffe web application template for the `dotnet new` command.

## Table of contents

- [Documentation](#documentation)
- [Installation](#installation)
- [Usage](#usage)
- [ViewEngine options](#viewengine-options)
- [Restoring and building](#restoring-and-building)
- [Updating the template](#updating-the-template)
- [Installation](#installation)
- [Basics](#basics)
- [Optional parameters](#optional-parameters)
- [--ViewEngine](#--viewengine)
- [--IncludeTests](#--includetests)
- [Updating the template](#updating-the-template)
- [Nightly builds and NuGet feed](#nightly-builds-and-nuget-feed)
- [More information](#more-information)
- [License](#license)

## Documentation

### Installation
## Installation

The easiest way to install the Giraffe template is by running the following command in your terminal:

Expand All @@ -30,61 +28,64 @@ dotnet new -i "giraffe-template::*"

This will pull and install the [giraffe-template NuGet package](https://www.nuget.org/packages/giraffe-template/) in your .NET environment and make it available to subsequent `dotnet new` commands.

### Usage
## Basics

After the template has been installed you can create a new Giraffe web application by simply running `dotnet new giraffe` in your terminal:

```
dotnet new giraffe
```

#### ViewEngine options
The Giraffe template only supports the F# language at the moment.

Further information and more help can be found by running `dotnet new giraffe --help` in your terminal.

## Optional parameters

### --ViewEngine

The Giraffe template supports three different view engine types at the moment:
The Giraffe template supports three different view engines:

- `giraffe` (default)
- `razor`
- `dotliquid`

You can optionally specify the `--ViewEngine` parameter (short `-V`) and pass in one of the supported values:
You can optionally specify the `--ViewEngine` parameter (short `-V`) to pass in one of the supported values:

```
dotnet new giraffe --ViewEngine razor
```

...or using `-V`:
The same using the abbreviated `-V` parameter:

```
dotnet new giraffe -V dotliquid
dotnet new giraffe -V razor
```

If you do not specify the `--ViewEngine` parameter then the `dotnet new giraffe` command will automatically create a Giraffe web application with the default `Giraffe.GiraffeViewEngine` engine.
If you do not specify the `--ViewEngine` parameter then the `dotnet new giraffe` command will automatically create a Giraffe web application with the default `GiraffeViewEngine` engine.

For further help you can also run `dotnet new giraffe --help` which will print all available parameters and their supported values.
### --IncludeTests

#### Restoring and building

After successfully creating a new application you should be able to restore, build and run your Giraffe web application without any further doing:
When creating a new Giraffe web application you can optionally specify the `--IncludeTests` (short `-I`) parameter to automatically generate a default unit test project for your application:

```
mkdir GiraffeSampleApp
cd GiraffeSampleApp
dotnet new giraffe --IncludeTests
```

dotnet new giraffe
This parameter can also be combined with other parameters:

dotnet restore
dotnet build
dotnet run
```
dotnet new giraffe --ViewEngine razor --IncludeTests
```

### Updating the template
## Updating the template

Whenever there is a new version of the Giraffe template you can update it by re-running the [instructions from the installation](#installation).

You can also explicitly set the version when installing the template:

```
dotnet new -i "giraffe-template::0.10.0"
dotnet new -i "giraffe-template::0.11.0"
```

## Nightly builds and NuGet feed
Expand Down
26 changes: 26 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
Release Notes
=============

## 0.11.0

#### New features

Added an additional parameter called `IncludeTests` which can be added to auto generate an accompanying test project to your Giraffe web application.

#### Examples:

Default Giraffe web application with the `GiraffeViewEngine` and no tests:

```
dotnet new giraffe
```

Default Giraffe web application with the `GiraffeViewEngine` and a default test project:

```
dotnet new giraffe --IncludeTests
```

Giraffe web application with the Razor view engine and a default test project:

```
dotnet new giraffe --ViewEngine razor --IncludeTests
```

## 0.10.0

#### New features
Expand Down
39 changes: 33 additions & 6 deletions src/content/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,50 @@
"description": "DotLiquid template engine"
}
]
},
"IncludeTests": {
"type": "parameter",
"dataType": "bool",
"defaultValue": "false"
}
},
"sources": [
{
"source": "./Giraffe.Template/",
"source": "./Giraffe/",
"target": "./",
"condition": "(ViewEngine == \"giraffe\")"
"condition": "(ViewEngine == \"giraffe\")",
"modifiers": [
{
"condition": "(!IncludeTests)",
"exclude": [ "**/AppNamePlaceholder.Tests/**/*" ]
}
]
},
{
"source": "./Razor.Template/",
"source": "./Razor/",
"target": "./",
"condition": "(ViewEngine == \"razor\")"
"condition": "(ViewEngine == \"razor\")",
"modifiers": [
{
"condition": "(!IncludeTests)",
"exclude": [ "**/AppNamePlaceholder.Tests/**/*" ]
}
]
},
{
"source": "./DotLiquid.Template/",
"source": "./DotLiquid/",
"target": "./",
"condition": "(ViewEngine == \"dotliquid\")"
"condition": "(ViewEngine == \"dotliquid\")",
"modifiers": [
{
"condition": "(!IncludeTests)",
"exclude": [ "**/AppNamePlaceholder.Tests/**/*" ]
}
]
},
{
"source": "./_Default/",
"target": "./"
}
]
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ open AppNamePlaceholder.Models
let indexHandler (name : string) =
let greetings = sprintf "Hello %s, from Giraffe!" name
let model = { Text = greetings }
dotLiquidHtmlView "Views/Index.html" model
dotLiquidHtmlTemplate "Views/Index.html" model

let webApp =
choose [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.*" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.*" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.*" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.0.*" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.*" />
<PackageReference Include="xunit" Version="2.3.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.*" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../../src/AppNamePlaceholder/AppNamePlaceholder.fsproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="Tests.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Program
let [<EntryPoint>] main _ = 0
87 changes: 87 additions & 0 deletions src/content/DotLiquid/tests/AppNamePlaceholder.Tests/Tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
module Tests

open System
open System.IO
open System.Net
open System.Net.Http
open Xunit
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.TestHost
open Microsoft.Extensions.DependencyInjection

// ---------------------------------
// Helper functions (extend as you need)
// ---------------------------------

let createHost() =
WebHostBuilder()
.UseContentRoot(Directory.GetCurrentDirectory())
.Configure(Action<IApplicationBuilder> AppNamePlaceholder.App.configureApp)
.ConfigureServices(Action<IServiceCollection> AppNamePlaceholder.App.configureServices)

let runTask task =
task
|> Async.AwaitTask
|> Async.RunSynchronously

let httpGet (path : string) (client : HttpClient) =
path
|> client.GetAsync
|> runTask

let isStatus (code : HttpStatusCode) (response : HttpResponseMessage) =
Assert.Equal(code, response.StatusCode)
response

let ensureSuccess (response : HttpResponseMessage) =
if not response.IsSuccessStatusCode
then response.Content.ReadAsStringAsync() |> runTask |> failwithf "%A"
else response

let readText (response : HttpResponseMessage) =
response.Content.ReadAsStringAsync()
|> runTask

let shouldEqual expected actual =
Assert.Equal(expected, actual)

let shouldContain (expected : string) (actual : string) =
Assert.True(actual.Contains expected)

// ---------------------------------
// Tests
// ---------------------------------

[<Fact>]
let ``Route / returns "Hello world, from Giraffe!"`` () =
use server = new TestServer(createHost())
use client = server.CreateClient()

client
|> httpGet "/"
|> ensureSuccess
|> readText
|> shouldContain "Hello world, from Giraffe!"

[<Fact>]
let ``Route /hello/fooBar returns "Hello fooBar, from Giraffe!"`` () =
use server = new TestServer(createHost())
use client = server.CreateClient()

client
|> httpGet "/hello/fooBar"
|> ensureSuccess
|> readText
|> shouldContain "Hello fooBar, from Giraffe!"

[<Fact>]
let ``Route which doesn't exist returns 404 Page not found`` () =
use server = new TestServer(createHost())
use client = server.CreateClient()

client
|> httpGet "/route/which/does/not/exist"
|> isStatus HttpStatusCode.NotFound
|> readText
|> shouldEqual "Not Found"
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.*" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.*" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.*" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.0.*" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.*" />
<PackageReference Include="xunit" Version="2.3.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.*" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../../src/AppNamePlaceholder/AppNamePlaceholder.fsproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="Tests.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions src/content/Giraffe/tests/AppNamePlaceholder.Tests/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Program
let [<EntryPoint>] main _ = 0
Loading

0 comments on commit 0c74843

Please sign in to comment.