Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinmoris committed Aug 18, 2018
2 parents 8b95a52 + 65ef4fa commit c85a3a0
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto
* text=auto
*.sh text eol=lf
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: csharp
sudo: required
dist: trusty

dotnet: 2.1.4
dotnet: 2.1.400
mono:
- 4.6.1
- 4.8.1
Expand All @@ -16,6 +16,7 @@ before_install:
- curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
- sudo apt-get update
- sudo apt-get install -y powershell
- sudo pwsh ./install-dotnet.ps1

script:
- export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/
Expand Down
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Release Notes
=============

## 1.3.0

Upgraded to Giraffe `2.0.0` and the latest ASP.NET Core `2.1.*` NuGet packages.

## 1.2.0

Added support for view folders (see [#1](https://github.com/giraffe-fsharp/Giraffe.Razor/issues/1), [#3](https://github.com/giraffe-fsharp/Giraffe.Razor/issues/3)).
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ environment:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
init:
- git config --global core.autocrlf true
install:
- ps: .\install-dotnet.ps1
build: off
build_script:
- ps: .\build.ps1 -Release -Pack
Expand Down
1 change: 0 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function Write-DotnetVersion
function dotnet-restore ($project, $argv) { Invoke-Cmd "dotnet restore $project $argv" }
function dotnet-build ($project, $argv) { Invoke-Cmd "dotnet build $project $argv" }
function dotnet-run ($project, $argv) { Invoke-Cmd "dotnet run --project $project $argv" }
function dotnet-test ($project, $argv) { Invoke-Cmd "dotnet test $project $argv" }
function dotnet-pack ($project, $argv) { Invoke-Cmd "dotnet pack $project $argv" }

function Test-Version ($project)
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.1.4"
"version": "2.1.400"
}
}
88 changes: 88 additions & 0 deletions install-dotnet.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# ----------------------------------------------------------
# Install script to check and download the correct .NET SDK
# ----------------------------------------------------------

function Test-IsWindows
{
[environment]::OSVersion.Platform -ne "Unix"
}

function Invoke-Cmd ($cmd)
{
Write-Host $cmd -ForegroundColor DarkCyan
if (Test-IsWindows) { $cmd = "cmd.exe /C $cmd" }
Invoke-Expression -Command $cmd
if ($LastExitCode -ne 0) { Write-Error "An error occured when executing '$cmd'."; return }
}

function dotnet-version { Invoke-Cmd "dotnet --version" }

function Get-DesiredSdk
{
Get-Content "global.json" | ConvertFrom-Json | % { $_.sdk.version.ToString() }
}

function Get-NetCoreSdk ($version)
{
$os = if (Test-IsWindows) { "windows" } else { "linux" }

$response = Invoke-WebRequest `
-Uri "https://www.microsoft.com/net/download/thank-you/dotnet-sdk-$version-$os-x64-binaries" `
-Method Get `
-MaximumRedirection 0 `

$downloadLink =
$response.Links `
| Where-Object { $_.onclick -eq "recordManualDownload()" } `
| Select-Object -Expand href

$tempFile = [System.IO.Path]::GetTempFileName()
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($downloadLink, $tempFile)
return $tempFile
}

function Install-NetCoreSdk ($sdkZipPath)
{
$env:DOTNET_INSTALL_DIR = "$pwd\.dotnetsdk"
New-Item $env:DOTNET_INSTALL_DIR -ItemType Directory -Force

Add-Type -AssemblyName System.IO.Compression.FileSystem;
[System.IO.Compression.ZipFile]::ExtractToDirectory($sdkZipPath, $env:DOTNET_INSTALL_DIR)
$env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
}

# ----------------------------------------------
# Install .NET Core SDK
# ----------------------------------------------

$ErrorActionPreference = "Stop"

# Rename the global.json before making the dotnet --version call
# This will prevent AppVeyor to fail because it might not find
# the desired SDK specified in the global.json
$globalJson = Get-Item "global.json"
Rename-Item -Path $globalJson.FullName -NewName "global.json.bak" -Force

