Skip to content

Commit

Permalink
slides
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Magnorsky committed Jul 28, 2016
1 parent 7d8064d commit cbba578
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 3 deletions.
2 changes: 1 addition & 1 deletion LSystem/svg.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ let main =
|> save
0

main
main
14 changes: 14 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@echo off
cls

.paket\paket.bootstrapper.exe
if errorlevel 1 (
exit /b %errorlevel%
)

.paket\paket.exe restore -v
if errorlevel 1 (
exit /b %errorlevel%
)

packages\FAKE\tools\FAKE.exe build.fsx %*
137 changes: 137 additions & 0 deletions build.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#I @"packages/FsReveal/fsreveal/"
#I @"packages/FAKE/tools/"
#I @"packages/Suave/lib/net40"

#r "FakeLib.dll"
#r "suave.dll"

#load "fsreveal.fsx"

// Git configuration (used for publishing documentation in gh-pages branch)
// The profile where the project is posted
let gitOwner = "myGitUser"
let gitHome = "https://github.com/" + gitOwner
// The name of the project on GitHub
let gitProjectName = "MyProject"

open FsReveal
open Fake
open Fake.Git
open System.IO
open System.Diagnostics
open Suave
open Suave.Web
open Suave.Http
open Suave.Http.Files

let outDir = __SOURCE_DIRECTORY__ @@ "output"
let slidesDir = __SOURCE_DIRECTORY__ @@ "slides"

Target "Clean" (fun _ ->
CleanDirs [outDir]
)

let fsiEvaluator =
let evaluator = FSharp.Literate.FsiEvaluator()
evaluator.EvaluationFailed.Add(fun err ->
traceImportant <| sprintf "Evaluating F# snippet failed:\n%s\nThe snippet evaluated:\n%s" err.StdErr err.Text )
evaluator

let copyStylesheet() =
try
CopyFile (outDir @@ "css" @@ "custom.css") (slidesDir @@ "custom.css")
with
| exn -> traceImportant <| sprintf "Could not copy stylesheet: %s" exn.Message

let copyPics() =
try
CopyDir (outDir @@ "images") (slidesDir @@ "images") (fun f -> true)
with
| exn -> traceImportant <| sprintf "Could not copy picture: %s" exn.Message

let generateFor (file:FileInfo) =
try
copyPics()
let rec tryGenerate trials =
try
FsReveal.GenerateFromFile(file.FullName, outDir, fsiEvaluator = fsiEvaluator)
with
| exn when trials > 0 -> tryGenerate (trials - 1)
| exn ->
traceImportant <| sprintf "Could not generate slides for: %s" file.FullName
traceImportant exn.Message

tryGenerate 3

copyStylesheet()
with
| :? FileNotFoundException as exn ->
traceImportant <| sprintf "Could not copy file: %s" exn.FileName

let handleWatcherEvents (e:FileSystemEventArgs) =
let fi = fileInfo e.FullPath
traceImportant <| sprintf "%s was changed." fi.Name
match fi.Attributes.HasFlag FileAttributes.Hidden || fi.Attributes.HasFlag FileAttributes.Directory with
| true -> ()
| _ -> generateFor fi

let startWebServer () =
let serverConfig =
{ defaultConfig with
homeFolder = Some (FullName outDir)
}
let app =
Writers.setHeader "Cache-Control" "no-cache, no-store, must-revalidate"
>>= Writers.setHeader "Pragma" "no-cache"
>>= Writers.setHeader "Expires" "0"
>>= browseHome
startWebServerAsync serverConfig app |> snd |> Async.Start
Process.Start "http://localhost:8083/index.html" |> ignore

Target "GenerateSlides" (fun _ ->
!! (slidesDir @@ "*.md")
++ (slidesDir @@ "*.fsx")
|> Seq.map fileInfo
|> Seq.iter generateFor
)

Target "KeepRunning" (fun _ ->
use watcher = new FileSystemWatcher(FullName slidesDir,"*.*")
watcher.EnableRaisingEvents <- true
watcher.IncludeSubdirectories <- true
watcher.Changed.Add(handleWatcherEvents)
watcher.Created.Add(handleWatcherEvents)
watcher.Renamed.Add(handleWatcherEvents)

startWebServer ()

traceImportant "Waiting for slide edits. Press any key to stop."

System.Console.ReadKey() |> ignore

watcher.EnableRaisingEvents <- false
watcher.Dispose()
)

Target "ReleaseSlides" (fun _ ->
if gitOwner = "myGitUser" || gitProjectName = "MyProject" then
failwith "You need to specify the gitOwner and gitProjectName in build.fsx"
let tempDocsDir = __SOURCE_DIRECTORY__ @@ "temp/gh-pages"
CleanDir tempDocsDir
Repository.cloneSingleBranch "" (gitHome + "/" + gitProjectName + ".git") "gh-pages" tempDocsDir

fullclean tempDocsDir
CopyRecursive outDir tempDocsDir true |> tracefn "%A"
StageAll tempDocsDir
Git.Commit.Commit tempDocsDir "Update generated slides"
Branches.push tempDocsDir
)

"Clean"
==> "GenerateSlides"
==> "KeepRunning"

"GenerateSlides"
==> "ReleaseSlides"

RunTargetOrDefault "KeepRunning"
33 changes: 33 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/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 -v
exit_code=$?
if [ $exit_code -ne 0 ]; then
exit $exit_code
fi

packages/FAKE/tools/FAKE.exe $@ --fsiargs -d:MONO 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 -v
exit_code=$?
if [ $exit_code -ne 0 ]; then
exit $exit_code
fi
mono packages/FAKE/tools/FAKE.exe $@ --fsiargs -d:MONO build.fsx
fi
5 changes: 5 additions & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source https://nuget.org/api/v2

nuget FsReveal
nuget FAKE
nuget Suave
17 changes: 17 additions & 0 deletions paket.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
NUGET
remote: https://nuget.org/api/v2
specs:
FAKE (3.27.2)
FSharp.Compiler.Service (0.0.87)
FSharp.Core (3.1.2.1)
FSharp.Formatting (2.8.0)
FSharp.Compiler.Service (>= 0.0.86)
FSharpVSPowerTools.Core (>= 1.7.0)
FSharpVSPowerTools.Core (1.7.0)
FSharp.Compiler.Service (>= 0.0.87)
FsPickler (1.0.16)
FsReveal (0.7.2)
FSharp.Formatting (>= 2.7.5)
Suave (0.26.1)
FSharp.Core (>= 3.1.2.1)
FsPickler (>= 1.0.7)
4 changes: 2 additions & 2 deletions slides/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ span.s {
color:#258525;
}

.reveal h1 {
/*.reveal h1 {
margin: 0 0 20px 0;
color: #4C1485;
background: rgba(253, 246, 227, 0.65);
}
}*/

.reveal blockquote {
background: rgba(253, 246, 227, 0.65);
Expand Down
Binary file added slides/images/bla.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added slides/images/dragon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added slides/images/fk.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added slides/images/herding-cats.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added slides/images/wd-logo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cbba578

Please sign in to comment.