diff --git a/src/.paket/paket.bootstrapper.exe b/src/.paket/paket.bootstrapper.exe deleted file mode 100644 index 64fdf24..0000000 Binary files a/src/.paket/paket.bootstrapper.exe and /dev/null differ diff --git a/src/MyWebLog.App/PageModule.fs b/src/MyWebLog.App/PageModule.fs index b78d9de..a928dac 100644 --- a/src/MyWebLog.App/PageModule.fs +++ b/src/MyWebLog.App/PageModule.fs @@ -15,17 +15,17 @@ type PageModule (data : IMyWebLogData, clock : IClock) as this = inherit NancyModule () 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 ("/pages", fun _ -> this.PageList ()) + 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 - |> List.map (fun p -> PageForDisplay (this.WebLog, p))) + 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) - { UserMessage.Empty with - Level = Level.Info - Message = System.String.Format - (Strings.get "MsgPageEditSuccess", - Strings.get (match pageId with "new" -> "Added" | _ -> "Updated")) } - |> model.AddMessage + model.AddMessage + { UserMessage.Empty with + Message = System.String.Format + (Strings.get "MsgPageEditSuccess", + 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 () diff --git a/src/MyWebLog.App/PostModule.fs b/src/MyWebLog.App/PostModule.fs index a83efeb..7e20d18 100644 --- a/src/MyWebLog.App/PostModule.fs +++ b/src/MyWebLog.App/PostModule.fs @@ -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,16 +63,21 @@ 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 - findFeedPosts data this.WebLog.Id 10 - |> List.map (fun (post, _) -> - { Title = post.Title - Link = sprintf "%s/%s" schemeAndUrl post.Permalink - ReleaseDate = Instant.FromUnixTimeTicks(post.PublishedOn).ToDateTimeOffset().DateTime - Description = post.Text - }) - |> myChannelFeed this.WebLog.Name schemeAndUrl this.WebLog.Subtitle + let feed = + findFeedPosts data this.WebLog.Id 10 + |> List.map (fun (post, _) -> + { Title = post.Title + Link = sprintf "%s/%s" schemeAndUrl post.Permalink + ReleaseDate = Instant.FromUnixTimeTicks(post.PublishedOn).ToDateTimeOffset().DateTime + 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,11 +253,12 @@ 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 - |> List.sortByDescending (fun r -> r.AsOf) - |> List.tryHead with - | Some r -> r - | None -> Revision.Empty + let rev = + match post.Revisions + |> List.sortByDescending (fun r -> r.AsOf) + |> List.tryHead with + | Some r -> r + | None -> Revision.Empty let model = EditPostModel (this.Context, this.WebLog, post, rev) model.Categories <- findAllCategories data this.WebLog.Id |> List.map (fun cat -> @@ -270,12 +278,14 @@ 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 - WebLogId = this.WebLog.Id - AuthorId = (this.Request.PersistableSession.GetOrDefault - (Keys.User, User.Empty)).Id } - | _ -> p + let post = + match postId with + | "new" -> + { p with + WebLogId = this.WebLog.Id + AuthorId = this.Request.PersistableSession.GetOrDefault(Keys.User, User.Empty).Id + } + | _ -> p let pId = { post with Status = match form.PublishNow with true -> PostStatus.Published | _ -> PostStatus.Draft @@ -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) - { 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 + model.AddMessage + { UserMessage.Empty with + Message = System.String.Format + (Strings.get "MsgPostEditSuccess", + Strings.get (match postId with "new" -> "Added" | _ -> "Updated"), + (match justPublished with true -> Strings.get "AndPublished" | _ -> "")) + } this.Redirect (sprintf "/post/%s/edit" pId) model | _ -> this.NotFound () diff --git a/src/build.cmd b/src/build.cmd deleted file mode 100644 index 40aff45..0000000 --- a/src/build.cmd +++ /dev/null @@ -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 %* diff --git a/src/build.fsx b/src/build.fsx deleted file mode 100644 index a13fe19..0000000 --- a/src/build.fsx +++ /dev/null @@ -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" diff --git a/src/build.sh b/src/build.sh deleted file mode 100644 index c40c3f8..0000000 --- a/src/build.sh +++ /dev/null @@ -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 diff --git a/src/paket.dependencies b/src/paket.dependencies deleted file mode 100644 index 7fb3107..0000000 --- a/src/paket.dependencies +++ /dev/null @@ -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 \ No newline at end of file diff --git a/src/paket.lock b/src/paket.lock deleted file mode 100644 index d7e0315..0000000 --- a/src/paket.lock +++ /dev/null @@ -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)