# Get the current .NET Core SDK version
$currentSdk = dotnet-version

# After we established the current installed .NET SDK we can put the global.json back
Rename-Item -Path ($globalJson.FullName + ".bak") -NewName "global.json" -Force

$desiredSdk = Get-DesiredSdk

if ($desiredSdk -eq $currentSdk)
{
Write-Host "The current .NET SDK matches the project's desired .NET SDK: $desiredSDK" -ForegroundColor Green
return
}

Write-Host "The current .NET SDK ($currentSdk) doesn't match the project's desired .NET SDK ($desiredSdk)." -ForegroundColor Yellow
Write-Host "Attempting to download and install the correct .NET SDK..."

$sdkZipPath = Get-NetCoreSdk $desiredSdk
Install-NetCoreSdk $sdkZipPath

Write-Host ".NET SDK installation complete." -ForegroundColor Green
dotnet-version
9 changes: 2 additions & 7 deletions samples/GiraffeRazorSample/GiraffeRazorSample.fsproj
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
<DebugType>portable</DebugType>
<AssemblyName>GiraffeRazorSample</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>GiraffeRazorSample</PackageId>
<RuntimeFrameworkVersion>2.0</RuntimeFrameworkVersion>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
<RunWorkingDirectory>$(MSBuildThisFileDirectory)</RunWorkingDirectory>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.*" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.*" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Giraffe.Razor\Giraffe.Razor.fsproj" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.*" />
</ItemGroup>

<ItemGroup>
<Watch Include="**\*.cshtml" Exclude="bin\**\*" />
</ItemGroup>
Expand Down
15 changes: 8 additions & 7 deletions src/Giraffe.Razor/Giraffe.Razor.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Giraffe.Razor</AssemblyName>
<Version>1.2.0</Version>
<Version>1.3.0</Version>
<Description>Razor view engine http handlers for the Giraffe web framework.</Description>
<Copyright>Copyright 2018 Dustin Moris Gorski</Copyright>
<NeutralLanguage>en-GB</NeutralLanguage>
Expand All @@ -23,15 +23,16 @@
<IncludeSymbols>true</IncludeSymbols>
<NetStandardImplicitPackageVersion>2.0</NetStandardImplicitPackageVersion>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="2.0.*" />
<PackageReference Include="Microsoft.AspNetCore.Antiforgery" Version="2.0.*" />
<PackageReference Include="Giraffe" Version="1.1.*" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.*" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="2.1.*" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="2.1.*" />
<PackageReference Include="Microsoft.AspNetCore.Antiforgery" Version="2.1.*" />
<PackageReference Include="Giraffe" Version="2.0.*" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 7 additions & 7 deletions src/Giraffe.Razor/RazorEngine.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ module RazorEngine =
open Giraffe

let private extractRouteData (path:string) =

let templatePath = path + "" //Normalize nulls

//Split path into segments and reverse the orders
let segments =
//Split path into segments and reverse the orders
let segments =
templatePath.Split('/', '\\')
|> List.ofSeq
|> List.ofSeq
|> List.rev

let routeValues =
let routeValues =
seq {
for i in 1..segments.Length do
match i with
Expand All @@ -40,7 +40,7 @@ module RazorEngine =

for (key,value) in routeValues do
routeData.Values.Add(key, value)

routeData

let renderView (razorViewEngine : IRazorViewEngine)
Expand All @@ -50,7 +50,7 @@ module RazorEngine =
(model : 'T) =
task {
let routeData = extractRouteData(viewName)
let templateName = routeData.Values.["action"].ToString()
let templateName = routeData.Values.["action"].ToString()

let actionContext = ActionContext(httpContext, routeData, ActionDescriptor())
let viewEngineResult = razorViewEngine.FindView(actionContext, templateName, true)
Expand Down

0 comments on commit c85a3a0

Please sign in to comment.