Skip to content

Commit 93ff9e8

Browse files
committed
Fix generated CSS scopes in layout views and update templates
1 parent 8d79c95 commit 93ff9e8

File tree

12 files changed

+302
-158
lines changed

12 files changed

+302
-158
lines changed

src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>@ViewData["Title"] - Company.WebApplication1</title>
77
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
8-
<link rel="stylesheet" href="~/css/site.css" />
8+
<link rel="stylesheet" href="~/Company.WebApplication1.styles.css" />
99
</head>
1010
<body>
1111
<header>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2+
for details on configuring this project to bundle and minify static web assets. */
3+
4+
a.navbar-brand {
5+
white-space: normal;
6+
text-align: center;
7+
word-break: break-all;
8+
}
9+
10+
/* Provide sufficient contrast against white background */
11+
a {
12+
color: #0366d6;
13+
}
14+
15+
.btn-primary {
16+
color: #fff;
17+
background-color: #1b6ec2;
18+
border-color: #1861ac;
19+
}
20+
21+
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
22+
color: #fff;
23+
background-color: #1b6ec2;
24+
border-color: #1861ac;
25+
}
26+
27+
/* Sticky footer styles
28+
-------------------------------------------------- */
29+
html {
30+
font-size: 14px;
31+
}
32+
@media (min-width: 768px) {
33+
html {
34+
font-size: 16px;
35+
}
36+
}
37+
38+
.border-top {
39+
border-top: 1px solid #e5e5e5;
40+
}
41+
.border-bottom {
42+
border-bottom: 1px solid #e5e5e5;
43+
}
44+
45+
.box-shadow {
46+
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
47+
}
48+
49+
button.accept-policy {
50+
font-size: 1rem;
51+
line-height: inherit;
52+
}
53+
54+
/* Sticky footer styles
55+
-------------------------------------------------- */
56+
html {
57+
position: relative;
58+
min-height: 100%;
59+
}
60+
61+
body {
62+
/* Margin bottom by footer height */
63+
margin-bottom: 60px;
64+
}
65+
.footer {
66+
position: absolute;
67+
bottom: 0;
68+
width: 100%;
69+
white-space: nowrap;
70+
line-height: 60px; /* Vertically center the text there */
71+
}
72+

src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>@ViewData["Title"] - Company.WebApplication1</title>
77
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
8-
<link rel="stylesheet" href="~/css/site.css" />
8+
<link rel="stylesheet" href="~/Company.WebApplication1.styles.css" />
99
</head>
1010
<body>
1111
<header>

src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/wwwroot/css/site.css renamed to src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml.css

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2-
for details on configuring this project to bundle and minify static web assets. */
3-
4-
a.navbar-brand {
1+
a.navbar-brand {
52
white-space: normal;
63
text-align: center;
74
word-break: break-all;
@@ -61,11 +58,4 @@ html {
6158
body {
6259
/* Margin bottom by footer height */
6360
margin-bottom: 60px;
64-
}
65-
.footer {
66-
position: absolute;
67-
bottom: 0;
68-
width: 100%;
69-
white-space: nowrap;
70-
line-height: 60px; /* Vertically center the text there */
71-
}
61+
}

src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/wwwroot/css/site.css

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<title>@ViewData["Title"] - Company.WebApplication1</title>
77

88
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
9-
<link rel="stylesheet" href="~/css/site.css" />
9+
<link rel="stylesheet" href="~/Company.WebApplication1.css" />
1010
</head>
1111
<body>
1212
<header>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2+
for details on configuring this project to bundle and minify static web assets. */
3+
4+
a.navbar-brand {
5+
white-space: normal;
6+
text-align: center;
7+
word-break: break-all;
8+
}
9+
10+
/* Provide sufficient contrast against white background */
11+
a {
12+
color: #0366d6;
13+
}
14+
15+
.btn-primary {
16+
color: #fff;
17+
background-color: #1b6ec2;
18+
border-color: #1861ac;
19+
}
20+
21+
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
22+
color: #fff;
23+
background-color: #1b6ec2;
24+
border-color: #1861ac;
25+
}
26+
27+
/* Sticky footer styles
28+
-------------------------------------------------- */
29+
html {
30+
font-size: 14px;
31+
}
32+
@media (min-width: 768px) {
33+
html {
34+
font-size: 16px;
35+
}
36+
}
37+
38+
.border-top {
39+
border-top: 1px solid #e5e5e5;
40+
}
41+
.border-bottom {
42+
border-bottom: 1px solid #e5e5e5;
43+
}
44+
45+
.box-shadow {
46+
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
47+
}
48+
49+
button.accept-policy {
50+
font-size: 1rem;
51+
line-height: inherit;
52+
}
53+
54+
/* Sticky footer styles
55+
-------------------------------------------------- */
56+
html {
57+
position: relative;
58+
min-height: 100%;
59+
}
60+
61+
body {
62+
/* Margin bottom by footer height */
63+
margin-bottom: 60px;
64+
}
65+
.footer {
66+
position: absolute;
67+
bottom: 0;
68+
width: 100%;
69+
white-space: nowrap;
70+
line-height: 60px; /* Vertically center the text there */
71+
}
72+

src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/wwwroot/css/site.css

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,45 @@ public class FormTagHelper : {typeof(TagHelper).FullName}
609609
CompileToAssembly(generated);
610610
}
611611

612+
[Fact]
613+
public void RazorView_Layout_WithCssScope()
614+
{
615+
// Arrange
616+
AddCSharpSyntaxTree($@"
617+
[{typeof(HtmlTargetElementAttribute).FullName}({"\"all\""})]
618+
public class AllTagHelper : {typeof(TagHelper).FullName}
619+
{{
620+
public string Bar {{ get; set; }}
621+
}}
622+
[{typeof(HtmlTargetElementAttribute).FullName}({"\"form\""})]
623+
public class FormTagHelper : {typeof(TagHelper).FullName}
624+
{{
625+
}}
626+
");
627+
628+
// Act
629+
// This test case attempts to use all syntaxes that might interact with auto-generated attributes
630+
var generated = CompileToCSharp(@"
631+
<!DOCTYPE html>
632+
<html lang=""en"">
633+
<head>
634+
<meta charset=""utf-8"" />
635+
<meta name=""viewport"" content=""width=device-width, initial-scale=1.0"" />
636+
<title>@ViewData[""Title""] - Test layout component</title>
637+
</head>
638+
<body>
639+
<p>This is a body.</p>
640+
</body>
641+
</html>
642+
", cssScope: "TestCssScope");
643+
644+
// Assert
645+
var intermediate = generated.CodeDocument.GetDocumentIntermediateNode();
646+
var csharp = generated.CodeDocument.GetCSharpDocument();
647+
AssertDocumentNodeMatchesBaseline(intermediate);
648+
AssertCSharpDocumentMatchesBaseline(csharp);
649+
CompileToAssembly(generated);
650+
}
612651
#endregion
613652

614653
#region DesignTime

0 commit comments

Comments
 (0)