This repository was archived by the owner on Jun 25, 2020. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
3+ using System . Linq ;
34
45namespace Pretzel . Logic . Templating . Context
56{
@@ -22,6 +23,14 @@ public class SiteContext
2223
2324 public List < Page > Pages { get ; set ; }
2425
26+ public List < Page > Html_Pages
27+ {
28+ get
29+ {
30+ return Pages . Where ( p => p . Url != null && p . Url . EndsWith ( ".html" ) ) . ToList ( ) ;
31+ }
32+ }
33+
2534 public string Title
2635 {
2736 get
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ public Hash ToHash()
3333 var x = Hash . FromDictionary ( context . Config . ToDictionary ( ) ) ;
3434 x [ "posts" ] = context . Posts . Select ( p => p . ToHash ( ) ) . ToList ( ) ;
3535 x [ "pages" ] = context . Pages . Select ( p => p . ToHash ( ) ) . ToList ( ) ;
36+ x [ "html_pages" ] = context . Html_Pages . Select ( p => p . ToHash ( ) ) . ToList ( ) ;
3637 x [ "title" ] = context . Title ;
3738 x [ "tags" ] = context . Tags ;
3839 x [ "categories" ] = context . Categories ;
Original file line number Diff line number Diff line change @@ -132,6 +132,33 @@ public void pages_with_front_matter_get_processed()
132132 Assert . IsType < Page > ( siteContext . Pages [ 0 ] ) ;
133133 }
134134
135+ [ Fact ]
136+ public void pages_with_html_extensions_are_included_in_html_pages ( )
137+ {
138+ // arrange
139+ fileSystem . AddFile ( @"C:\TestSite\SubFolder\SomeFile.html" , new MockFileData ( ToPageContent ( "# Title" ) ) ) ;
140+
141+ // act
142+ var siteContext = generator . BuildContext ( @"C:\TestSite" , @"C:\TestSite\_site" , false ) ;
143+
144+ // assert
145+ Assert . Equal ( 1 , siteContext . Html_Pages . Count ) ;
146+ Assert . IsType < Page > ( siteContext . Html_Pages [ 0 ] ) ;
147+ }
148+
149+ [ Fact ]
150+ public void pages_without_html_extensions_are_not_included_in_html_pages ( )
151+ {
152+ // arrange
153+ fileSystem . AddFile ( @"C:\TestSite\SubFolder\SomeFile.xml" , new MockFileData ( ToPageContent ( "# Title" ) ) ) ;
154+
155+ // act
156+ var siteContext = generator . BuildContext ( @"C:\TestSite" , @"C:\TestSite\_site" , false ) ;
157+
158+ // assert
159+ Assert . Equal ( 0 , siteContext . Html_Pages . Count ) ;
160+ }
161+
135162 [ Fact ]
136163 public void site_context_includes_pages_in_same_folder ( )
137164 {
Original file line number Diff line number Diff line change @@ -2241,5 +2241,33 @@ public override ITag CreateTag()
22412241 }
22422242 }
22432243 }
2244+
2245+ public class Given_Page_Uses_Html_Pages : BakingEnvironment < LiquidEngine >
2246+ {
2247+ private const string TemplateContents = "<html><body>{{ content }}</body></html>" ;
2248+ private const string PageContents = "---\r \n layout: default \r \n ---\r \n \r \n {{ site.html_pages | size }}" ;
2249+ private const string ExpectedfileContents = "<html><body>1</body></html>" ;
2250+
2251+ public override LiquidEngine Given ( )
2252+ {
2253+ return new LiquidEngine ( ) ;
2254+ }
2255+
2256+ public override void When ( )
2257+ {
2258+ FileSystem . AddFile ( @"C:\website\_layouts\default.html" , new MockFileData ( TemplateContents ) ) ;
2259+ FileSystem . AddFile ( @"C:\website\index.html" , new MockFileData ( PageContents ) ) ;
2260+ var generator = GetSiteContextGenerator ( FileSystem ) ;
2261+ var context = generator . BuildContext ( @"C:\website\" , @"C:\website\_site" , false ) ;
2262+ Subject . FileSystem = FileSystem ;
2263+ Subject . Process ( context ) ;
2264+ }
2265+
2266+ [ Fact ]
2267+ public void The_Output_Should_Have_The_Html_Pages_Size_Value ( )
2268+ {
2269+ Assert . Equal ( ExpectedfileContents , FileSystem . File . ReadAllText ( @"C:\website\_site\index.html" ) . RemoveWhiteSpace ( ) ) ;
2270+ }
2271+ }
22442272 }
22452273}
You can’t perform that action at this time.
0 commit comments