snaplet-coffee 0.1.0.0 → 0.1.0.1
raw patch · 3 files changed
+20/−6 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
snaplet-coffee.cabal view
@@ -2,17 +2,19 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: snaplet-coffee-version: 0.1.0.0--- synopsis:-description: A simple snaplet based off of 'snaplet-fay'- but for CoffeeScript.+version: 0.1.0.1+synopsis: CoffeeScript for Snap, auto-compilation and pre-compilation.+description: A simple snaplet based off of 'snaplet-fay' but for CoffeeScript. license: GPL-3 license-file: LICENSE author: Kevin van Rooijen maintainer: kevin.van.rooijen@gmail.com copyright: Copyright (C) 2013 Kevin van Rooijen-category: Snap+category: Web, Snap build-type: Simple+homepage: https://github.com/AtticHacker/snaplet-coffee+bug-reports: https://github.com/AtticHacker/snaplet-coffee/issues+ cabal-version: >=1.8 data-files:
src/Snap/Snaplet/Coffee.hs view
@@ -19,6 +19,7 @@ import Control.Monad (liftM) import Paths_snaplet_coffee +-- | Snaplet-Coffee initializer initCoffee :: SnapletInit c CoffeeScript initCoffee = makeSnaplet "coffee" "description" dataDir $ do config <- getSnapletUserConfig@@ -35,6 +36,7 @@ where dataDir = Just $ liftM (++ "/resources") getDataDir configOptions = ["compilerPath", "compilerMode", "destinationPath"] +-- | Serves the compiled CoffeeScript files coffeeServe :: Handler b CoffeeScript () coffeeServe = do modifyResponse . setContentType $ "text/javascript;charset=utf-8"@@ -44,6 +46,7 @@ when (Development == compileMode cfg) $ liftIO $ compileFiles cfg [requestedFile] serveDirectory $ destinationDir cfg +-- | Compiles the files that are being served, but ignores all other files. compileFiles :: MonadIO m => CoffeeScript -> [FilePath] -> m () compileFiles cfg fp = do let coffeeStruct = Coffee (compiler cfg) False
src/Snap/Snaplet/Coffee/Utils.hs view
@@ -14,6 +14,7 @@ import System.Directory import System.FilePath +-- | Simple data structure for CompileMode data CompileMode = Development | Production deriving (Show, Eq) -- | The CoffeeScript Snaplet Configuration@@ -24,41 +25,49 @@ , destinationDir :: FilePath } deriving (Show) +-- | Gets all the .coffee files in the source directory allCoffeeFiles :: CoffeeScript -> IO [FilePath] allCoffeeFiles cfg = do let p = srcDir cfg a <- getDirectoryContents p return $ map (</> srcDir cfg) $ filterCoffee a +-- | Simple reverse taker takeReverse :: Int -> [a] -> [a] takeReverse i = reverse . take i . reverse +-- | Filters the .coffee files filterCoffee :: [String] -> [String] filterCoffee = filter ((==) ".coffee" . takeReverse 7) +-- | Source directory srcDir :: CoffeeScript -> FilePath srcDir = (</> "coffee") . snapletFilePath +-- | Destination directory destDir :: CoffeeScript -> FilePath destDir = (</> "js") . snapletFilePath +-- | Function to create directories if they don't exist createDirUnlessExists :: FilePath -> IO () createDirUnlessExists fp = do dirExists <- doesDirectoryExist fp unless dirExists $ createDirectory fp +-- | Gets the CompileMode getCompilerMode :: Maybe String -> CompileMode getCompilerMode Nothing = Production getCompilerMode (Just "Development") = Development getCompilerMode (Just "Production") = Production getCompilerMode (Just x) = error $ x ++ " is not a valid Compiler mode for snaplet-coffeescript. -- devel.cfg" +-- | Gets the destination directory getDestDir :: Maybe String -> CoffeeScript -> FilePath getDestDir Nothing c = destDir c getDestDir (Just "") c = destDir c getDestDir (Just x) _ = x -+-- | Converts path/to/file.js to file.coffee requestedCoffeeFile :: String -> FilePath requestedCoffeeFile = ("/"++) . (++"coffee") . reverse .dropWhile con2 . takeWhile con1 . reverse