├── .gitignore ├── Hakyll └── Web │ └── Elm.hs ├── LICENSE ├── README.md ├── Setup.hs └── hakyll-elm.cabal /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | cabal-dev 3 | *.o 4 | *.hi 5 | *.chi 6 | *.chs.h 7 | .virthualenv 8 | *~ 9 | -------------------------------------------------------------------------------- /Hakyll/Web/Elm.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedStrings #-} 2 | module Hakyll.Web.Elm (elmStandaloneCompiler) 3 | where 4 | 5 | import Data.Monoid ((<>), mempty) 6 | import Data.String (fromString) 7 | import Data.Traversable (traverse) 8 | import Control.Applicative ((<$>)) 9 | import Control.Monad.Error (throwError) 10 | 11 | import Hakyll 12 | import Text.Blaze (preEscapedToMarkup) 13 | import Text.Blaze.Html5 ((!)) 14 | import Text.Blaze.Html.Renderer.String (renderHtml) 15 | 16 | import qualified Elm.Internal.Utils as Elm 17 | import qualified Text.Blaze.Html5 as H 18 | import qualified Text.Blaze.Html5.Attributes as Attr 19 | 20 | {-| Compiles an elm file to a div and inline Javascript. 21 | 22 | Expects elm-runtime.js to have already been loaded on the page. 23 | 24 | Works for files that only import from modules in the elm runtime. 25 | -} 26 | elmStandaloneCompiler :: Compiler (Item String) 27 | elmStandaloneCompiler = cached cacheName $ do 28 | it <- getResourceBody 29 | case traverse compileModule it of 30 | Left err -> throwError [err] 31 | Right out -> return out 32 | 33 | where cacheName = "Hakyll.Web.Elm.elmStandaloneCompiler" 34 | 35 | compileModule :: String -> Either String String 36 | compileModule bod = html modul <$> js 37 | where modul = maybe "Main" id . Elm.moduleName $ bod 38 | js = Elm.compile bod 39 | 40 | html :: String -- ^ Module Name 41 | -> String -- ^ Generated Javascript 42 | -> String -- ^ HTML & JS 43 | html modul genJS = renderHtml $ node <> instantiate 44 | where node = H.div ! Attr.id (fromString modul) $ mempty 45 | instantiate = (H.script ! Attr.type_ "text/javascript") 46 | . preEscapedToMarkup . unlines $ 47 | [ genJS 48 | , "var div = document.getElementById('" <> modul <> "', div);" 49 | , "Elm.embed(Elm." <> modul <> ", div);" 50 | ] 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Max New 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials provided 14 | with the distribution. 15 | 16 | * Neither the name of Max New nor the names of other 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | hakyll-elm 2 | ========== 3 | 4 | Hakyll wrapper for the Elm compiler. 5 | 6 | A wrapper for compiling [Elm]() programs to 7 | html/javascript in a Hakyll project. 8 | 9 | Currently supports single-module programs that only import from an Elm 10 | runtime that's manually included. 11 | -------------------------------------------------------------------------------- /Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | 3 | main = defaultMain 4 | -------------------------------------------------------------------------------- /hakyll-elm.cabal: -------------------------------------------------------------------------------- 1 | name: hakyll-elm 2 | version: 0.2.1 3 | synopsis: Hakyll wrapper for the Elm compiler. 4 | description: A wrapper for compiling 5 | Elm () programs to 6 | html/javascript in a Hakyll project. 7 | . 8 | Currently supports single-module programs that 9 | only import from an Elm runtime that's manually 10 | included. 11 | 12 | homepage: https://github.com/maxsnew/hakyll-elm 13 | license: BSD3 14 | license-file: LICENSE 15 | copyright: Copyright: (c) 2013 Max New 16 | author: Max New 17 | maintainer: maxsnew@gmail.com 18 | category: Web 19 | build-type: Simple 20 | cabal-version: >=1.10 21 | 22 | source-repository head 23 | type: git 24 | location: git://github.com/maxsnew/hakyll-elm.git 25 | branch: develop 26 | 27 | source-repository this 28 | type: git 29 | location: git://github.com/maxsnew/hakyll-elm.git 30 | branch: master 31 | tag: v0.2.1 32 | 33 | library 34 | -- Modules exported by the library. 35 | exposed-modules: Hakyll.Web.Elm 36 | build-depends: base >= 4.6 && < 4.7, 37 | hakyll >= 4.0 && < 4.5, 38 | Elm >= 0.10.1 && <= 0.11, 39 | mtl >= 1.0 && < 3.0, 40 | blaze-html >= 0.4 && < 0.7, 41 | blaze-markup >= 0.5 && < 0.6 42 | -- Base language which the package is written in. 43 | default-language: Haskell2010 44 | ghc-options: -Wall 45 | --------------------------------------------------------------------------------