Skip to content
This repository has been archived by the owner on Aug 23, 2018. It is now read-only.

Commit

Permalink
Integrating elm-reactor-index
Browse files Browse the repository at this point in the history
Added Index.elm and Util.elm to frontend.
Added necessary asset files (icons).
Fixed asset and source paths in Index.elm.
Changed Index.hs to serve the new index page.
Added compile hooks for Index.elm
Added assets to staticAssets in Main.hs.
Added index.js to staticAssets in Main.hs.
Added assets to .cabal file.
Added index.js to .cabal file.

Build succeeds. Build is tested. Works as expected. (as far as I can tell)
  • Loading branch information
JustusAdam committed Jul 20, 2015
1 parent 6d97dbf commit dc7c268
Show file tree
Hide file tree
Showing 26 changed files with 145 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dist
assets/_reactor/debug.js
assets/_reactor/index.js
elm-stuff
cabal.sandbox.config
.cabal-sandbox/
54 changes: 38 additions & 16 deletions Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,38 @@ import System.FilePath
import System.Directory


debugScriptPath :: FilePath
debugScriptPath = outputPath "debug.js"


indexScriptPath :: FilePath
indexScriptPath = outputPath "index.js"


toBuild :: [IO ()]
toBuild =
[ buildSideBar
, buildIndex
]


outputPath :: FilePath -> FilePath
outputPath = (("assets" </> "_reactor") </>)


elmCompile :: FilePath -> FilePath -> IO ()
elmCompile source target = do
(exitCode, out, err) <- readProcessWithExitCode
"elm-make"
[ "--yes", "frontend" </> source, "--output=" ++ target ]
""
case exitCode of
ExitSuccess -> return ()
ExitFailure _ ->
hPutStrLn stderr (unlines ["Failed to build" ++ source, "", out, err]) >>
exitFailure


main :: IO ()
main =
defaultMainWithHooks simpleUserHooks { postBuild = myPostBuild }
Expand All @@ -19,25 +51,15 @@ main =
myPostBuild :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
myPostBuild args flags pd lbi =
do putStrLn "Custom build step: creating and collecting all static resources"
buildSideBar
sequence_ toBuild
src <- readFile ("frontend" </> "debugger-implementation.js")
appendFile output src
appendFile debugScriptPath src
postBuild simpleUserHooks args flags pd lbi


output :: FilePath
output =
"assets" </> "_reactor" </> "debug.js"
buildSideBar :: IO ()
buildSideBar = elmCompile "SideBar.elm" debugScriptPath


buildSideBar :: IO ()
buildSideBar =
do (exitCode, out, err) <-
readProcessWithExitCode "elm-make" [ "--yes", "frontend" </> "SideBar.elm", "--output=" ++ output ] ""
case exitCode of
ExitSuccess ->
return ()

ExitFailure _ ->
do hPutStrLn stderr ("Failed to build SideBar.elm\n\n" ++ out ++ err)
exitFailure
buildIndex :: IO ()
buildIndex = elmCompile "Index.elm" indexScriptPath
Binary file added assets/_reactor/icons/aperture-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/audio-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/book-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/browser-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/code-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/cog-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/document-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/file-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/folder-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/hard-drive-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/home-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/key-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/list-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/lock-locked-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/spreadsheet-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/terminal-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/_reactor/icons/wrench-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/_reactor/wrench.png
Binary file not shown.
18 changes: 10 additions & 8 deletions backend/Index.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import qualified Data.ByteString.Lazy as LBS
import Data.List (intercalate)
import Data.Aeson as Json
import qualified Data.Map as Map
import Data.FileEmbed (embedFile)
import System.Directory (doesDirectoryExist, doesFileExist,
getDirectoryContents)
import System.FilePath ((</>), splitDirectories)
Expand All @@ -24,6 +23,10 @@ elmConfig :: FilePath
elmConfig = "elm-package.json"


compiledCodeLocation :: S.ByteString
compiledCodeLocation = "/_reactor/index.js"


