From 93ff9e871f08a1bed5e817137bd2a7a5b3bde2c8 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Thu, 25 Mar 2021 15:13:17 -0700 Subject: [PATCH 1/4] Fix generated CSS scopes in layout views and update templates --- .../Pages/Shared/_Layout.cshtml | 2 +- .../Pages/Shared/_Layout.cshtml.css | 72 +++++++++++++++++++ .../Views/Shared/_Layout.cshtml | 2 +- .../Views/Shared/_Layout.cshtml.css} | 14 +--- .../StarterWeb-CSharp/wwwroot/css/site.css | 71 ------------------ .../Views/Shared/_Layout.cshtml | 2 +- .../Views/Shared/_Layout.cshtml.css | 72 +++++++++++++++++++ .../StarterWeb-FSharp/wwwroot/css/site.css | 71 ------------------ .../CodeGenerationIntegrationTest.cs | 39 ++++++++++ .../RazorView_Layout_WithCssScope.codegen.cs | 44 ++++++++++++ .../RazorView_Layout_WithCssScope.ir.txt | 68 ++++++++++++++++++ .../src/Extensions/ViewCssScopePass.cs | 3 +- 12 files changed, 302 insertions(+), 158 deletions(-) create mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml.css rename src/ProjectTemplates/Web.ProjectTemplates/content/{RazorPagesWeb-CSharp/wwwroot/css/site.css => StarterWeb-CSharp/Views/Shared/_Layout.cshtml.css} (73%) delete mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/wwwroot/css/site.css create mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml.css delete mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/wwwroot/css/site.css create mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_Layout_WithCssScope.codegen.cs create mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_Layout_WithCssScope.ir.txt diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml index e2a66b3b62d4..dd4ef13fd8a2 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml @@ -5,7 +5,7 @@ @ViewData["Title"] - Company.WebApplication1 - +
diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml.css b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml.css new file mode 100644 index 000000000000..1edd7e02710e --- /dev/null +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml.css @@ -0,0 +1,72 @@ +/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification +for details on configuring this project to bundle and minify static web assets. */ + +a.navbar-brand { + white-space: normal; + text-align: center; + word-break: break-all; + } + + /* Provide sufficient contrast against white background */ + a { + color: #0366d6; + } + + .btn-primary { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; + } + + .nav-pills .nav-link.active, .nav-pills .show > .nav-link { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; + } + + /* Sticky footer styles + -------------------------------------------------- */ + html { + font-size: 14px; + } + @media (min-width: 768px) { + html { + font-size: 16px; + } + } + + .border-top { + border-top: 1px solid #e5e5e5; + } + .border-bottom { + border-bottom: 1px solid #e5e5e5; + } + + .box-shadow { + box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); + } + + button.accept-policy { + font-size: 1rem; + line-height: inherit; + } + + /* Sticky footer styles + -------------------------------------------------- */ + html { + position: relative; + min-height: 100%; + } + + body { + /* Margin bottom by footer height */ + margin-bottom: 60px; + } + .footer { + position: absolute; + bottom: 0; + width: 100%; + white-space: nowrap; + line-height: 60px; /* Vertically center the text there */ + } + \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml index 560ffb88ce24..e4eaa990897f 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml @@ -5,7 +5,7 @@ @ViewData["Title"] - Company.WebApplication1 - +
diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/wwwroot/css/site.css b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml.css similarity index 73% rename from src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/wwwroot/css/site.css rename to src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml.css index e679a8ea7fb5..1d52eaa10910 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/wwwroot/css/site.css +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml.css @@ -1,7 +1,4 @@ -/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification -for details on configuring this project to bundle and minify static web assets. */ - -a.navbar-brand { +a.navbar-brand { white-space: normal; text-align: center; word-break: break-all; @@ -61,11 +58,4 @@ html { body { /* Margin bottom by footer height */ margin-bottom: 60px; -} -.footer { - position: absolute; - bottom: 0; - width: 100%; - white-space: nowrap; - line-height: 60px; /* Vertically center the text there */ -} +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/wwwroot/css/site.css b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/wwwroot/css/site.css deleted file mode 100644 index e679a8ea7fb5..000000000000 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/wwwroot/css/site.css +++ /dev/null @@ -1,71 +0,0 @@ -/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification -for details on configuring this project to bundle and minify static web assets. */ - -a.navbar-brand { - white-space: normal; - text-align: center; - word-break: break-all; -} - -/* Provide sufficient contrast against white background */ -a { - color: #0366d6; -} - -.btn-primary { - color: #fff; - background-color: #1b6ec2; - border-color: #1861ac; -} - -.nav-pills .nav-link.active, .nav-pills .show > .nav-link { - color: #fff; - background-color: #1b6ec2; - border-color: #1861ac; -} - -/* Sticky footer styles --------------------------------------------------- */ -html { - font-size: 14px; -} -@media (min-width: 768px) { - html { - font-size: 16px; - } -} - -.border-top { - border-top: 1px solid #e5e5e5; -} -.border-bottom { - border-bottom: 1px solid #e5e5e5; -} - -.box-shadow { - box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); -} - -button.accept-policy { - font-size: 1rem; - line-height: inherit; -} - -/* Sticky footer styles --------------------------------------------------- */ -html { - position: relative; - min-height: 100%; -} - -body { - /* Margin bottom by footer height */ - margin-bottom: 60px; -} -.footer { - position: absolute; - bottom: 0; - width: 100%; - white-space: nowrap; - line-height: 60px; /* Vertically center the text there */ -} diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml index b326cdff079a..da29d8a6b2ef 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml @@ -6,7 +6,7 @@ @ViewData["Title"] - Company.WebApplication1 - +
diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml.css b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml.css new file mode 100644 index 000000000000..1edd7e02710e --- /dev/null +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml.css @@ -0,0 +1,72 @@ +/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification +for details on configuring this project to bundle and minify static web assets. */ + +a.navbar-brand { + white-space: normal; + text-align: center; + word-break: break-all; + } + + /* Provide sufficient contrast against white background */ + a { + color: #0366d6; + } + + .btn-primary { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; + } + + .nav-pills .nav-link.active, .nav-pills .show > .nav-link { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; + } + + /* Sticky footer styles + -------------------------------------------------- */ + html { + font-size: 14px; + } + @media (min-width: 768px) { + html { + font-size: 16px; + } + } + + .border-top { + border-top: 1px solid #e5e5e5; + } + .border-bottom { + border-bottom: 1px solid #e5e5e5; + } + + .box-shadow { + box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); + } + + button.accept-policy { + font-size: 1rem; + line-height: inherit; + } + + /* Sticky footer styles + -------------------------------------------------- */ + html { + position: relative; + min-height: 100%; + } + + body { + /* Margin bottom by footer height */ + margin-bottom: 60px; + } + .footer { + position: absolute; + bottom: 0; + width: 100%; + white-space: nowrap; + line-height: 60px; /* Vertically center the text there */ + } + \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/wwwroot/css/site.css b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/wwwroot/css/site.css deleted file mode 100644 index e679a8ea7fb5..000000000000 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/wwwroot/css/site.css +++ /dev/null @@ -1,71 +0,0 @@ -/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification -for details on configuring this project to bundle and minify static web assets. */ - -a.navbar-brand { - white-space: normal; - text-align: center; - word-break: break-all; -} - -/* Provide sufficient contrast against white background */ -a { - color: #0366d6; -} - -.btn-primary { - color: #fff; - background-color: #1b6ec2; - border-color: #1861ac; -} - -.nav-pills .nav-link.active, .nav-pills .show > .nav-link { - color: #fff; - background-color: #1b6ec2; - border-color: #1861ac; -} - -/* Sticky footer styles --------------------------------------------------- */ -html { - font-size: 14px; -} -@media (min-width: 768px) { - html { - font-size: 16px; - } -} - -.border-top { - border-top: 1px solid #e5e5e5; -} -.border-bottom { - border-bottom: 1px solid #e5e5e5; -} - -.box-shadow { - box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); -} - -button.accept-policy { - font-size: 1rem; - line-height: inherit; -} - -/* Sticky footer styles --------------------------------------------------- */ -html { - position: relative; - min-height: 100%; -} - -body { - /* Margin bottom by footer height */ - margin-bottom: 60px; -} -.footer { - position: absolute; - bottom: 0; - width: 100%; - white-space: nowrap; - line-height: 60px; /* Vertically center the text there */ -} diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 49d5f463f7c2..9c5f7543a7fe 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -609,6 +609,45 @@ public class FormTagHelper : {typeof(TagHelper).FullName} CompileToAssembly(generated); } + [Fact] + public void RazorView_Layout_WithCssScope() + { + // Arrange + AddCSharpSyntaxTree($@" +[{typeof(HtmlTargetElementAttribute).FullName}({"\"all\""})] +public class AllTagHelper : {typeof(TagHelper).FullName} +{{ + public string Bar {{ get; set; }} +}} +[{typeof(HtmlTargetElementAttribute).FullName}({"\"form\""})] +public class FormTagHelper : {typeof(TagHelper).FullName} +{{ +}} +"); + + // Act + // This test case attempts to use all syntaxes that might interact with auto-generated attributes + var generated = CompileToCSharp(@" + + + + + + @ViewData[""Title""] - Test layout component + + +

This is a body.

+ + +", cssScope: "TestCssScope"); + + // Assert + var intermediate = generated.CodeDocument.GetDocumentIntermediateNode(); + var csharp = generated.CodeDocument.GetCSharpDocument(); + AssertDocumentNodeMatchesBaseline(intermediate); + AssertCSharpDocumentMatchesBaseline(csharp); + CompileToAssembly(generated); + } #endregion #region DesignTime diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_Layout_WithCssScope.codegen.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_Layout_WithCssScope.codegen.cs new file mode 100644 index 000000000000..282f05793985 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_Layout_WithCssScope.codegen.cs @@ -0,0 +1,44 @@ +#pragma checksum "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "aa3144e1672369f198372f95e6bbee5ac485c5c3" +// +#pragma warning disable 1591 +[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test), @"mvc.1.0.view", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] +namespace AspNetCore +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Rendering; + using Microsoft.AspNetCore.Mvc.ViewFeatures; + [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"aa3144e1672369f198372f95e6bbee5ac485c5c3", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + WriteLiteral("\r\n\r\n\r\n\r\n \r\n \r\n "); +#nullable restore +#line 7 "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" + Write(ViewData["Title"]); + +#line default +#line hidden +#nullable disable + WriteLiteral(" - Test layout component\r\n\r\n\r\n

This is a body.

\r\n\r\n\r\n"); + } + #pragma warning restore 1998 + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_Layout_WithCssScope.ir.txt b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_Layout_WithCssScope.ir.txt new file mode 100644 index 000000000000..c7db330e79b4 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_Layout_WithCssScope.ir.txt @@ -0,0 +1,68 @@ +Document - + RazorCompiledItemAttribute - + NamespaceDeclaration - - AspNetCore + UsingDirective - (1:0,1 [14] ) - System + UsingDirective - (16:1,1 [34] ) - System.Collections.Generic + UsingDirective - (51:2,1 [19] ) - System.Linq + UsingDirective - (71:3,1 [30] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [32] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [42] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [45] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + RazorSourceChecksumAttribute - + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + HtmlContent - (0:0,0 [164] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (0:0,0 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (2:1,0 [17] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (19:2,0 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (35:2,16 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (37:3,0 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (43:3,6 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (49:4,4 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (73:4,28 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (79:5,4 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (151:5,76 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (157:6,4 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + CSharpExpression - (165:6,12 [17] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (165:6,12 [17] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - CSharp - ViewData["Title"] + HtmlContent - (182:6,29 [97] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (182:6,29 [24] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \-Test layout component + LazyIntermediateToken - (206:6,53 [8] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (214:6,61 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (216:7,0 [7] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (223:7,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (225:8,0 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (231:8,6 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (237:9,4 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (240:9,7 [15] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - This is a body. + LazyIntermediateToken - (255:9,22 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (259:9,26 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (261:10,0 [7] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (268:10,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (270:11,0 [7] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (277:11,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs index c17844a438bb..ae20b386c243 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs @@ -42,7 +42,8 @@ private void ProcessElement(HtmlContentIntermediateNode node, string cssScope) if (child is IntermediateToken token && token.IsHtml) { var content = token.Content; - if (content.StartsWith("<", StringComparison.Ordinal) && !content.StartsWith(" Date: Thu, 25 Mar 2021 16:01:20 -0700 Subject: [PATCH 2/4] Update template baselines --- .../Pages/Shared/_Layout.cshtml | 2 +- .../Pages/Shared/_Layout.cshtml.css | 72 ------------------- .../RazorPagesWeb-CSharp/wwwroot/css/site.css | 71 ++++++++++++++++++ .../Views/Shared/_Layout.cshtml.css | 12 +++- .../test/template-baselines.json | 14 ++-- 5 files changed, 90 insertions(+), 81 deletions(-) delete mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml.css create mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/wwwroot/css/site.css diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml index dd4ef13fd8a2..e2a66b3b62d4 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml @@ -5,7 +5,7 @@ @ViewData["Title"] - Company.WebApplication1 - +
diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml.css b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml.css deleted file mode 100644 index 1edd7e02710e..000000000000 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml.css +++ /dev/null @@ -1,72 +0,0 @@ -/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification -for details on configuring this project to bundle and minify static web assets. */ - -a.navbar-brand { - white-space: normal; - text-align: center; - word-break: break-all; - } - - /* Provide sufficient contrast against white background */ - a { - color: #0366d6; - } - - .btn-primary { - color: #fff; - background-color: #1b6ec2; - border-color: #1861ac; - } - - .nav-pills .nav-link.active, .nav-pills .show > .nav-link { - color: #fff; - background-color: #1b6ec2; - border-color: #1861ac; - } - - /* Sticky footer styles - -------------------------------------------------- */ - html { - font-size: 14px; - } - @media (min-width: 768px) { - html { - font-size: 16px; - } - } - - .border-top { - border-top: 1px solid #e5e5e5; - } - .border-bottom { - border-bottom: 1px solid #e5e5e5; - } - - .box-shadow { - box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); - } - - button.accept-policy { - font-size: 1rem; - line-height: inherit; - } - - /* Sticky footer styles - -------------------------------------------------- */ - html { - position: relative; - min-height: 100%; - } - - body { - /* Margin bottom by footer height */ - margin-bottom: 60px; - } - .footer { - position: absolute; - bottom: 0; - width: 100%; - white-space: nowrap; - line-height: 60px; /* Vertically center the text there */ - } - \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/wwwroot/css/site.css b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/wwwroot/css/site.css new file mode 100644 index 000000000000..e679a8ea7fb5 --- /dev/null +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/wwwroot/css/site.css @@ -0,0 +1,71 @@ +/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification +for details on configuring this project to bundle and minify static web assets. */ + +a.navbar-brand { + white-space: normal; + text-align: center; + word-break: break-all; +} + +/* Provide sufficient contrast against white background */ +a { + color: #0366d6; +} + +.btn-primary { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; +} + +.nav-pills .nav-link.active, .nav-pills .show > .nav-link { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; +} + +/* Sticky footer styles +-------------------------------------------------- */ +html { + font-size: 14px; +} +@media (min-width: 768px) { + html { + font-size: 16px; + } +} + +.border-top { + border-top: 1px solid #e5e5e5; +} +.border-bottom { + border-bottom: 1px solid #e5e5e5; +} + +.box-shadow { + box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); +} + +button.accept-policy { + font-size: 1rem; + line-height: inherit; +} + +/* Sticky footer styles +-------------------------------------------------- */ +html { + position: relative; + min-height: 100%; +} + +body { + /* Margin bottom by footer height */ + margin-bottom: 60px; +} +.footer { + position: absolute; + bottom: 0; + width: 100%; + white-space: nowrap; + line-height: 60px; /* Vertically center the text there */ +} diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml.css b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml.css index 1d52eaa10910..c80313cb5bdd 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml.css +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml.css @@ -1,4 +1,7 @@ -a.navbar-brand { +/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification +for details on configuring this project to bundle and minify static web assets. */ + +a.navbar-brand { white-space: normal; text-align: center; word-break: break-all; @@ -58,4 +61,11 @@ html { body { /* Margin bottom by footer height */ margin-bottom: 60px; +} +.footer { + position: absolute; + bottom: 0; + width: 100%; + white-space: nowrap; + line-height: 60px; /* Vertically center the text there */ } \ No newline at end of file diff --git a/src/ProjectTemplates/test/template-baselines.json b/src/ProjectTemplates/test/template-baselines.json index 9e36b3eed22e..bb63bfaa84f9 100644 --- a/src/ProjectTemplates/test/template-baselines.json +++ b/src/ProjectTemplates/test/template-baselines.json @@ -484,10 +484,10 @@ "Views/Home/Privacy.cshtml", "Views/Shared/Error.cshtml", "Views/Shared/_Layout.cshtml", + "Views/Shared/_Layout.cshtml.css", "Views/Shared/_LoginPartial.cshtml", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", - "wwwroot/css/site.css", "wwwroot/js/site.js", "wwwroot/lib/bootstrap/LICENSE", "wwwroot/lib/bootstrap/dist/css/bootstrap.css", @@ -542,9 +542,9 @@ "Views/Home/Privacy.cshtml", "Views/Shared/Error.cshtml", "Views/Shared/_Layout.cshtml", + "Views/Shared/_Layout.cshtml.css", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", - "wwwroot/css/site.css", "wwwroot/js/site.js", "wwwroot/lib/bootstrap/LICENSE", "wwwroot/lib/bootstrap/dist/css/bootstrap.css", @@ -599,10 +599,10 @@ "Views/Home/Privacy.cshtml", "Views/Shared/Error.cshtml", "Views/Shared/_Layout.cshtml", + "Views/Shared/_Layout.cshtml.css", "Views/Shared/_LoginPartial.cshtml", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", - "wwwroot/css/site.css", "wwwroot/js/site.js", "wwwroot/lib/bootstrap/LICENSE", "wwwroot/lib/bootstrap/dist/css/bootstrap.css", @@ -657,10 +657,10 @@ "Views/Home/Privacy.cshtml", "Views/Shared/Error.cshtml", "Views/Shared/_Layout.cshtml", + "Views/Shared/_Layout.cshtml.css", "Views/Shared/_LoginPartial.cshtml", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", - "wwwroot/css/site.css", "wwwroot/js/site.js", "wwwroot/lib/bootstrap/LICENSE", "wwwroot/lib/bootstrap/dist/css/bootstrap.css", @@ -715,9 +715,9 @@ "Views/Home/Privacy.cshtml", "Views/Shared/Error.cshtml", "Views/Shared/_Layout.cshtml", + "Views/Shared/_Layout.cshtml.css", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", - "wwwroot/css/site.css", "wwwroot/js/site.js", "wwwroot/lib/bootstrap/LICENSE", "wwwroot/lib/bootstrap/dist/css/bootstrap.css", @@ -772,10 +772,10 @@ "Views/Home/Privacy.cshtml", "Views/Shared/Error.cshtml", "Views/Shared/_Layout.cshtml", + "Views/Shared/_Layout.cshtml.css", "Views/Shared/_LoginPartial.cshtml", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", - "wwwroot/css/site.css", "wwwroot/js/site.js", "wwwroot/lib/bootstrap/LICENSE", "wwwroot/lib/bootstrap/dist/css/bootstrap.css", @@ -830,9 +830,9 @@ "Views/Home/Privacy.cshtml", "Views/Shared/Error.cshtml", "Views/Shared/_Layout.cshtml", + "Views/Shared/_Layout.cshtml.css", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", - "wwwroot/css/site.css", "wwwroot/js/site.js", "wwwroot/lib/bootstrap/LICENSE", "wwwroot/lib/bootstrap/dist/css/bootstrap.css", From c93ae1909c32369fda5ee86575c0949e6e84387c Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Sat, 27 Mar 2021 15:50:33 -0700 Subject: [PATCH 3/4] Enabled scoped CSS for MVC template tests --- src/ProjectTemplates/test/MvcTemplateTest.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ProjectTemplates/test/MvcTemplateTest.cs b/src/ProjectTemplates/test/MvcTemplateTest.cs index 1718059effa9..a10f67180af7 100644 --- a/src/ProjectTemplates/test/MvcTemplateTest.cs +++ b/src/ProjectTemplates/test/MvcTemplateTest.cs @@ -45,6 +45,9 @@ public ITestOutputHelper Output private async Task MvcTemplateCore(string languageOverride) { + // Additional arguments are needed. See: https://github.com/dotnet/aspnetcore/issues/24278 + Environment.SetEnvironmentVariable("EnableDefaultScopedCssItems", "true"); + var project = await ProjectFactory.GetOrCreateProject("mvcnoauth" + (languageOverride == "F#" ? "fsharp" : "csharp"), Output); var createResult = await project.RunDotNetNewAsync("mvc", language: languageOverride); @@ -121,6 +124,9 @@ private async Task MvcTemplateCore(string languageOverride) [SkipOnHelix("Cert failure, https://github.com/dotnet/aspnetcore/issues/28090", Queues = "All.OSX;" + HelixConstants.Windows10Arm64 + HelixConstants.DebianArm64)] public async Task MvcTemplate_IndividualAuth(bool useLocalDB) { + // Additional arguments are needed. See: https://github.com/dotnet/aspnetcore/issues/24278 + Environment.SetEnvironmentVariable("EnableDefaultScopedCssItems", "true"); + var project = await ProjectFactory.GetOrCreateProject("mvcindividual" + (useLocalDB ? "uld" : ""), Output); var createResult = await project.RunDotNetNewAsync("mvc", auth: "Individual", useLocalDB: useLocalDB); From b51262dc73f3abfdbcb4bcc396791c301cb8b6c7 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Tue, 30 Mar 2021 11:50:34 -0700 Subject: [PATCH 4/4] Bring back static CSS file --- .../Views/Shared/_Layout.cshtml | 1 + .../Views/Shared/_Layout.cshtml.css | 20 ------------------ .../StarterWeb-CSharp/wwwroot/css/site.css | 21 +++++++++++++++++++ .../Views/Shared/_Layout.cshtml | 1 + .../Views/Shared/_Layout.cshtml.css | 20 ------------------ .../StarterWeb-FSharp/wwwroot/css/site.css | 21 +++++++++++++++++++ .../test/template-baselines.json | 7 +++++++ 7 files changed, 51 insertions(+), 40 deletions(-) create mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/wwwroot/css/site.css create mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/wwwroot/css/site.css diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml index e4eaa990897f..79f34bc21167 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml @@ -5,6 +5,7 @@ @ViewData["Title"] - Company.WebApplication1 + diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml.css b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml.css index c80313cb5bdd..557867a54f99 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml.css +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml.css @@ -24,17 +24,6 @@ a { border-color: #1861ac; } -/* Sticky footer styles --------------------------------------------------- */ -html { - font-size: 14px; -} -@media (min-width: 768px) { - html { - font-size: 16px; - } -} - .border-top { border-top: 1px solid #e5e5e5; } @@ -53,15 +42,6 @@ button.accept-policy { /* Sticky footer styles -------------------------------------------------- */ -html { - position: relative; - min-height: 100%; -} - -body { - /* Margin bottom by footer height */ - margin-bottom: 60px; -} .footer { position: absolute; bottom: 0; diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/wwwroot/css/site.css b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/wwwroot/css/site.css new file mode 100644 index 000000000000..3b1e20a04d53 --- /dev/null +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/wwwroot/css/site.css @@ -0,0 +1,21 @@ +html { + font-size: 14px; + } + @media (min-width: 768px) { + html { + font-size: 16px; + } + } + + /* Sticky footer styles + -------------------------------------------------- */ + html { + position: relative; + min-height: 100%; + } + + body { + /* Margin bottom by footer height */ + margin-bottom: 60px; + } + \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml index da29d8a6b2ef..00e46209a640 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml @@ -6,6 +6,7 @@ @ViewData["Title"] - Company.WebApplication1 + diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml.css b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml.css index 1edd7e02710e..08f5018416a9 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml.css +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml.css @@ -24,17 +24,6 @@ a.navbar-brand { border-color: #1861ac; } - /* Sticky footer styles - -------------------------------------------------- */ - html { - font-size: 14px; - } - @media (min-width: 768px) { - html { - font-size: 16px; - } - } - .border-top { border-top: 1px solid #e5e5e5; } @@ -53,15 +42,6 @@ a.navbar-brand { /* Sticky footer styles -------------------------------------------------- */ - html { - position: relative; - min-height: 100%; - } - - body { - /* Margin bottom by footer height */ - margin-bottom: 60px; - } .footer { position: absolute; bottom: 0; diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/wwwroot/css/site.css b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/wwwroot/css/site.css new file mode 100644 index 000000000000..3b1e20a04d53 --- /dev/null +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/wwwroot/css/site.css @@ -0,0 +1,21 @@ +html { + font-size: 14px; + } + @media (min-width: 768px) { + html { + font-size: 16px; + } + } + + /* Sticky footer styles + -------------------------------------------------- */ + html { + position: relative; + min-height: 100%; + } + + body { + /* Margin bottom by footer height */ + margin-bottom: 60px; + } + \ No newline at end of file diff --git a/src/ProjectTemplates/test/template-baselines.json b/src/ProjectTemplates/test/template-baselines.json index bb63bfaa84f9..100b5a1f6be4 100644 --- a/src/ProjectTemplates/test/template-baselines.json +++ b/src/ProjectTemplates/test/template-baselines.json @@ -488,6 +488,7 @@ "Views/Shared/_LoginPartial.cshtml", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", + "wwwroot/css/site.css", "wwwroot/js/site.js", "wwwroot/lib/bootstrap/LICENSE", "wwwroot/lib/bootstrap/dist/css/bootstrap.css", @@ -545,6 +546,7 @@ "Views/Shared/_Layout.cshtml.css", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", + "wwwroot/css/site.css", "wwwroot/js/site.js", "wwwroot/lib/bootstrap/LICENSE", "wwwroot/lib/bootstrap/dist/css/bootstrap.css", @@ -603,6 +605,7 @@ "Views/Shared/_LoginPartial.cshtml", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", + "wwwroot/css/site.css", "wwwroot/js/site.js", "wwwroot/lib/bootstrap/LICENSE", "wwwroot/lib/bootstrap/dist/css/bootstrap.css", @@ -661,6 +664,7 @@ "Views/Shared/_LoginPartial.cshtml", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", + "wwwroot/css/site.css", "wwwroot/js/site.js", "wwwroot/lib/bootstrap/LICENSE", "wwwroot/lib/bootstrap/dist/css/bootstrap.css", @@ -718,6 +722,7 @@ "Views/Shared/_Layout.cshtml.css", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", + "wwwroot/css/site.css", "wwwroot/js/site.js", "wwwroot/lib/bootstrap/LICENSE", "wwwroot/lib/bootstrap/dist/css/bootstrap.css", @@ -776,6 +781,7 @@ "Views/Shared/_LoginPartial.cshtml", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", + "wwwroot/css/site.css", "wwwroot/js/site.js", "wwwroot/lib/bootstrap/LICENSE", "wwwroot/lib/bootstrap/dist/css/bootstrap.css", @@ -833,6 +839,7 @@ "Views/Shared/_Layout.cshtml.css", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", + "wwwroot/css/site.css", "wwwroot/js/site.js", "wwwroot/lib/bootstrap/LICENSE", "wwwroot/lib/bootstrap/dist/css/bootstrap.css",