A little housekeeping
- Simplified user message generation (Info is default level) - Removed paket and FAKE files, as we're using the default .NET Core build system
This commit is contained in:
		
							parent
							
								
									739fe3ff9c
								
							
						
					
					
						commit
						47266817f6
					
				
										
											Binary file not shown.
										
									
								
							| @ -16,15 +16,15 @@ type PageModule (data : IMyWebLogData, clock : IClock) as this = | ||||
| 
 | ||||
|   do | ||||
|     this.Get    ("/pages",            fun _ -> this.PageList   ()) | ||||
|     this.Get    ("/page/{id}/edit",   fun parms -> this.EditPage   (downcast parms)) | ||||
|     this.Post   ("/page/{id}/edit",   fun parms -> this.SavePage   (downcast parms)) | ||||
|     this.Delete ("/page/{id}/delete", fun parms -> this.DeletePage (downcast parms)) | ||||
|     this.Get    ("/page/{id}/edit",   fun p -> this.EditPage   (downcast p)) | ||||
|     this.Post   ("/page/{id}/edit",   fun p -> this.SavePage   (downcast p)) | ||||
|     this.Delete ("/page/{id}/delete", fun p -> this.DeletePage (downcast p)) | ||||
| 
 | ||||
|   /// List all pages | ||||
|   member this.PageList () : obj = | ||||
|     this.RequiresAccessLevel AuthorizationLevel.Administrator | ||||
|     let model = | ||||
|       PagesModel(this.Context, this.WebLog, findAllPages data this.WebLog.Id | ||||
|       PagesModel (this.Context, this.WebLog, findAllPages data this.WebLog.Id | ||||
|                                              |> List.map (fun p -> PageForDisplay (this.WebLog, p))) | ||||
|     model.PageTitle <- Strings.get "Pages" | ||||
|     upcast this.View.["admin/page/list", model] | ||||
| @ -74,12 +74,12 @@ type PageModule (data : IMyWebLogData, clock : IClock) as this = | ||||
|             } | ||||
|           |> savePage data | ||||
|         let model = MyWebLogModel (this.Context, this.WebLog) | ||||
|         model.AddMessage | ||||
|           { UserMessage.Empty with | ||||
|             Level   = Level.Info | ||||
|               Message = System.String.Format | ||||
|                           (Strings.get "MsgPageEditSuccess", | ||||
|                           Strings.get (match pageId with "new" -> "Added" | _ -> "Updated")) } | ||||
|         |> model.AddMessage | ||||
|                             Strings.get (match pageId with "new" -> "Added" | _ -> "Updated")) | ||||
|             } | ||||
|         this.Redirect (sprintf "/page/%s/edit" pId) model | ||||
|     | _ -> this.NotFound () | ||||
| 
 | ||||
| @ -92,9 +92,6 @@ type PageModule (data : IMyWebLogData, clock : IClock) as this = | ||||
|     | Some page -> | ||||
|         deletePage data page.WebLogId page.Id | ||||
|         let model = MyWebLogModel (this.Context, this.WebLog) | ||||
|         { UserMessage.Empty with | ||||
|             Level   = Level.Info | ||||
|             Message = Strings.get "MsgPageDeleted" } | ||||
|         |> model.AddMessage | ||||
|         model.AddMessage { UserMessage.Empty with Message = Strings.get "MsgPageDeleted" } | ||||
|         this.Redirect "/pages" model | ||||
|     | _ -> this.NotFound () | ||||
|  | ||||
| @ -23,12 +23,14 @@ type NewsItem = | ||||
|   } | ||||
| 
 | ||||
| /// Routes dealing with posts (including the home page, /tag, /category, RSS, and catch-all routes) | ||||
| type PostModule(data : IMyWebLogData, clock : IClock) as this = | ||||
| type PostModule (data : IMyWebLogData, clock : IClock) as this = | ||||
|   inherit NancyModule () | ||||
| 
 | ||||
