Permalink
Browse files

attempt to use Razor for complex layout

  • Loading branch information...
1 parent 66d7c8c commit 8afea34e0bce7751de002013368d8cef8bb63416 @akurdyukov committed May 13, 2012
View
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <solution>
+ <add key="disableSourceControlIntegration" value="true" />
+ </solution>
+</configuration>
View
Binary file not shown.
View
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
+
+ <!-- Windows specific commands -->
+ <NuGetToolsPath Condition=" '$(OS)' == 'Windows_NT'">$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
+ <PackagesConfig Condition=" '$(OS)' == 'Windows_NT'">$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
+ <PackagesDir Condition=" '$(OS)' == 'Windows_NT'">$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
+
+ <!-- We need to launch nuget.exe with the mono command if we're not on windows -->
+ <NuGetToolsPath Condition=" '$(OS)' != 'Windows_NT'">$(SolutionDir).nuget</NuGetToolsPath>
+ <PackagesConfig Condition=" '$(OS)' != 'Windows_NT' ">packages.config</PackagesConfig>
+ <PackagesDir Condition=" '$(OS)' != 'Windows_NT'">$(SolutionDir)packages</PackagesDir>
+
+ <!-- NuGet command -->
+ <NuGetExePath>$(NuGetToolsPath)\nuget.exe</NuGetExePath>
+ <NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
+ <NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
+
+ <PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
+
+ <!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config -->
+ <PackageSources>""</PackageSources>
+
+ <!-- Enable the restore command to run before builds -->
+ <RestorePackages Condition="$(RestorePackages) == ''">false</RestorePackages>
+
+ <!-- Property that enables building a package from a project -->
+ <BuildPackage Condition="$(BuildPackage) == ''">false</BuildPackage>
+
+ <!-- Commands -->
+ <RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source $(PackageSources) -o "$(PackagesDir)"</RestoreCommand>
+ <BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand>
+
+ <!-- Make the build depend on restore packages -->
+ <BuildDependsOn Condition="$(RestorePackages) == 'true'">
+ RestorePackages;
+ $(BuildDependsOn);
+ </BuildDependsOn>
+
+ <!-- Make the build depend on restore packages -->
+ <BuildDependsOn Condition="$(BuildPackage) == 'true'">
+ $(BuildDependsOn);
+ BuildPackage;
+ </BuildDependsOn>
+ </PropertyGroup>
+
+ <Target Name="CheckPrerequisites">
+ <!-- Raise an error if we're unable to locate nuget.exe -->
+ <Error Condition="!Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
+ </Target>
+
+ <Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
+ <Exec Command="$(RestoreCommand)"
+ Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
+
+ <Exec Command="$(RestoreCommand)"
+ LogStandardErrorAsError="true"
+ Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
+ </Target>
+
+ <Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
+ <Exec Command="$(BuildCommand)"
+ Condition=" '$(OS)' != 'Windows_NT' " />
+
+ <Exec Command="$(BuildCommand)"
+ LogStandardErrorAsError="true"
+ Condition=" '$(OS)' == 'Windows_NT' " />
+ </Target>
+</Project>
View
@@ -3,6 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NancySelfHost", "NancySelfHost\NancySelfHost.csproj", "{9F14E4A0-F9A0-44B4-9C72-DBD51020E14F}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{A533DE8F-D4D7-4B0F-85E2-66153A5103BB}"
+ ProjectSection(SolutionItems) = preProject
+ .nuget\NuGet.exe = .nuget\NuGet.exe
+ .nuget\NuGet.targets = .nuget\NuGet.targets
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
@@ -14,6 +14,8 @@
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
@@ -35,9 +37,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="DotLiquid">
- <HintPath>..\packages\DotLiquid.1.5.4.0\lib\NET40\DotLiquid.dll</HintPath>
- </Reference>
<Reference Include="Nancy">
<HintPath>..\packages\Nancy.0.10.0\lib\net40\Nancy.dll</HintPath>
</Reference>
@@ -47,9 +46,6 @@
<Reference Include="Nancy.Hosting.Self">
<HintPath>..\packages\Nancy.Hosting.Self.0.10.0\lib\net40\Nancy.Hosting.Self.dll</HintPath>
</Reference>
- <Reference Include="Nancy.ViewEngines.DotLiquid">
- <HintPath>..\packages\Nancy.Viewengines.DotLiquid.0.10.0\lib\net40\Nancy.ViewEngines.DotLiquid.dll</HintPath>
- </Reference>
<Reference Include="Nancy.ViewEngines.Razor">
<HintPath>..\packages\Nancy.Viewengines.Razor.0.10.0\lib\net40\Nancy.ViewEngines.Razor.dll</HintPath>
</Reference>
@@ -118,16 +114,17 @@
<Content Include="assets\bootstrap\js\bootstrap.min.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
- <Content Include="Views\index.html">
+ <None Include="Views\index.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </Content>
+ </None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
xcopy /s /y "$(SolutionDir)packages\Nancy.Viewengines.Razor.0.10.0\BuildProviders\Nancy.ViewEngines.Razor.BuildProviders.dll" "$(ProjectDir)bin"
xcopy /s /y "$(SolutionDir)packages\Nancy.Viewengines.Razor.0.10.0\lib\Net40\Nancy.ViewEngines.Razor.dll" "$(ProjectDir)bin"</PostBuildEvent>
</PropertyGroup>
+ <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
@@ -1,12 +1,19 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+@{
+ ViewBag.ShowNavbar = true;
+ ViewBag.PageTitle = "";
+}
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
- <title>Some Application</title>
+ <title>@ViewBag.PageTitle</title>
<link href="@Url.Content("/assets/bootstrap/css/bootstrap.css")" rel="stylesheet"/>
@RenderSection("Header", required: false)
</head>
<body>
- <div class="navbar navbar-fixed-top">
+ @if (ViewBag.ShowNavbar)
+ {
+ <div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="@Url.Content("/")">Project name</a>
@@ -20,6 +27,7 @@
</div>
</div>
</div>
+ }
<div class="container">
<div class="content">
@RenderBody()
@@ -0,0 +1,11 @@
+@{
+ Layout = "MainLayout";
+ ViewBag.Test = "test value"; // this given compilation error
+ Model.Something = "invalid"; // this crashes whole application
+}
+
+<div class="row">
+ <div class="span12">
+ <a href="secure">Enter the "Secure Zone"!</a>
+ </div>
+</div>
@@ -1,9 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
- <title>Forms Authentication Demo</title>
-</head>
-<body>
- <a href="secure">Enter the "Secure Zone"!</a>
-</body>
-</html>
@@ -1,5 +1,6 @@
@{
Layout = "MainLayout";
+ ViewBag.ShowNavbar = false;
}
@section Header {
@@ -1,9 +1,13 @@
@{
Layout = "MainLayout";
-}
+}
-Welcome to the secure area @Model.Username ! @Model.Id
-
-<br />
-<br />
-<a href="@Url.Content("~/logout")">Logout</a>
+<div class="row">
+ <div class="span12">
+ <h1>Welcome to the secure area @Model.Username !</h1>
+ <p>Your session id: @Model.Id</p>
+ <p>
+ <a href="@Url.Content("~/logout")">Logout</a>
+ </p>
+ </div>
+</div>
@@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="DotLiquid" version="1.5.4.0" />
<package id="Nancy" version="0.10.0" />
<package id="Nancy.Authentication.Forms" version="0.10.0" />
<package id="Nancy.Hosting.Self" version="0.10.0" />
- <package id="Nancy.Viewengines.DotLiquid" version="0.10.0" />
<package id="Nancy.Viewengines.Razor" version="0.10.0" />
</packages>

0 comments on commit 8afea34

Please sign in to comment.