Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinmoris committed Apr 19, 2019
2 parents 1a824da + 04232c0 commit de18267
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 19 deletions.
8 changes: 6 additions & 2 deletions .psscripts/build-functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ function Test-IsMonoInstalled
if (Test-IsMonoInstalled) { Write-Host "Mono is available." }
#>

$result = Invoke-Cmd "mono --version" -Silent
return $result.StartsWith("Mono JIT compiler version")
try
{
$result = Invoke-Cmd "mono --version" -Silent
return $result.StartsWith("Mono JIT compiler version")
}
catch { return false }
}

function Get-UbuntuVersion
Expand Down
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ language: csharp
sudo: required
dist: trusty

dotnet: 2.2.101
dotnet: 2.2.105
mono:
- 4.6.1
- 4.8.1
- 5.16.0

- 5.18.0
os:
- linux

Expand Down
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ Razor view engine support for the [Giraffe](https://github.com/giraffe-fsharp/Gi

[![NuGet Info](https://buildstats.info/nuget/Giraffe.Razor?includePreReleases=true)](https://www.nuget.org/packages/Giraffe.Razor/)

| Windows | Linux |
| :------ | :---- |
| [![Windows Build status](https://ci.appveyor.com/api/projects/status/914030ec0lrc0vti/branch/develop?svg=true)](https://ci.appveyor.com/project/dustinmoris/giraffe-razor/branch/develop) | [![Linux Build status](https://travis-ci.org/giraffe-fsharp/Giraffe.Razor.svg?branch=develop)](https://travis-ci.org/giraffe-fsharp/Giraffe.Razor/builds?branch=develop) |
| [![Windows Build history](https://buildstats.info/appveyor/chart/dustinmoris/giraffe-razor?branch=develop&includeBuildsFromPullRequest=false)](https://ci.appveyor.com/project/dustinmoris/giraffe-razor/history?branch=develop) | [![Linux Build history](https://buildstats.info/travisci/chart/giraffe-fsharp/Giraffe.Razor?branch=develop&includeBuildsFromPullRequest=false)](https://travis-ci.org/giraffe-fsharp/Giraffe.Razor/builds?branch=develop) |
### Windows and Linux Builds

[![Windows Build status](https://ci.appveyor.com/api/projects/status/914030ec0lrc0vti/branch/develop?svg=true)](https://ci.appveyor.com/project/dustinmoris/giraffe-razor/branch/develop)

[![Windows Build history](https://buildstats.info/appveyor/chart/dustinmoris/giraffe-razor?branch=develop&includeBuildsFromPullRequest=false&buildCount=40)](https://ci.appveyor.com/project/dustinmoris/giraffe-razor/history?branch=develop)

## Table of contents

Expand Down Expand Up @@ -40,6 +41,18 @@ type Startup() =
svc.AddRazorEngine viewsFolderPath |> ignore
```

If your all of your Razor views are kept in a Razor class library, then you do not need to specify a views folder path when registering the Razor dependencies. In this case there is an overload of `AddRazorEngine` which takes no arguments:

```fsharp
open Giraffe
open Giraffe.Razor
type Startup() =
member __.ConfigureServices (svc : IServiceCollection,
env : IHostingEnvironment) =
svc.AddRazorEngine() |> ignore
```

### razorView

The `razorView` http handler utilises the official ASP.NET Core MVC Razor view engine to compile a view into a HTML page and sets the body of the `HttpResponse` object. It requires the content type, the view name, an optional view model, an optional view data dictionary, and an optional model state dictionary as input parameters.
Expand Down
10 changes: 10 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
Release Notes
=============

## 4.0.0

#### Breaking changes & Bug fixes

- Fixed a bug around the `TempData` implementation to ensure that all previously stored data in the `TempData` dictionary is accessible as well as newly made changes are persisted going forward.

#### New features

- Added an additional overload of `AddRazorEngine` which does not take any arguments, which supports Razor views from a class library.

## 3.0.0

#### New features/Breaking changes
Expand Down
5 changes: 4 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
version: 0.1.0-{build}
image: Visual Studio 2017
image:
- Visual Studio 2017
- Ubuntu
environment:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
init:
- git config --global core.autocrlf true
install:
- sh: export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/
- ps: .\.psscripts\install-dotnet.ps1
build: off
build_script:
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"projects": [ "src", "tests" ],
"sdk": {
"version": "2.2.101"
"version": "2.2.105"
}
}
6 changes: 3 additions & 3 deletions src/Giraffe.Razor/Giraffe.Razor.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<PropertyGroup>
<!-- General -->
<AssemblyName>Giraffe.Razor</AssemblyName>
<Version>3.0.0</Version>
<Version>4.0.0</Version>
<Description>Razor view engine support for the Giraffe web framework.</Description>
<Copyright>Copyright 2018 Dustin Moris Gorski</Copyright>
<Authors>Dustin Moris Gorski and contributors</Authors>
<NeutralLanguage>en-GB</NeutralLanguage>

<!-- Build settings -->
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<DebugType>portable</DebugType>
<OutputType>Library</OutputType>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down Expand Up @@ -42,7 +42,7 @@
<PackageReference Include="Microsoft.Extensions.Primitives" Version="2.2.*" />
<PackageReference Include="Microsoft.AspNetCore.Antiforgery" Version="2.2.*" />
<PackageReference Include="TaskBuilder.fs" Version="2.1.*" />
<PackageReference Include="Giraffe" Version="3.5.*" />
<PackageReference Include="Giraffe" Version="3.6.*" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Giraffe.Razor/HttpHandlers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ module HttpHandlers =
fun (next : HttpFunc) (ctx : HttpContext) ->
task {
let engine = ctx.RequestServices.GetService<IRazorViewEngine>()
let tempDataProvider = ctx.RequestServices.GetService<ITempDataProvider>()
let! result = renderView engine tempDataProvider ctx viewName model viewData modelState
let tempDataDict = ctx.RequestServices.GetService<ITempDataDictionaryFactory>().GetTempData ctx
let! result = renderView engine tempDataDict ctx viewName model viewData modelState
match result with
| Error msg -> return (failwith msg)
| Ok output ->
Expand Down
6 changes: 5 additions & 1 deletion src/Giraffe.Razor/Middleware.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ module Middleware =
options.FileProviders.Add(new PhysicalFileProvider(viewsFolderPath)))
.AddMvc()
|> ignore
this.AddAntiforgery()
this.AddAntiforgery()

member this.AddRazorEngine() =
this.AddMvc() |> ignore
this.AddAntiforgery()
4 changes: 2 additions & 2 deletions src/Giraffe.Razor/RazorEngine.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module RazorEngine =
routeData

let renderView (razorViewEngine : IRazorViewEngine)
(tempDataProvider : ITempDataProvider)
(tempDataDict : ITempDataDictionary)
(httpContext : HttpContext)
(viewName : string)
(model : 'T option)
Expand Down Expand Up @@ -73,10 +73,10 @@ module RazorEngine =
if (viewData.IsSome) then
viewData.Value
|> Seq.iter (fun x -> viewDataDict.Add x)
let tempDataDict = TempDataDictionary(actionContext.HttpContext, tempDataProvider)
let htmlHelperOptions = HtmlHelperOptions()
use output = new StringWriter()
let viewContext = ViewContext(actionContext, view, viewDataDict, tempDataDict, output, htmlHelperOptions)
do! view.RenderAsync(viewContext)
tempDataDict.Save()
return Ok (output.ToString())
}

0 comments on commit de18267

Please sign in to comment.