packages feed

omaketex (empty) → 0.1.0.0

raw patch · 4 files changed

+147/−0 lines, 4 filesdep +basedep +optparse-applicativedep +shakespeare-textsetup-changed

Dependencies added: base, optparse-applicative, shakespeare-text, shelly, text

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Hiromi ISHII++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Hiromi ISHII nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ omaketex.cabal view
@@ -0,0 +1,28 @@+-- Initial omaketex.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++name:                omaketex+version:             0.1.0.0+synopsis:            A simple tool to generate OMakefile for latex files.+description:         A simple toot to generate OMakefile for latex files.+license:             BSD3+license-file:        LICENSE+author:              Hiromi ISHII+maintainer:          konn.jinro_at_gmail.com+-- copyright:           +category:            Text+build-type:          Simple+-- extra-source-files:  +cabal-version:       >=1.10++executable omaketex+  main-is:             omaketex.hs+  -- other-modules:       +  -- other-extensions:    +  build-depends:       base                 >=4.6 && <4.7+               ,       shakespeare-text     == 1.0.*+               ,       optparse-applicative == 0.5.*+               ,       shelly               == 1.3.*+               ,       text                 == 0.11.*+  -- hs-source-dirs:      +  default-language:    Haskell2010
+ omaketex.hs view
@@ -0,0 +1,87 @@+{-# LANGUAGE DeriveDataTypeable, ExtendedDefaultRules, OverloadedStrings #-}+{-# LANGUAGE QuasiQuotes, RecordWildCards                                #-}+{-# OPTIONS_GHC -fno-warn-type-defaults -fno-warn-unused-do-bind         #-}+module Main where+import           Control.Monad+import           Data.Monoid+import qualified Data.Text             as T+import           Options.Applicative+import           Shelly+import           Text.Shakespeare.Text++default (T.Text)++dotTeX :: T.Text -> T.Text+dotTeX = flip T.append ".tex"++omakeroot :: T.Text+omakeroot = [st|+open build/LaTeX+DefineCommandVars()+.SUBDIRS: .+|]++data Settings = Settings { texDocs :: [T.Text]+                         , deps    :: [String]+                         , git     :: Bool+                         } deriving (Read, Show, Eq, Ord)++settings :: ParserInfo Settings+settings = info (helper <*> parser)+                (fullDesc+              <> header "omaketex - OMakefile generation for latex. "+              <> progDesc "Generates a OMakefile for latex files. It also supports git." )+  where+    parser = Settings <$> arguments1 (fmap T.pack <$> str) (metavar "TeXs" <> help "TeX files to typeset.")+                      <*> many (strOption (metavar "FILE" <> help "File(s) tex depends on (e.g. bib, sty...)"+                                        <> long "deps" <> short 'd')+                               )+                      <*> switch (long "git" <> short 'g' <> help "whether commit & push after typesettings success.")++omakefile :: Settings -> T.Text+omakefile (Settings ins dps gits) = T.tail [st|+LATEX = platex+MAKEINDEX = mendex -U+DVIPDFM = dvipdfmx+BIBTEX = pbibtex++TEXINPUTS = #{T.unwords $ map dotTeX ins}+#{T.unlines $ map latexDocument ins}+TEXDEPS[] =+#{T.unlines $ map indent $ map T.pack dps}+.DEFAULT: #{T.unwords $ concatMap dviAndPdf ins}+.BUILD_SUCCESS:+  /usr/bin/open -aSkim -g #{T.unwords $ map dotPdf ins}+  #{gitmessage gits}+|]++gitmessage :: Bool -> T.Text+gitmessage True = [st|(git commit -am "$(shell date +%Y-%m-%d\ %T\ %Z)" && git push origin master) || echo "nothing to commit nor push"|]+gitmessage False = ""++dotPdf :: T.Text -> T.Text+dotPdf x = x <> ".pdf"++dviAndPdf :: T.Text -> [T.Text]+dviAndPdf x = [x <> ".pdf", x <> ".dvi"]++indent :: T.Text -> T.Text+indent = T.append "    "++latexDocument :: T.Text -> T.Text+latexDocument base = [st|LaTeXDocument(#{base}, #{base})|]++main :: IO ()+main = do+  set@Settings{..} <- execParser settings+  shelly $ do+    forM_ texDocs $ \fname -> do+      let fp | fname `hasExt` "tex" = fromText fname+             | otherwise           = fname <.> "tex"+      touchfile fp+      when git $ cmd "git" "add" fp+    writefile "OMakeroot" omakeroot+    writefile "OMakefile" $ omakefile set+    when git $ do+      cmd "git" "add" "OMakeroot"+      cmd "git" "add" "OMakefile"