-- |
-- Module : Main
-- Copyright : (c) OleksandrZhabenko 2022
-- License : MIT
-- Stability : Experimental
-- Maintainer : olexandr543@yahoo.com
--
-- Simple tool to create html presentation for text. The html and css template is taken from different tutorials
-- in the Internet (with changes). The idea is to post some text on the background partially transparent image.
-- The meaning of the command line parameters by the first modifier is the following:
--
-- "f" -> name of the file where the text presented is written;
--
-- "i" -> path to the image file to be used;
--
-- "h" -> title and the main header;
--
-- "a" -> author;
--
-- "p" -> width of the textual div in percentage (no % sign needed);
--
-- "d" -> width of the header container in percentage (no % sign needed);
--
-- "s" -> font-size in percents for text;
--
-- "o" -> opacity for the image;
--
-- "w" -> width of the main container;
--
-- "b" -> background-color;
--
-- "c" -> color;
module Main where
import Data.Lists.FLines (newLineEnding)
import System.Environment (getArgs)
import CLI.Arguments
import CLI.Arguments.Parsing
import CLI.Arguments.Get
import Data.Monoid (mconcat,mappend)
import Data.List (intercalate)
main :: IO ()
main = do
args <- getArgs
let argsB = fst . takeBsR bSpecs $ args
file = mconcat . getB "f" $ argsB
image = mconcat . getB "i" $ argsB
header = (\ts -> if null ts then "Заголовок" else ts) . mconcat . getB "h" $ argsB
author = (\ts -> if null ts then "Автор" else ts) . mconcat . getB "a" $ argsB
fontsize = (\ts -> if null ts then "100" else ts) . mconcat . getB "s" $ argsB
opacity = (\ts -> if null ts then "0.5" else ts) . mconcat . getB "o" $ argsB
width = (\ts -> if null ts then "1080" else ts) . mconcat . getB "w" $ argsB
widthH = (\ts -> if null ts then "10" else ts) . mconcat . getB "d" $ argsB
widthP = (\ts -> if null ts then "70" else ts) . mconcat . getB "p" $ argsB
backgroundcolor = (\ts -> if null ts then "#025abb" else ts) . mconcat . getB "b" $ argsB
color = (\ts -> if null ts then "#fed501" else ts) . mconcat . getB "c" $ argsB
text <- readFile file
let lineS = concatMap (\xs -> mconcat [" ", xs, "<br>", newLineEnding]) . lines $ text
appendFile (header `mappend` ".html") . {-
mconcat $ [intercalate newLineEnding ["<html>", "<head>",
"<meta charset=\"UTF-8\">", "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">",
"<title>"], header, intercalate newLineEnding ["</title>", "<author class=\"author\">"]
, author, intercalate newLineEnding ["</author>", "<style>", ".header2 {",
" padding-left: 80px;", "}", ".main-container {", " width: 100%;", " display: flex;",
" direction: row;", "}", "", ".main-body {", " width: "], width,
intercalate newLineEnding ["px;", "}", "", ".header-container {", " width: "], widthH,
intercalate newLineEnding ["%;", " padding-left: 40px;", " padding-right: 20px;", "}", "", ".paragraph {",
" font-family: Helvetica, sans-serif;", " width: "], widthP,
intercalate newLineEnding ["%;", " padding-left: 40px;", " padding-right: 40px;",
" font-weight: 400;", " font-size: 16pt;", " text-align: justify;", " line-height: 161.8%;",
" font-size: "], fontsize, intercalate newLineEnding ["%;", " background-color: "]
, backgroundcolor, intercalate newLineEnding [";", ""," color: "]
, color, intercalate newLineEnding [";","}", "", ".img {", " opacity: "]
, opacity, intercalate newLineEnding [";", " width: 200px;", " padding: 20px;",
"}", "", ".author {", " font-size: 18pt;", " font-weight: 500;", "}", "</style>", "</head>", "<body>",
" <div class=\"main-container\">", " <header>", " <div class=\"header-container\">",
" <img class=\"img\" src="], image, intercalate newLineEnding [">",
" </div>", " </header>", " <div class=\"main-body\">",
" <div style=\"justify-content: center;\">", " <h2 class=\"header2\">"]
, header, intercalate newLineEnding ["</h2>", " <p class=\"paragraph\">",""]
, lineS, intercalate newLineEnding [" </p>", " </div>",
" </div>", " </div>", "</body>", "</html>", ""]]
-} helper1 newLineEnding [header,author,width,widthH,widthP,fontsize,backgroundcolor,color,opacity,image,header,lineS] $ [
["<html>", "<head>", "<meta charset=\"UTF-8\">",
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">", "<title>"],
["</title>", "<author class=\"author\">"], ["</author>", "<style>", ".header2 {",
" padding-left: 80px;", "}", ".main-container {", " width: 100%;", " display: flex;",
" direction: row;", "}", "", ".main-body {", " width: "],
["px;", "}", "", ".header-container {", " width: "],["%;", " padding-left: 40px;",
" padding-right: 20px;", "}", "", ".paragraph {", " font-family: Helvetica, sans-serif;",
" width: "],["%;", " padding-left: 40px;", " padding-right: 40px;",
" font-weight: 400;", " text-align: justify;", " line-height: 161.8%;",
" font-size: "],["%;", " background-color: "],[";", " color: "],
[";","}", "", ".img {", " opacity: "],[";", " width: 200px;", " padding: 20px;",
"}", "", ".author {", " font-size: 18pt;", " font-weight: 500;", "}", "</style>", "</head>", "<body>",
" <div class=\"main-container\">", " <header>", " <div class=\"header-container\">",
" <img class=\"img\" src=\""],["\">"," </div>", " </header>",
" <div class=\"main-body\">", " <div style=\"justify-content: center;\">",
" <h2 class=\"header2\">"],["</h2>", " <p class=\"paragraph\">",""],
[" </p>", " </div>", " </div>", " </div>", "</body>", "</html>", ""]]
bSpecs = zip ["f","i","h","a","p","d","s","o","w","b","c"] . cycle $ [1]
helper1 :: [a] -> [[a]] -> [[[a]]] -> [a]
helper1 delim tss@(ys:yss) zsss@(zss:usss) = mconcat [intercalate delim zss, ys, helper1 delim yss usss]
helper1 delim _ (zss:usss) = intercalate delim zss
helper1 _ _ _ = []