{-# LANGUAGE OverloadedStrings #-}

module Text.Internal.Cassius (i2bMixin) where

import qualified Data.Text.Lazy as TL
import Text.IndentToBrace (i2b)

i2bMixin :: String -> String
i2bMixin :: [Char] -> [Char]
i2bMixin [Char]
s' =
    Text -> [Char]
TL.unpack
        (Text -> [Char]) -> Text -> [Char]
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Text
stripEnd Text
"}"
        (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Text
stripFront Text
"mixin {"
        (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text
TL.strip
        (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
TL.pack
        ([Char] -> Text) -> [Char] -> Text
forall a b. (a -> b) -> a -> b
$ [Char] -> [Char]
i2b
        ([Char] -> [Char]) -> [Char] -> [Char]
forall a b. (a -> b) -> a -> b
$ [[Char]] -> [Char]
unlines
        ([[Char]] -> [Char]) -> [[Char]] -> [Char]
forall a b. (a -> b) -> a -> b
$ [Char]
"mixin" [Char] -> [[Char]] -> [[Char]]
forall a. a -> [a] -> [a]
: (([Char] -> [Char]) -> [[Char]] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
map ([Char]
"    " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++) ([[Char]] -> [[Char]]) -> [[Char]] -> [[Char]]
forall a b. (a -> b) -> a -> b
$ [Char] -> [[Char]]
lines [Char]
s')
  where
    stripFront :: Text -> Text -> Text
stripFront Text
x Text
y =
        case Text -> Text -> Maybe Text
TL.stripPrefix Text
x Text
y of
            Maybe Text
Nothing -> Text
y
            Just Text
z -> Text
z
    stripEnd :: Text -> Text -> Text
stripEnd Text
x Text
y =
        case Text -> Text -> Maybe Text
TL.stripSuffix Text
x Text
y of
            Maybe Text
Nothing -> Text
y
            Just Text
z -> Text
z