From 21a7d47f3b06e72e0337267d6f4e0b600f098db5 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Thu, 23 Oct 2014 05:56:39 +0300 Subject: [PATCH] Fixes for import Handler indentation --- yesod-bin/AddHandler.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/yesod-bin/AddHandler.hs b/yesod-bin/AddHandler.hs index 9c59c59b..acd9ba90 100644 --- a/yesod-bin/AddHandler.hs +++ b/yesod-bin/AddHandler.hs @@ -1,13 +1,13 @@ +{-# LANGUAGE PatternGuards #-} module AddHandler (addHandler) where import Prelude hiding (readFile) import System.IO (hFlush, stdout) import Data.Char (isLower, toLower, isSpace) -import Data.List (isPrefixOf, isSuffixOf) +import Data.List (isPrefixOf, isSuffixOf, stripPrefix) import qualified Data.Text as T import qualified Data.Text.IO as TIO import System.Directory (getDirectoryContents, doesFileExist) -import Control.Monad (when) -- strict readFile readFile :: FilePath -> IO String @@ -62,18 +62,18 @@ fixApp :: String -> String -> String fixApp name = unlines . reverse . go . reverse . lines where - l = "import Handler." ++ name + l spaces = "import " ++ spaces ++ "Handler." ++ name - go [] = [l] + go [] = [l ""] go (x:xs) - | "import Handler." `isPrefixOf` x = l : x : xs + | Just y <- stripPrefix "import " x, "Handler." `isPrefixOf` dropWhile (== ' ') y = l (takeWhile (== ' ') y) : x : xs | otherwise = x : go xs fixCabal :: String -> String -> String fixCabal name = unlines . reverse . go . reverse . lines where - l = "import Handler." ++ name + l = " Handler." ++ name go [] = [l] go (x:xs)