{-|
Haskell representation fof the Model record as used by the frontend.
-}
Expand Down Expand Up @@ -122,13 +125,12 @@ indexPageTemplate :: S.ByteString -> S.ByteString -> S.ByteString
indexPageTemplate directory projectData = S.intercalate ""
[ "<head><title>"
, directory
, "</title><script charset=\"utf-8\">"
, $(embedFile "embedded/elm.js")
, "</script><script type=\"text/javascript\">"
, "</title><script charset=\"utf-8\" src=\""
, compiledCodeLocation
, "\"></script><script type=\"text/javascript\">"
, projectData
, "</script><style type=\"text/css\">"
, $(embedFile "embedded/index.css")
, "</style></head><body><script type=\"text/javascript\">\
, "</script><style>html, body {margin: 0;padding: 0;}</style>\
\</head><body><script type=\"text/javascript\">\
\window.addEventListener(\"DOMContentLoaded\", function (){ \
\Elm.fullscreen(Elm.Index, { modelPort: document.initialModel });})\
\</script></body>\n"
Expand Down Expand Up @@ -159,7 +161,7 @@ elmIndexGenerator directory = do
allFiles <- liftIO $ filterM (doesFileExist . (directory </>)) entries
configExists <- liftIO $ doesFileExist $ "." </> elmConfig
config <- if configExists
then decodeStrict <$> (liftIO $ S.readFile $ "." </> elmConfig)
then decodeStrict <$> liftIO (S.readFile $ "." </> elmConfig)
else return Nothing

let model =
Expand Down
31 changes: 24 additions & 7 deletions backend/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,37 @@ serveHtml html =
serveAssets :: Snap ()
serveAssets =
do file <- BSC.unpack . rqPathInfo <$> getRequest
case file `elem` staticAssets of
True ->
serveFile =<< liftIO (Utils.getDataFile file)
if file `elem` staticAssets
then serveFile =<< liftIO (Utils.getDataFile file)
else pass

False ->
pass

icon :: String -> FilePath
icon name = "_reactor/icons" </> name ++ "-4x.png"


staticAssets :: [FilePath]
staticAssets =
[ "favicon.ico"
, "_reactor/debug.js"
, "_reactor/wrench.png"
, "_reactor/index.js"
, icon "file"
, icon "folder"
, icon "book"
, icon "home"
, icon "browser"
, icon "aperture"
, icon "code"
, icon "cog"
, icon "wrench"
, icon "document"
, icon "spreadsheet"
, icon "key"
, icon "lock-locked"
, icon "audio"
, icon "list"
, icon "hard-drive"
, icon "terminal"
, "_reactor/debugger/pause-button-up.png"
, "_reactor/debugger/pause-button-down.png"
, "_reactor/debugger/pause-button-hover.png"
Expand All @@ -161,4 +179,3 @@ staticAssets =
, "_reactor/debugger/restart-button-down.png"
, "_reactor/debugger/restart-button-hover.png"
]

2 changes: 1 addition & 1 deletion elm-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"evancz/elm-markdown": "1.1.4 <= v < 2.0.0"
},
"elm-version": "0.15.0 <= v < 0.16.0"
}
}
19 changes: 18 additions & 1 deletion elm-reactor.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,24 @@ Data-dir:
Data-files:
favicon.ico
_reactor/debug.js
_reactor/wrench.png
_reactor/index.js
_reactor/icons/file-4x.png
_reactor/icons/folder-4x.png
_reactor/icons/book-4x.png
_reactor/icons/home-4x.png
_reactor/icons/browser-4x.png
_reactor/icons/aperture-4x.png
_reactor/icons/code-4x.png
_reactor/icons/cog-4x.png
_reactor/icons/wrench-4x.png
_reactor/icons/document-4x.png
_reactor/icons/spreadsheet-4x.png
_reactor/icons/key-4x.png
_reactor/icons/lock-locked-4x.png
_reactor/icons/audio-4x.png
_reactor/icons/list-4x.png
_reactor/icons/hard-drive-4x.png
_reactor/icons/terminal-4x.png
_reactor/debugger/pause-button-up.png
_reactor/debugger/pause-button-down.png
_reactor/debugger/pause-button-hover.png
Expand Down
10 changes: 8 additions & 2 deletions frontend/Index.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import Signal exposing (Signal, Address)
import String
import Util exposing (..)
import Dict exposing (fromList)
import Maybe.Extra exposing (or)


-- CONSTANTS

(=>) = (,)

iconPath = "open-iconic/png"
iconPath = "/_reactor/icons"
separatorStyle = style [ "display" => "inline-block", "margin" => "0 5px" ]
guiDependencySeparator = span [ separatorStyle ] [ text "/" ]
guiPathSeparator = span [ separatorStyle ] [ text "/" ]
Expand Down Expand Up @@ -130,6 +129,13 @@ clearfix =
-- UTILITY FUNCTIONS


or : Maybe a -> Maybe a -> Maybe a
or ma mb =
case ma of
Nothing -> mb
_ -> ma


packageUrl : Dependency -> String
packageUrl {account, name, version} =
"http://package.elm-lang.org/packages"
Expand Down
45 changes: 45 additions & 0 deletions frontend/Util.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module Util where


import String


isSuffixOf = String.endsWith


(</>) : String -> String -> String
a </> b =
if "/" `isSuffixOf` a
then a ++ b
else a ++ "/" ++ b


splitPath = String.split "/"


find : a -> List (a, b) -> Maybe b
find elem l =
case l of
[] -> Nothing
(elem2, val)::tail ->
if elem2 == elem
then Just val
else find elem tail


takeExtension : String -> String
takeExtension str =
let
loop l =
case l of
[] -> ""
[a] -> a
(_::t) -> loop t
in
case String.split "." str of
[] -> ""
(_::t) -> loop t


(><) : List a -> List b -> List (a,b)
(><) = List.map2 (,)

0 comments on commit dc7c268

Please sign in to comment.