|   /// Get the page number from the dictionary | ||||
|   let getPage (parameters : DynamicDictionary) = | ||||
|     match parameters.ContainsKey "page" with true -> System.Int32.Parse (parameters.["page"].ToString ()) | _ -> 1 | ||||
|     match parameters.ContainsKey "page" with | ||||
|     | true -> match System.Int32.TryParse (parameters.["page"].ToString ()) with true, pg -> pg | _ -> 1 | ||||
|     | _ -> 1 | ||||
| 
 | ||||
|   /// Convert a list of posts to a list of posts for display | ||||
|   let forDisplay posts = posts |> List.map (fun post -> PostForDisplay (this.WebLog, post)) | ||||
| @ -37,23 +39,23 @@ type PostModule(data : IMyWebLogData, clock : IClock) as this = | ||||
|   let generateFeed format : obj = | ||||
|     let myChannelFeed channelTitle channelLink channelDescription (items : NewsItem list) = | ||||
|       let xn = XName.Get | ||||
|       let elem name (valu:string) = XElement (xn name, valu) | ||||
|       let elem name (valu : string) = XElement (xn name, valu) | ||||
|       let elems = | ||||
|         items | ||||
|         |> List.sortBy (fun i -> i.ReleaseDate)  | ||||
|         |> List.map (fun i -> | ||||
|             XElement | ||||
|               (xn "item", | ||||
|             XElement ( | ||||
|                xn "item", | ||||
|                elem "title" (System.Net.WebUtility.HtmlEncode i.Title), | ||||
|                elem "link" i.Link, | ||||
|                elem "guid" i.Link, | ||||
|                elem "pubDate" (i.ReleaseDate.ToString "r"), | ||||
|                elem "description" (System.Net.WebUtility.HtmlEncode i.Description) | ||||
|             )) | ||||
|       XDocument( | ||||
|         XDeclaration("1.0", "utf-8", "yes"), | ||||
|         XElement | ||||
|           (xn "rss", | ||||
|       XDocument ( | ||||
|         XDeclaration ("1.0", "utf-8", "yes"), | ||||
|         XElement ( | ||||
|            xn "rss", | ||||
|            XAttribute (xn "version", "2.0"), | ||||
|            elem "title" channelTitle, | ||||
|            elem "link" channelLink, | ||||
| @ -61,8 +63,8 @@ type PostModule(data : IMyWebLogData, clock : IClock) as this = | ||||
|            elem "language" "en-us", | ||||
|            XElement (xn "channel", elems)) | ||||
|         |> box) | ||||
|       |> box | ||||
|     let schemeAndUrl = sprintf "%s://%s" this.Request.Url.Scheme this.WebLog.UrlBase | ||||
|     let feed = | ||||
|       findFeedPosts data this.WebLog.Id 10 | ||||
|       |> List.map (fun (post, _) -> | ||||
|           { Title       = post.Title | ||||
| @ -71,6 +73,11 @@ type PostModule(data : IMyWebLogData, clock : IClock) as this = | ||||
|             Description = post.Text | ||||
|             }) | ||||
|       |> myChannelFeed this.WebLog.Name schemeAndUrl this.WebLog.Subtitle | ||||
|     let stream = new IO.MemoryStream () | ||||
|     Xml.XmlWriter.Create stream |> feed.Save | ||||
|     //|> match format with "atom" -> feed.SaveAsAtom10 | _ -> feed.SaveAsRss20 | ||||
|     stream.Position <- 0L | ||||
|     upcast this.Response.FromStream (stream, sprintf "application/%s+xml" format) | ||||
|     // TODO: how to return this? | ||||
| 
 | ||||
|     (*  | ||||
| @ -246,7 +253,8 @@ type PostModule(data : IMyWebLogData, clock : IClock) as this = | ||||
|     match postId with "new" -> Some Post.Empty | _ -> tryFindPost data this.WebLog.Id postId | ||||
|     |> function | ||||
|     | Some post -> | ||||
|         let rev = match post.Revisions | ||||
|         let rev = | ||||
|           match post.Revisions | ||||
|                 |> List.sortByDescending (fun r -> r.AsOf) | ||||
|                 |> List.tryHead with | ||||
|           | Some r -> r | ||||
| @ -270,11 +278,13 @@ type PostModule(data : IMyWebLogData, clock : IClock) as this = | ||||
|     |> function | ||||
|     | Some p -> | ||||
|         let justPublished = p.PublishedOn = 0L && form.PublishNow | ||||
|         let post = match postId with | ||||
|                    | "new" -> { p with | ||||
|         let post = | ||||
|           match postId with | ||||
|           | "new" -> | ||||
|               { p with | ||||
|                   WebLogId = this.WebLog.Id | ||||
|                                   AuthorId = (this.Request.PersistableSession.GetOrDefault<User> | ||||
|                                                 (Keys.User, User.Empty)).Id } | ||||
|                   AuthorId = this.Request.PersistableSession.GetOrDefault<User>(Keys.User, User.Empty).Id | ||||
|                 } | ||||
|           | _ -> p | ||||
|         let pId = | ||||
|           { post with | ||||
| @ -296,12 +306,12 @@ type PostModule(data : IMyWebLogData, clock : IClock) as this = | ||||
|                               Text       = form.Text } :: post.Revisions } | ||||
|           |> savePost data | ||||
|         let model = MyWebLogModel(this.Context, this.WebLog) | ||||
|         model.AddMessage | ||||
|           { UserMessage.Empty with | ||||
|             Level   = Level.Info | ||||
|               Message = System.String.Format | ||||
|                           (Strings.get "MsgPostEditSuccess", | ||||
|                             Strings.get (match postId with "new" -> "Added" | _ -> "Updated"), | ||||
|                           (match justPublished with true -> Strings.get "AndPublished" | _ -> "")) } | ||||
|         |> model.AddMessage | ||||
|                             (match justPublished with true -> Strings.get "AndPublished" | _ -> "")) | ||||
|             } | ||||
|         this.Redirect (sprintf "/post/%s/edit" pId) model | ||||
|     | _ -> this.NotFound () | ||||
|  | ||||
| @ -1,14 +0,0 @@ | ||||
| @echo off | ||||
| cls | ||||
| 
 | ||||
| .paket\paket.bootstrapper.exe | ||||
| if errorlevel 1 ( | ||||
|   exit /b %errorlevel% | ||||
| ) | ||||
| 
 | ||||
| .paket\paket.exe restore | ||||
| if errorlevel 1 ( | ||||
|   exit /b %errorlevel% | ||||
| ) | ||||
| 
 | ||||
| packages\FAKE\tools\FAKE.exe build.fsx %* | ||||
| @ -1,42 +0,0 @@ | ||||
| // include Fake libs | ||||
| #r "./packages/FAKE/tools/FakeLib.dll" | ||||
| 
 | ||||
| open Fake | ||||
| 
 | ||||
| // Directories | ||||
| let buildDir  = "./build/" | ||||
| let deployDir = "./deploy/" | ||||
| 
 | ||||
| 
 | ||||
| // Filesets | ||||
| let appReferences  = | ||||
|     !! "/**/*.csproj" | ||||
|       ++ "/**/*.fsproj" | ||||
| 
 | ||||
| // version info | ||||
| let version = "0.1"  // or retrieve from CI server | ||||
| 
 | ||||
| // Targets | ||||
| Target "Clean" (fun _ -> | ||||
|     CleanDirs [buildDir; deployDir] | ||||
| ) | ||||
| 
 | ||||
| Target "Build" (fun _ -> | ||||
|     // compile all projects below src/app/ | ||||
|     MSBuildDebug buildDir "Build" appReferences | ||||
|         |> Log "AppBuild-Output: " | ||||
| ) | ||||
| 
 | ||||
| Target "Deploy" (fun _ -> | ||||
|     !! (buildDir + "/**/*.*") | ||||
|         -- "*.zip" | ||||
|         |> Zip buildDir (deployDir + "ApplicationName." + version + ".zip") | ||||
| ) | ||||
| 
 | ||||
| // Build order | ||||
| "Clean" | ||||
|   ==> "Build" | ||||
|   ==> "Deploy" | ||||
| 
 | ||||
| // start build | ||||
| RunTargetOrDefault "Build" | ||||
							
								
								
									
										33
									
								
								src/build.sh
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								src/build.sh
									
									
									
									
									
								
							| @ -1,33 +0,0 @@ | ||||
| #!/bin/bash | ||||
| if test "$OS" = "Windows_NT" | ||||
| then | ||||
|   # use .Net | ||||
| 
 | ||||
|   .paket/paket.bootstrapper.exe | ||||
|   exit_code=$? | ||||
|   if [ $exit_code -ne 0 ]; then | ||||
|   	exit $exit_code | ||||
|   fi | ||||
| 
 | ||||
|   .paket/paket.exe restore | ||||
|   exit_code=$? | ||||
|   if [ $exit_code -ne 0 ]; then | ||||
|   	exit $exit_code | ||||
|   fi | ||||
| 
 | ||||
|   packages/FAKE/tools/FAKE.exe $@ --fsiargs build.fsx | ||||
| else | ||||
|   # use mono | ||||
|   mono .paket/paket.bootstrapper.exe | ||||
|   exit_code=$? | ||||
|   if [ $exit_code -ne 0 ]; then | ||||
|   	exit $exit_code | ||||
|   fi | ||||
| 
 | ||||
|   mono .paket/paket.exe restore | ||||
|   exit_code=$? | ||||
|   if [ $exit_code -ne 0 ]; then | ||||
|   	exit $exit_code | ||||
|   fi | ||||
|   mono packages/FAKE/tools/FAKE.exe $@ --fsiargs -d:MONO build.fsx | ||||
| fi | ||||
| @ -1,13 +0,0 @@ | ||||
| framework: net40, net45, net452 | ||||
| source https://www.nuget.org/api/v2 | ||||
| nuget Common.Logging 3.3.0 | ||||
| nuget FAKE | ||||
| nuget FSharp.Interop.Dynamic | ||||
| nuget FSharp.Formatting | ||||
| nuget Nancy | ||||
| nuget Nancy.Authentication.Forms | ||||
| nuget Nancy.Session.RethinkDb | ||||
| nuget Newtonsoft.Json | ||||
| nuget NodaTime | ||||
| nuget RethinkDb.Driver | ||||
| nuget Suave | ||||
| @ -1,34 +0,0 @@ | ||||
| FRAMEWORK: NET40, NET45, NET452 | ||||
| NUGET | ||||
|   remote: https://www.nuget.org/api/v2 | ||||
|     Common.Logging (3.3) | ||||
|       Common.Logging.Core (>= 3.3) | ||||
|     Common.Logging.Core (3.3.1) | ||||
|     Dynamitey (1.0.2) | ||||
|     FAKE (4.36) | ||||
|     FSharp.Compiler.Service (2.0.0.6) | ||||
|     FSharp.Core (4.0.0.1) | ||||
|     FSharp.Formatting (2.14.4) | ||||
|       FSharp.Compiler.Service (2.0.0.6) | ||||
|       FSharpVSPowerTools.Core (>= 2.3 < 2.4) | ||||
|     FSharp.Interop.Dynamic (3.0) | ||||
|       Dynamitey (>= 1.0.2) | ||||
|       FSharp.Core (>= 3.1.2.1) | ||||
|     FSharpVSPowerTools.Core (2.3) | ||||
|       FSharp.Compiler.Service (>= 2.0.0.3) | ||||
|     Nancy (1.4.3) | ||||
|     Nancy.Authentication.Forms (1.4.1) | ||||
|       Nancy (>= 1.4.1) | ||||
|     Nancy.Session.Persistable (0.9) | ||||
|       Nancy (>= 1.4.3) | ||||
|       Newtonsoft.Json (>= 9.0.1) | ||||
|     Nancy.Session.RethinkDB (0.9) | ||||
|       Nancy.Session.Persistable (>= 0.9) | ||||
|       RethinkDb.Driver (>= 2.3.9) | ||||
|     Newtonsoft.Json (9.0.1) | ||||
|     NodaTime (1.3.2) | ||||
|     RethinkDb.Driver (2.3.10) | ||||
|       Common.Logging (>= 3.3) - framework: net45, net452 | ||||
|       Newtonsoft.Json (>= 9.0.1) - framework: net45, net452 | ||||
|     Suave (1.1.3) | ||||
|       FSharp.Core (>= 3.1.2.5) | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user