shake-minify (empty) → 0.1.0
raw patch · 4 files changed
+90/−0 lines, 4 filesdep +basedep +bytestringdep +css-textsetup-changed
Dependencies added: base, bytestring, css-text, hjsmin, shake, text
Files
- LICENSE +20/−0
- Setup.hs +2/−0
- shake-minify.cabal +28/−0
- src/Development/Shake/Minify.hs +40/−0
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2015 Luke Hoersten++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ shake-minify.cabal view
@@ -0,0 +1,28 @@+name: shake-minify+version: 0.1.0+synopsis: Shake Minify Actions+description: Shake minify actions for CSS and JS files.+license: BSD3+license-file: LICENSE+author: Luke Hoersten+maintainer: luke@hoersten.org+homepage: https://github.com/LukeHoersten/shake-minify+category: Web, Development+build-type: Simple+cabal-version: >=1.10++library+ exposed-modules: Development.Shake.Minify+ build-depends: base >= 4.7 && < 4.8+ , bytestring >= 0.10 && < 0.11+ , css-text >= 0.1 && < 0.2+ , hjsmin >= 0.1 && < 0.2+ , shake >= 0.14 && < 0.15+ , text >= 1.2 && < 1.3+ hs-source-dirs: src+ default-language: Haskell2010+ ghc-options: -Wall -fwarn-tabs++source-repository head+ type: git+ location: git://github.com/LukeHoersten/shake-minify.git
+ src/Development/Shake/Minify.hs view
@@ -0,0 +1,40 @@+-- | Minify JS and CSS files similar to the following example:+--+-- @+-- main :: IO ()+-- main = shakeArgs shakeOptions $ do+-- want ["\/\/*.min.js", "\/\/*.min.css"]+-- "//*.min.js" *> minifyJs+-- "//*.min.css" *> minifyCss+-- @++module Development.Shake.Minify where++import qualified Data.ByteString.Lazy as BS+import qualified Data.Text.IO as TIO+import qualified Data.Text.Lazy as LT+import qualified Data.Text.Lazy.Builder as LTB+import Development.Shake (Action, liftIO, need)+import Development.Shake.FilePath (dropExtension, (-<.>))+import qualified Text.CSS.Parse as CSS+import qualified Text.CSS.Render as CSS+import qualified Text.Jasmine as JS+++-- | Given a @.min.js@ path, find the @.js@ file and minify it into the specified file name.+minifyJs :: FilePath -- ^ Desired minified JS files (ex: @"//*.min.js"@)+ -> Action ()+minifyJs minJs = do+ let js = dropExtension minJs -<.> "js"+ need [js]+ liftIO $ BS.writeFile minJs =<< JS.minifyFile js+++-- | Given a @.min.css@ path, find the @.css@ file and minify it into the specified file name.+minifyCss :: FilePath -- ^ Desired minified CSS files (ex: @"//*.min.css"@)+ -> Action ()+minifyCss minCss = do+ let css = dropExtension minCss -<.> "css"+ need [css]+ liftIO $ TIO.writeFile minCss . LT.toStrict . LTB.toLazyText . minify =<< TIO.readFile css+ where minify = either error CSS.renderNestedBlocks . CSS.parseNestedBlocks