Commit 857bd64d authored by Henrik Tramberend's avatar Henrik Tramberend
Browse files

Merge branch 'master' into sketch-pad

parents 7a6a7728 f4b38c79
......@@ -41,7 +41,6 @@ RUN apt-get update && apt-get install -y \
graphviz \
gnuplot \
rsync \
sassc \
unzip \
zip
......
......@@ -20,6 +20,7 @@ import Data.Version
import Development.Shake
import Development.Shake.FilePath
import GHC.Conc (numCapabilities)
import System.Decker.OS (defaultProvisioning)
import System.Directory (createDirectoryIfMissing, createFileLink, removeFile)
import System.Environment.Blank
import System.FilePath ()
......@@ -59,8 +60,7 @@ main = do
" (branch: " ++
deckerGitBranch ++
", commit: " ++
deckerGitCommitId ++
", tag: " ++ deckerGitVersionTag ++ ")"
deckerGitCommitId ++ ", tag: " ++ deckerGitVersionTag ++ ")"
putNormal $ "pandoc version " ++ pandocVersion
putNormal $ "pandoc-types version " ++ showVersion pandocTypesVersion
--
......@@ -92,7 +92,7 @@ main = do
need ["watch"]
runHttpServer serverPort directories Nothing
--
phony "example" writeExampleProject
phony "example" $ liftIO writeExampleProject
--
phony "sketch-pad-index" $ do
indicesA >>= need
......@@ -173,17 +173,12 @@ main = do
pdflatex ["-output-directory", dir, src]
pdf2svg [pdf, out]
liftIO $ removeFile pdf
priority 2 $
"//*.css" %> \out -> do
let src = out -<.> ".scss"
exists <- doesFileExist src
when exists $ do
need [src]
sassc [src, out]
--
phony "clean" $ do
removeFilesAfter (directories ^. public) ["//"]
removeFilesAfter (directories ^. project) cruft
old <- liftIO getOldResources
forM_ old $ \dir -> removeFilesAfter dir ["//"]
when isDevelopmentVersion $
removeFilesAfter (directories ^. appData) ["//"]
--
......@@ -214,15 +209,21 @@ main = do
(directories ^. support)
Just value
| value == show Copy ->
rsync
[ ((directories ^. appData) </> "support/")
, (directories ^. support)
]
liftIO $
copyDir
((directories ^. appData) </> "support")
(directories ^. support)
Nothing ->
liftIO $
createFileLink
((directories ^. appData) </> "support")
(directories ^. support)
case defaultProvisioning of
SymLink ->
createFileLink
((directories ^. appData) </> "support")
(directories ^. support)
_ ->
copyDir
((directories ^. appData) </> "support")
(directories ^. support)
_ -> return ()
--
phony "check" checkExternalPrograms
......
......@@ -95,3 +95,19 @@ resource/support/reveal.js-menu/%: node_modules/reveal.js-menu/%
node_modules/%:
yarn install
SECONDARY = node_modules/reveal.js/css/print/paper.css
SECONDARY += node_modules/reveal.js/css/print/pdf.css
SECONDARY += node_modules/reveal.js/plugin/notes/notes.html
SECONDARY += node_modules/reveal.js/plugin/notes/notes.js
SECONDARY += node_modules/reveal.js-menu/menu.js
SECONDARY += node_modules/reveal.js-menu/menu.css
SECONDARY += node_modules/reveal.js-menu/font-awesome/css/all.css
SECONDARY += node_modules/reveal.js-menu/font-awesome/webfonts/fa-solid-900.woff2
SECONDARY += node_modules/reveal.js-menu/font-awesome/webfonts/fa-regular-400.woff2
SECONDARY += node_modules/reveal.js-menu/font-awesome/webfonts/fa-solid-900.woff
SECONDARY += node_modules/reveal.js-menu/font-awesome/webfonts/fa-regular-400.woff
SECONDARY += node_modules/reveal.js-menu/font-awesome/webfonts/fa-solid-900.ttf
SECONDARY += node_modules/reveal.js-menu/font-awesome/webfonts/fa-regular-400.ttf
.SECONDARY: $(SECONDARY)
......@@ -93,6 +93,14 @@ dependencies:
library:
source-dirs: src
when:
- condition: os(windows)
then:
source-dirs: src-win
exposed-modules: "System.Decker.OS"
else:
source-dirs: src-mac
exposed-modules: "System.Decker.OS"
executables:
decker:
......
......@@ -37,7 +37,6 @@ Decker uses a few external tools that need to be installed on the system:
- [*Gnuplot*](http://gnuplot.sourceforge.net) to generate graphs using `dot`
- [*pdf2svg*](https://github.com/dawbarton/pdf2svg) to generate SVG files from
PDF documents
- [*sassc*](https://github.com/sass/sassc) to compile SCSS to CSS
- *libbzip2-dev*
- [*NodeJS*](https://nodejs.org/) as a prerequisite for Yarn
- [*Yarn*](https://yarnpkg.com) to install Javascript dependencies
......@@ -47,7 +46,7 @@ Decker uses a few external tools that need to be installed on the system:
Use [Homebrew](https://brew.sh) to install most of them.
``` {.sh}
brew install rsync unzip graphviz gnuplot pdf2svg sassc yarn
brew install rsync unzip graphviz gnuplot pdf2svg yarn
```
For the rest follow instructions on their respective webites.
......
{-- Author: Jan-Philipp Stauffert <jan-philipp.stauffert@uni-wuerzburg.de.de> --}
module System.Decker.OS
( defaultProvisioning
) where
import Common
defaultProvisioning :: Provisioning
defaultProvisioning = SymLink
{-- Author: Jan-Philipp Stauffert <jan-philipp.stauffert@uni-wuerzburg.de.de> --}
module System.Decker.OS
( defaultProvisioning
) where
import Common
defaultProvisioning :: Provisioning
defaultProvisioning = Copy
......@@ -8,8 +8,6 @@ module External
, pdflatex
, pdf2svg
, decktape
, sassc
, git
, checkExternalPrograms
) where
......@@ -94,20 +92,6 @@ programs =
[]
(helpText
"Decktape PDF exporter (https://github.com/astefanutti/decktape)"))
, ( "sassc"
, ExternalProgram
[]
"sassc"
["--style", "nested"]
["-v"]
(helpText "LibSass wrapper (https://github.com/sass/sassc)"))
, ( "git"
, ExternalProgram
[]
"git"
[]
["version"]
(helpText "Git version control (https://git-scm.com)"))
]
type Program = [String] -> Action ()
......@@ -137,12 +121,6 @@ pdf2svg = makeProgram "pdf2svg"
decktape :: Program
decktape = makeProgram "decktape"
sassc :: Program
sassc = makeProgram "sassc"
git :: Program'
git = makeProgram' "git"
helpText :: String -> String
helpText name =
"The " ++
......
......@@ -2,20 +2,24 @@
module Resources
( extractResources
, getResourceString
, getOldResources
, deckerResourceDir
, writeResourceFiles
, writeExampleProject
, copyDir
) where
import Common
import Control.Exception
import Control.Monad
import Control.Monad.Extra
import Data.List.Split (splitOn)
import Exception
import System.Directory
import System.Environment
import System.Exit
import System.FilePath
import System.Process
import Text.Regex.TDFA
deckerResourceDir :: IO FilePath
deckerResourceDir =
......@@ -24,6 +28,22 @@ deckerResourceDir =
("decker" ++
"-" ++ deckerVersion ++ "-" ++ deckerGitBranch ++ "-" ++ deckerGitCommitId)
-- | Get the absolute paths of resource folders
-- with version numbers older than the current one
getOldResources :: IO [FilePath]
getOldResources = do
dir <- getXdgDirectory XdgData []
files <- listDirectory dir
return $ map (dir </>) $ filter oldVersion files
where
convert = map (read :: String -> Int)
currentVersion = convert (splitOn "." deckerVersion)
deckerRegex = "decker-([0-9]+)[.]([0-9]+)[.]([0-9]+)-" :: String
oldVersion name =
case getAllTextSubmatches (name =~ deckerRegex) :: [String] of
[] -> False
_:x:y:z:_ -> convert [x, y, z] < currentVersion
getResourceString :: FilePath -> IO String
getResourceString path = do
dataDir <- deckerResourceDir
......@@ -53,9 +73,42 @@ unzip args = do
ExitFailure 1 -> True
_ -> False
-- | Write the example project to the current folder
writeExampleProject :: IO ()
writeExampleProject = writeResourceFiles "example" "."
writeResourceFiles :: FilePath -> FilePath -> IO ()
writeResourceFiles prefix destDir = do
dataDir <- deckerResourceDir
let src = dataDir </> prefix
exists <- doesDirectoryExist (destDir </> prefix)
unless exists $ callProcess "cp" ["-R", src, destDir]
copyDir src destDir
-- | Copy a file to a file location or to a directory
cp :: FilePath -> FilePath -> IO ()
cp src dst = do
unlessM (doesFileExist src) $
throw (userError "src does not exist or is not a file")
unlessM (doesFileExist dst) $ do
destIsDir <- doesDirectoryExist dst
if destIsDir
then copyFile src (dst </> takeFileName src)
else copyFile src dst
-- | Copy a directory and its contents recursively
copyDir :: FilePath -> FilePath -> IO ()
copyDir src dst = do
unlessM (doesDirectoryExist src) $
throw (userError "src does not exist or is not a directory")
dstExists <- doesDirectoryExist dst
if dstExists && (last (splitPath src) /= last (splitPath dst))
then copyDir src (dst </> last (splitPath src))
else do
createDirectoryIfMissing True dst
contents <- listDirectory src
forM_ contents $ \name -> do
let srcPath = src </> name
let dstPath = dst </> name
isDirectory <- doesDirectoryExist srcPath
if isDirectory
then copyDir srcPath dstPath
else cp srcPath dstPath
......@@ -10,7 +10,6 @@ module Utilities
, markdownToPdfHandout
, markdownToHtmlPage
, markdownToPdfPage
, writeExampleProject
, metaValueAsString
, (<++>)
, writeEmbeddedFiles
......@@ -250,7 +249,7 @@ writePandocFile fmt options out pandoc =
case getWriter fmt of
Right (TextWriter writePandoc, _) ->
runIOQuietly (writePandoc options pandoc) >>= handleError >>=
T.writeFile out
B.writeFile out . E.encodeUtf8
Right (ByteStringWriter writePandoc, _) ->
runIOQuietly (writePandoc options pandoc) >>= handleError >>=
LB.writeFile out
......@@ -497,7 +496,7 @@ readMetaMarkdown markdownFile = do
externalMeta <-
liftIO $ aggregateMetaData projectDir (takeDirectory markdownFile)
-- extract embedded meta data from the document
markdown <- liftIO $ T.readFile markdownFile
markdown <- liftIO $ E.decodeUtf8 <$> B.readFile markdownFile
let pandoc = readMarkdownOrThrow pandocReaderOpts markdown
Pandoc fileMeta fileBlocks <- liftIO $ provideSlideIds pandoc
let documentMeta = MetaMap $ unMeta fileMeta
......@@ -687,9 +686,9 @@ processCitesWithDefault pandoc@(Pandoc meta blocks) =
_ -> return pandoc
liftIO $ processCites' document
writeExampleProject :: Action ()
writeExampleProject = liftIO $ writeResourceFiles "example" "."
-- moved to Resources.hs
-- writeExampleProject :: Action ()
-- writeExampleProject = liftIO $ writeResourceFiles "example" "."
{--
writeExampleProject :: Action ()
writeExampleProject = mapM_ writeOne deckerExampleDir
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment