packages feed

hakyll-contrib-elm (empty) → 0.1.0.0

raw patch · 6 files changed

+153/−0 lines, 6 filesdep +basedep +bytestringdep +directorysetup-changed

Dependencies added: base, bytestring, directory, hakyll, hakyll-contrib-elm, process, temporary

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Erik Stevenson (c) 2016++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Erik Stevenson nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,29 @@+# Use Elm and Hakyll
+
+## Usage
+
+Verify you have the `elm-make` build tool installed: `npm install -g elm`
+
+```haskell
+{-# LANGUAGE OverloadedStrings #-}
+
+module Main where
+
+import Hakyll
+import Hakyll.Contrib.Elm
+
+main :: IO ()
+main = hakyll $ do
+
+  match "elm/*.elm" $ do
+    route $ setExtension "js" `composeRoutes` gsubRoute "elm/" (const "js/")
+    compile elmMake
+
+  match "index.html" $ do
+    route idRoute
+    compile $
+      getResourceBody
+      >>= loadAndApplyTemplate "templates/layout.html" defaultContext
+
+  match "templates/*" $ compile templateCompiler
+```
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple
+
+main = defaultMain
+ example/Main.hs view
@@ -0,0 +1,23 @@+
+{-# LANGUAGE OverloadedStrings #-}
+
+module Main where
+
+import Hakyll
+import Hakyll.Contrib.Elm
+
+main :: IO ()
+main = hakyll $ do
+
+  match "elm/*.elm" $ do
+    route $ setExtension "js" `composeRoutes` gsubRoute "elm/" (const "js/")
+    compile elmMake
+
+  match "index.html" $ do
+    route idRoute
+    compile $
+      getResourceBody
+      >>= loadAndApplyTemplate "templates/layout.html" defaultContext
+
+  match "templates/*" $ compile templateCompiler
+
+ hakyll-contrib-elm.cabal view
@@ -0,0 +1,40 @@+name:                hakyll-contrib-elm+version:             0.1.0.0+synopsis:            Compile Elm code for inclusion in Hakyll static site.+description:+  A Hakyll extension which allows building and including Elm+  projects in static sites.+homepage:            https://github.com/narrative/hakyll-contrib-elm#readme+bug-reports:         https://github.com/narrative/hakyll-contrib-elm/issues+license:             BSD3+license-file:        LICENSE+author:              Erik Stevenson+maintainer:          eriknstevenson@gmail.com+copyright:           2016 Erik Stevenson+category:            Web+build-type:          Simple+cabal-version:       >=1.10++extra-source-files:+    README.md++library+  hs-source-dirs:      src+  exposed-modules:     Hakyll.Contrib.Elm+  default-language:    Haskell2010+  ghc-options:         -Wall+  build-depends:       base < 5+                     , bytestring+                     , directory+                     , hakyll+                     , process+                     , temporary++executable hakyll-contrib-elm-example+  hs-source-dirs:      example+  main-is:             Main.hs+  default-language:    Haskell2010+  ghc-options:         -threaded -Wall+  build-depends:       base < 5+                     , hakyll+                     , hakyll-contrib-elm
+ src/Hakyll/Contrib/Elm.hs view
@@ -0,0 +1,28 @@+{-# LANGUAGE OverloadedStrings #-}++module Hakyll.Contrib.Elm (elmMake) where++import qualified Data.ByteString.Char8 as BS+import           Data.Monoid+import           Hakyll+import           System.Directory (getCurrentDirectory)+import           System.IO.Temp (withTempFile)+import           System.Process (callCommand)++-- | Use the 'elm-make' tool to build a elm source file and+-- generate javascript. (Requires you have elm-make installed and available on your PATH.)+elmMake :: Compiler (Item String)+elmMake =+  cached "Hakyll.Contrib.Elm.elmMake" $ do+    inputFile <- getResourceFilePath+    elmOutput <- unsafeCompiler $ do+      dir <- getCurrentDirectory+      withTempFile dir "output.js" $ \fp h -> do+        let outputFile = "--output=" <> fp+            warn = "--warn"+            args = unwords [inputFile, warn, outputFile]+            cmd = "elm-make" <> " " <> args+        putStrLn $ "Running command: " <> cmd+        callCommand cmd+        fmap BS.unpack $ BS.hGetContents h+    makeItem elmOutput