hsass 0.2.0 → 0.3.0
raw patch · 6 files changed
+87/−30 lines, 6 filesdep +bytestringdep +transformersdep −mtlPVP ok
version bump matches the API change (PVP)
Dependencies added: bytestring, transformers
Dependencies removed: mtl
API changes (from Hackage documentation)
- Text.Sass.Compilation: instance SassResult SassExtendedResult
- Text.Sass.Compilation: instance Show SassExtendedResult
+ Text.Sass.Compilation: instance SassResult ByteString
+ Text.Sass.Compilation: instance SassResult a => SassResult (SassExtendedResult a)
+ Text.Sass.Compilation: instance Show (SassExtendedResult a)
+ Text.Sass.Compilation: type ExtendedResultBS = IO (Either SassError (SassExtendedResult ByteString))
- Text.Sass.Compilation: data SassExtendedResult
+ Text.Sass.Compilation: data SassExtendedResult a
- Text.Sass.Compilation: resultIncludes :: SassExtendedResult -> IO [String]
+ Text.Sass.Compilation: resultIncludes :: SassExtendedResult a -> IO [String]
- Text.Sass.Compilation: resultSourcemap :: SassExtendedResult -> IO (Maybe String)
+ Text.Sass.Compilation: resultSourcemap :: SassExtendedResult a -> IO (Maybe String)
- Text.Sass.Compilation: resultString :: SassExtendedResult -> String
+ Text.Sass.Compilation: resultString :: SassExtendedResult a -> a
- Text.Sass.Compilation: type ExtendedResult = IO (Either SassError SassExtendedResult)
+ Text.Sass.Compilation: type ExtendedResult = IO (Either SassError (SassExtendedResult String))
Files
- CHANGELOG.md +21/−4
- Text/Sass/Compilation.hs +34/−15
- Text/Sass/Options/Internal.hs +3/−0
- Text/Sass/Utils.hs +16/−4
- Text/Sass/Values/Internal.hs +3/−0
- hsass.cabal +10/−7
CHANGELOG.md view
@@ -2,17 +2,34 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## 0.2.0 - 2015-06-01+## [0.3.0] - 2015-07-10+### Added+- Support for a `ByteString` result (thanks to [Andy+ Morris](https://github.com/jakubfijalkowski/hsass/pull/3) ).+ ### Changed-- Return type of 'compileString' and 'compileFile' is now polymorphic - may- return both 'String' and 'SassExtendedResult' on success.+- `SassExtendedResult` is now parametrised by a base result type (e.g.+ `String`).+- The package depends on `transformers` instead of `mtl`.++### Fixed+- Fix GHC 7.10.1 warnings related to AMP proposal.+- Support for stack's lts-2.17 resolver.++## [0.2.0] - 2015-06-01+### Changed+- Return type of `compileString` and `compileFile` is now polymorphic - may+ return both `String` and `SassExtendedResult` on success. - Fixes in documentation (articles, mostly). ### Added-- 'SassExtendedResult' with a compiled string, a list of files included during+- `SassExtendedResult` with a compiled string, a list of files included during compilation and a source map. ## 0.1.0 - 2015-04-11 ### Added - Support for functions, importers, headers and sass values. - Compilation of files and strings.++[0.2.0]: https://github.com/jakubfijalkowski/hsass/compare/v0.1.0...v0.2.0+[0.3.0]: https://github.com/jakubfijalkowski/hsass/compare/v0.2.0...v0.3.0
Text/Sass/Compilation.hs view
@@ -1,5 +1,6 @@ -- | Compilation of sass source or sass files. {-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TypeSynonymInstances #-} module Text.Sass.Compilation@@ -11,6 +12,7 @@ , SassExtendedResult , StringResult , ExtendedResult+ , ExtendedResultBS , resultString , resultIncludes , resultSourcemap@@ -27,7 +29,10 @@ ) where import qualified Bindings.Libsass as Lib+import Data.ByteString (ByteString, packCString)+#if !MIN_VERSION_base(4,8,0) import Control.Applicative ((<$>))+#endif import Control.Monad (forM, (>=>)) import Foreign import Foreign.C@@ -40,31 +45,38 @@ errorContext :: ForeignPtr Lib.SassContext } --- | Represents extended result - compiled string with a list of includes and--- a source map.+-- | Represents extended result - compiled string (or other string-like type,+-- eg. 'ByteString') with a list of includes and a source map. ----- Subject to name change in future versions.-data SassExtendedResult = SassExtendedResult {- resultString :: String, -- ^ Compiled string.+-- Subject to name change in future.+data SassExtendedResult a = SassExtendedResult {+ resultString :: a, -- ^ Compiled string. resultContext :: ForeignPtr Lib.SassContext } -- | Result of compilation - 'Either' 'SassError' or a compiled string. ----- Subject to name change in future versions.+-- Subject to name change in future. type StringResult = IO (Either SassError String) -- | Result of compilation - 'Either' 'SassError' or extended results - a -- compiled string with a list of included files and a source map. ----- Subject to name change in future versions.-type ExtendedResult = IO (Either SassError SassExtendedResult)+-- Subject to name change in future.+type ExtendedResult = IO (Either SassError (SassExtendedResult String))+--+-- | Result of compilation - 'Either' 'SassError' or extended results - a+-- compiled 'ByteString' with a list of included files and a source map.+--+-- Subject to name change in future.+type ExtendedResultBS = IO (Either SassError (SassExtendedResult ByteString)) -- | Typeclass that allows multiple results from compilation functions. ----- Currently, only two types are supported - 'String' and 'SassExtendedResult'.--- The first provides only a compiled string, the latter one gives access to a--- list of included files and a source map (if available).+-- Currently, only three types are supported - 'String', 'ByteString' and+-- @'SassExtendedResult' a@ (where a is something that is an instance of+-- 'SassResult'). The first provides only a compiled string, the latter one+-- gives access to a list of included files and a source map (if available). class SassResult a where toSassResult :: ForeignPtr Lib.SassContext -> IO a @@ -75,7 +87,7 @@ instance Eq SassError where (SassError s1 _) == (SassError s2 _) = s1 == s2 -instance Show SassExtendedResult where+instance Show (SassExtendedResult a) where show _ = "SassExtendedResult" -- | Only compiled code.@@ -85,8 +97,15 @@ !result' <- peekCString result return result' +-- | Only compiled code (UTF-8 encoding).+instance SassResult ByteString where+ toSassResult ptr = withForeignPtr ptr $ \ctx -> do+ result <- Lib.sass_context_get_output_string ctx+ !result' <- packCString result+ return result'+ -- | Compiled code with includes and a source map.-instance SassResult SassExtendedResult where+instance (SassResult a) => SassResult (SassExtendedResult a) where toSassResult ptr = do str <- toSassResult ptr return $ SassExtendedResult str ptr@@ -142,14 +161,14 @@ errorColumn = loadIntFromError Lib.sass_context_get_error_column -- | Loads a list of files that have been included during compilation.-resultIncludes :: SassExtendedResult -> IO [String]+resultIncludes :: SassExtendedResult a -> IO [String] resultIncludes ex = withForeignPtr (resultContext ex) $ \ctx -> do lst <- Lib.sass_context_get_included_files ctx len <- Lib.sass_context_get_included_files_size ctx forM (arrayRange $ fromIntegral len) (peekElemOff lst >=> peekCString) -- | Loads a source map if it was generated by libsass.-resultSourcemap :: SassExtendedResult -> IO (Maybe String)+resultSourcemap :: SassExtendedResult a -> IO (Maybe String) resultSourcemap ex = withForeignPtr (resultContext ex) $ \ctx -> do cstr <- Lib.sass_context_get_source_map_string ctx if cstr == nullPtr
Text/Sass/Options/Internal.hs view
@@ -1,6 +1,7 @@ -- | Copying 'SassOptions' into native context. This module is internal and -- should not be considered stable. {-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP #-} module Text.Sass.Options.Internal ( copyOptionsToNative@@ -8,7 +9,9 @@ ) where import qualified Bindings.Libsass as Lib+#if !MIN_VERSION_base(4,8,0) import Control.Applicative ((<$>))+#endif import Control.Monad ((>=>)) import Foreign import Foreign.C
Text/Sass/Utils.hs view
@@ -1,5 +1,6 @@ -- | Helper functions. This module is internal and should not be used in -- production code.+{-# LANGUAGE CPP #-} module Text.Sass.Utils ( -- * Interoperation with C API@@ -12,12 +13,23 @@ , arrayRange ) where -import Control.Monad.Loops (whileM_)-import Control.Monad.State.Strict-import Data.List (intercalate)+import Control.Monad (zipWithM_, (>=>))+import Control.Monad.IO.Class+import Control.Monad.Loops (whileM_)+import Control.Monad.Trans.Class+import Control.Monad.Trans.State.Strict+import Data.List (intercalate) import Foreign import Foreign.C-import System.FilePath (searchPathSeparator)+import System.FilePath (searchPathSeparator)++-- Fix for transformers-0.3.0.0 (used by lts-2.17 in stack).+#if !MIN_VERSION_transformers(0,4,0)+modify' :: (Monad m) => (s -> s) -> StateT s m ()+modify' f = do+ s <- get+ put $! f s+#endif -- | 'withOptionalCString' @str action@, if @str@ is 'Nothing', @action@ is not -- invoked, otherwise behaves like 'withCString'.
Text/Sass/Values/Internal.hs view
@@ -1,5 +1,6 @@ -- | Conversion of 'SassValue' or list of 'SassValue's into native -- representation. This module is internal and should not be considered stable.+{-# LANGUAGE CPP #-} module Text.Sass.Values.Internal ( toNativeValue@@ -9,7 +10,9 @@ ) where import qualified Bindings.Libsass as Lib+#if !MIN_VERSION_base(4,8,0) import Control.Applicative ((<$>))+#endif import Control.Monad (forM, (>=>)) import Foreign import Foreign.C
hsass.cabal view
@@ -1,5 +1,5 @@ name: hsass-version: 0.2.0+version: 0.3.0 license: MIT license-file: LICENSE author: Jakub Fijałkowski <fiolek94@gmail.com>@@ -46,13 +46,15 @@ , Text.Sass.Values.Internal , Text.Sass.Utils build-depends:- base >= 4.7 && < 5,- hlibsass >= 0.1.1,- data-default-class,- filepath >= 1.0,- mtl >= 2.2,- monad-loops >= 0.3+ base >= 4.7 && < 5+ , hlibsass >= 0.1.1+ , bytestring >= 0.10.0+ , data-default-class+ , filepath >= 1.0+ , transformers >= 0.3+ , monad-loops >= 0.3 hs-source-dirs: .+ other-extensions: CPP default-language: Haskell2010 ghc-options: -Wall @@ -63,6 +65,7 @@ ghc-options: -Wall build-depends: base >= 4.7 && < 5+ , bytestring >= 0.10.0 , hspec >= 2.1.5 , hspec-discover >= 2.1.5 , temporary >= 1.1