From 74ce7d9bf0c837b89c48579b6c97dac3ce042093 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 25 Mar 2012 19:01:56 +0200 Subject: [PATCH] * small colouriser tool to run .hs files through HsColour --- tools/colouriser/LICENSE | 3 ++ tools/colouriser/colour.cabal | 64 +++++++++++++++++++++++++++++++++++ tools/colouriser/colour.hs | 21 ++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 tools/colouriser/LICENSE create mode 100644 tools/colouriser/colour.cabal create mode 100644 tools/colouriser/colour.hs diff --git a/tools/colouriser/LICENSE b/tools/colouriser/LICENSE new file mode 100644 index 000000000..44ade8735 --- /dev/null +++ b/tools/colouriser/LICENSE @@ -0,0 +1,3 @@ +This program comes with absolutely no warranty and I can't guarantee that it's not going to explode in your face. + +In addition to this, I don't care what you do with this. \ No newline at end of file diff --git a/tools/colouriser/colour.cabal b/tools/colouriser/colour.cabal new file mode 100644 index 000000000..c74e6f2da --- /dev/null +++ b/tools/colouriser/colour.cabal @@ -0,0 +1,64 @@ +-- colour.cabal auto-generated by cabal init. For additional options, +-- see +-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr. +-- The name of the package. +Name: colour + +-- The package version. See the Haskell package versioning policy +-- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for +-- standards guiding when and how versions should be incremented. +Version: 0.1 + +-- A short (one-line) description of the package. +Synopsis: Shortcut program to use HsColour + +-- A longer description of the package. +-- Description: + +-- URL for the project homepage or repository. +Homepage: http://tazj.in/ + +-- The license under which the package is released. +License: OtherLicense + +-- The file containing the license text. +License-file: LICENSE + +-- The package author(s). +Author: tazjin + +-- An email address to which users can send suggestions, bug reports, +-- and patches. +-- Maintainer: + +-- A copyright notice. +-- Copyright: + +Category: Web + +Build-type: Simple + +-- Extra files to be distributed with the package, such as examples or +-- a README. +-- Extra-source-files: + +-- Constraint on the version of Cabal needed to build this package. +Cabal-version: >=1.2 + + +Executable colour + -- .hs or .lhs file containing the Main module. + Main-is: colour.hs + + -- Packages needed in order to build this package. + Build-depends: + base, + options, + hscolour + + -- Modules not exported by this package. + -- Other-modules: + + -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source. + -- Build-tools: + \ No newline at end of file diff --git a/tools/colouriser/colour.hs b/tools/colouriser/colour.hs new file mode 100644 index 000000000..03ae8d51f --- /dev/null +++ b/tools/colouriser/colour.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE TemplateHaskell #-} + +import Control.Monad (unless) +import Language.Haskell.HsColour.Colourise (defaultColourPrefs) +import Language.Haskell.HsColour.CSS +import Options + +defineOptions "MainOptions" $ do + stringOption "optFile" "file" "" + "Name of the .hs file. Will be used for the HTML file as well" + +colorCode :: String -> String -> IO () +colorCode input output = do + code <- readFile input + writeFile output $ hscolour False code + +main :: IO () +main = runCommand $ \opts args -> do + let file = optFile opts + unless (file == "") $ + colorCode (file ++ ".hs") (file ++ ".html") \ No newline at end of file