-
Notifications
You must be signed in to change notification settings - Fork 35
/
snippet.fs
41 lines (35 loc) · 1.22 KB
/
snippet.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module FsSnip.Pages.Snippet
open System
open System.Web
open FsSnip
open FsSnip.Data
open FsSnip.Utils
open Suave
open Suave.Http
open Suave.Http.Successful
// -------------------------------------------------------------------------------------------------
// Snippet details and raw view pages
// -------------------------------------------------------------------------------------------------
type FormattedSnippet =
{ Html : string
Details : Data.Snippet
Revision : int }
let invalidSnippetId id =
RequestErrors.NOT_FOUND ""
let showSnippet id r =
let id' = demangleId id
match Seq.tryFind (fun s -> s.ID = id') publicSnippets with
| Some snippetInfo ->
match Data.loadSnippet id r with
| Some snippet ->
let rev = match r with Latest -> snippetInfo.Versions - 1 | Revision r -> r
{ Html = snippet
Details = Data.snippets |> Seq.find (fun s -> s.ID = demangleId id)
Revision = rev }
|> DotLiquid.page<FormattedSnippet> "snippet.html"
| None -> invalidSnippetId id
| None -> invalidSnippetId id
let showRawSnippet id r =
match Data.loadRawSnippet id r with
| Some s -> Writers.setMimeType "text/plain" >>= OK s
| None -> invalidSnippetId id