better generator

This commit is contained in:
Yann Esposito 2016-03-25 17:40:59 +01:00
parent eb4ef3519b
commit 65e2224958
7 changed files with 234 additions and 56 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
TAGS

View file

@ -2,7 +2,7 @@
-- stack --install-ghc runghc --package turtle --resolver lts-5.5 --verbosity silent --package=ansi-terminal
{-# LANGUAGE OverloadedStrings #-}
import Control.Arrow ((>>>))
import qualified Control.Foldl as Fold
import qualified Data.Text.IO as T
import Filesystem.Path (addExtension, replaceExtension)
import qualified Filesystem.Path as F
@ -10,60 +10,83 @@ import Prelude hiding (FilePath)
import System.Console.ANSI
import Turtle
data Options = Options { web :: Bool
, reveal :: Bool
, pdf :: Bool
, beamer :: Bool
, file :: Maybe FilePath
} deriving (Show)
-- Command Line Options
data Options =
Options { web :: Bool
, reveal :: Bool
, pdf :: Bool
, beamer :: Bool
, debug :: Bool
, file :: Maybe FilePath
} deriving (Show)
parser :: Parser Options
parser = Options <$> switch "web" 'w' "generate HTML web page"
<*> switch "reveal" 'r' "generate HTML presentation using reveal"
<*> switch "pdf" 'p' "generate PDF article"
<*> switch "beamer" 'b' "generate PDF presentation using beamer"
<*> switch "debug" 'd' "debug mode (show commands)"
<*> optional (argPath "file" "markdown file path")
fgrep :: Pattern a -> Shell FilePath -> Shell FilePath
fgrep pat sp = do
fpath <- sp
_:_ <- return (match pat (either id id (toText fpath)))
return fpath
initOptions :: IO Options
initOptions = do
rawopts <- options "compile files" parser
return $ if web rawopts || reveal rawopts || pdf rawopts || beamer rawopts
then rawopts
else rawopts { web = True
, reveal = True
, pdf = True
, beamer = True }
main :: IO ()
main = do
opts <- options "compile files" parser
opts <- initOptions
sh $ do
argfile <- case file opts of
Nothing -> fgrep (invert (prefix "./.")) $ find (has ".md") "."
Nothing -> findMarkdownFiles
Just someFile -> return someFile
liftIO $ do
when (debug opts) (yellowPrn ("-- " <> format fp argfile <> " --"))
cd (directory argfile)
when (web opts) (toWeb argfile)
when (reveal opts) (toReveal argfile)
when (pdf opts) (toPdf argfile)
when (beamer opts) (toBeamer argfile)
when (web opts) (toWeb (debug opts) argfile)
when (reveal opts) (toReveal (debug opts) argfile)
when (pdf opts) (toPdf (debug opts) argfile)
when (beamer opts) (toBeamer (debug opts) argfile)
toWeb :: FilePath -> IO ()
toWeb fpath = do
let dest = replaceExtension fpath "html"
pr :: FilePath
pr = F.concat $ map (const "..") (splitDirectories (directory fpath))
prt :: Text
prt = format fp pr
void $ shell ("pandoc -s -mathjax -t html5"
<> "--template " <> prt <> " "
<> "--section-divs"
<> "--variable transition=linear"
<> "--variable prefix=" <> prt
<> "-o " <> format fp dest
<> format fp fpath) empty
-- | Find Markdown Files (skip hidden directories)
findMarkdownFiles :: Shell FilePath
findMarkdownFiles = fgrep (invert (prefix "./.")) $ find (has ".md") "."
toReveal :: FilePath -> IO ()
toReveal fpath = do
let renameToDest = filename >>> dropExtension >>> flip addExtension "reveal" >>> flip addExtension "html"
dest = renameToDest fpath
-- | basic exec command with debug option and colors DONE or FAILED status
execcmd :: Bool -> FilePath -> Text -> IO ()
execcmd dbg dest cmd = do
when dbg (T.putStrLn cmd)
T.putStr $ format fp dest <> " "
answer <- shell cmd empty
case answer of
ExitSuccess -> greenPrn "[DONE]"
ExitFailure _ -> redPrn "[FAILED]"
-- | Generate HTML format
toWeb :: Bool -> FilePath -> IO ()
toWeb dbg fpath = do
let dest = filename (replaceExtension fpath "html")
pr :: FilePath
pr = F.concat $ map (const "..") (splitDirectories (directory fpath))
cmd = "pandoc -s -S --toc -mathjax -t html5 --smart "
<> "--css " <> format fp (pr </> "styling.css") <> " "
<> "-A " <> format fp (pr </> "footer.html") <> " "
<> "-o " <> format fp dest <> " "
<> format fp (filename fpath)
execcmd dbg dest cmd
-- | Generate HTML Reveal.js Presentation
toReveal :: Bool -> FilePath -> IO ()
toReveal dbg fpath = do
let dest = fpath |> filename
|> dropExtension
|> flip addExtension "reveal"
|> flip addExtension "html"
pr :: FilePath
pr = F.concat $ map (const "..") (splitDirectories (directory fpath))
template = pr </> "template-revealjs.html"
@ -76,26 +99,83 @@ toReveal fpath = do
<> "--variable prefix=" <> prt <> " "
<> "-o " <> format fp dest <> " "
<> format fp (filename fpath)
T.putStr $ format fp dest <> " "
answer <- shell cmd empty
case answer of
ExitSuccess -> greenPrn "[DONE]"
ExitFailure _ -> redPrn "[FAILED]"
execcmd dbg dest cmd
toPdf :: FilePath -> IO ()
toPdf = print
-- | Generate PDF Document using XeLaTeX
toPdf :: Bool -> FilePath -> IO ()
toPdf dbg fpath = do
let dest = fpath |> filename
|> dropExtension
|> flip addExtension "pdf"
pr = F.concat $ map (const "..") (splitDirectories (directory fpath))
template = pr </> "template.latex"
cmd = "pandoc -s -S -N --toc "
<> "--template=" <> format fp template <> " "
<> "--section-divs "
<> "--variable fontsize=14pt "
<> "--variable linkcolor=orange "
<> "--variable urlcolor=orange "
<> "--latex-engine=xelatex "
<> "-o " <> format fp dest <> " "
<> format fp (filename fpath)
execcmd dbg dest cmd
toBeamer :: FilePath -> IO ()
toBeamer = print
-- | Generate Beamer Presentation PDF
toBeamer :: Bool -> FilePath -> IO ()
toBeamer dbg fpath = do
mslideLevel <- fold (fpath |> filename
|> input
|> grep (prefix "slide_level: ")
|> sed (prefix "slide_level: " *> star digit))
Fold.head
let slideLevel = maybe "2" (\l -> if l == "" then "2" else l) mslideLevel
dest = fpath |> filename
|> dropExtension
|> flip addExtension "beamer"
|> flip addExtension "pdf"
cmd :: Text
cmd = "pandoc -s -S -N "
<> "-t beamer "
<> "--slide-level=" <> slideLevel <> " "
<> "--variable fontsize=14pt "
<> "--variable linkcolor=orange "
<> "--variable urlcolor=orange "
<> "--latex-engine=xelatex "
<> "-o " <> format fp dest <> " "
<> format fp (filename fpath)
execcmd dbg dest cmd
-- # Colors Helpers (should be a sub lib)
-- import System.Console.ANSI
prnColor :: Color -> Text -> IO ()
prnColor c txt = do
setSGR [SetColor Foreground Dull c]
T.putStrLn txt
setSGR [Reset]
greenPrn :: Text -> IO ()
greenPrn txt = do
setSGR [SetColor Foreground Dull Green]
T.putStrLn txt
setSGR [Reset]
greenPrn = prnColor Green
redPrn :: Text -> IO ()
redPrn txt = do
setSGR [SetColor Foreground Dull Red]
T.putStrLn txt
setSGR [Reset]
redPrn = prnColor Red
yellowPrn :: Text -> IO ()
yellowPrn = prnColor Yellow
-- | Helper to make code look a lot more (->) in Clojure
-- Generally humans, prefer to read function applied in the order
-- from left to right not in the reverse order.
-- This operator can be found in F# and Elm
(|>) :: a -> (a -> b) -> b
(|>) v fn = fn v
-- # Grep Files helper
-- | Same as grep put to be used after find or ls
fgrep :: Pattern a -> Shell FilePath -> Shell FilePath
fgrep pat sp = do
fpath <- sp
_:_ <- return (match pat (either id id (toText fpath)))
return fpath

95
druid/druid.html Normal file
View file

@ -0,0 +1,95 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="Yann Esposito">
<title>Druid pour lanalyse de données en temps réel</title>
<style type="text/css">code{white-space: pre;}</style>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="../styling.css">
</head>
<body>
<header>
<h1 class="title">Druid pour lanalyse de données en temps réel</h1>
<h2 class="author">Yann Esposito</h2>
<h3 class="date">7 Avril 2016</h3>
</header>
<nav id="TOC">
<ul>
<li><a href="#intro">Intro</a><ul>
<li><a href="#plan">Plan</a></li>
<li><a href="#expérience">Expérience</a></li>
<li><a href="#demande">Demande</a></li>
<li><a href="#en-pratique">En pratique</a></li>
<li><a href="#origine-php">Origine (PHP)</a></li>
<li><a href="#introduction">Introduction</a></li>
</ul></li>
<li><a href="#druid">Druid</a><ul>
<li><a href="#who">Who</a></li>
<li><a href="#goal">Goal</a></li>
<li><a href="#concepts">Concepts</a></li>
<li><a href="#features">Features</a></li>
<li><a href="#proof">Proof</a></li>
</ul></li>
</ul>
</nav>
<h1 id="intro">Intro</h1>
<h2 id="plan">Plan</h2>
<ul>
<li>Introduction ; pourquoi ?</li>
<li>Comment ?</li>
</ul>
<h2 id="expérience">Expérience</h2>
<ul>
<li>Real Time Social Media Analytics</li>
</ul>
<h2 id="demande">Demande</h2>
<ul>
<li>Twitter: <code>20k msg/s</code>, <code>1msg = 10ko</code> pendant 24h</li>
<li>Facebook public: 1000 à 2000 msg/s en continu</li>
</ul>
<h2 id="en-pratique">En pratique</h2>
<ul>
<li>Twitter: 400 msg/s en continu, pics à 1500</li>
</ul>
<h2 id="origine-php">Origine (PHP)</h2>
<p><img src="img/bad_php.jpg" alt="History" /> </p>
<h2 id="introduction">Introduction</h2>
<ul>
<li>Traitement de donnée gros volume + faible latence</li>
<li>Typiquement <code>pulse</code></li>
</ul>
<p><a href="http://pulse.vigiglo.be/#/vgteam/TV_Shows" target="_blank"> DEMO </a></p>
<h1 id="druid">Druid</h1>
<h2 id="who">Who</h2>
<p>Metamarkets</p>
<h2 id="goal">Goal</h2>
<blockquote>
<p>Druid is an open source store designed for real-time exploratory analytics on large data sets.</p>
</blockquote>
<blockquote>
<p>hosted dashboard that would allow users to arbitrarily explore and visualize event streams.</p>
</blockquote>
<h2 id="concepts">Concepts</h2>
<ul>
<li>Column-oriented storage layout</li>
<li>distributed, shared-nothing architecture</li>
<li>advanced indexing structure</li>
</ul>
<h2 id="features">Features</h2>
<ul>
<li>fast aggregations</li>
<li>flexible filters</li>
<li>low latency data ingestion</li>
</ul>
<p><strong>arbitrary exploration of billion-row tables tables with sub-second latencies</strong></p>
<h2 id="proof">Proof</h2>
<div id="footer">
<a href="yannesposito.com">Y</a>
</div>
</body>
</html>

BIN
druid/druid.pdf Normal file

Binary file not shown.

View file

@ -9,7 +9,7 @@
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="../.reveal.js-3.2.0/css/reveal.css">
<link rel="stylesheet" href="../.reveal.js-3.2.0/css/theme/solarized.css" id="theme">
<link rel="stylesheet" href="../.reveal.js-3.2.0/css/theme/default.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="../.reveal.js-3.2.0/lib/css/zenburn.css">
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
@ -130,7 +130,7 @@
center: false,
// available themes are in /css/theme
theme: Reveal.getQueryHash().theme || 'solarized',
theme: Reveal.getQueryHash().theme || 'default',
// default/cube/page/concave/zoom/linear/fade/none
transition: Reveal.getQueryHash().transition || 'linear',

BIN
druid/img/bad_php.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View file

@ -102,6 +102,8 @@ $endif$
\definecolor{cyan}{RGB}{42,161,152}
\definecolor{green}{RGB}{133,153,0}
% -----------------------------------------
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\hypersetup{breaklinks=true,
bookmarks=true,
pdfauthor={$author-meta$},