Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ main = getEnvironment >>= (hakyllWith configuration . rules)
sitePort :: Int
sitePort = 4000

supportedLanguages :: [String]
supportedLanguages = [ -- Name here the directories of the programming languages to be supported
"haskell"
, "functional-full-stack" -- Haskell backend + PureScript frontend
]

markdownPattern :: Pattern
markdownPattern = filePattern "md"

imagePattern :: Pattern
imagePattern = filePattern "png"

filePattern :: String -> Pattern
filePattern extension = foldl (.||.) (head patterns) (tail patterns)
where
patterns = fmap (\dir -> fromGlob $ "tutorials/" ++ dir ++ "/*/*." ++ extension) supportedLanguages

configuration :: Configuration
configuration =
defaultConfiguration
Expand Down Expand Up @@ -52,7 +69,7 @@ rules env = do
create ["archive.html"] $ do
route idRoute
compile $ do
tutorials <- recentFirst =<< loadAll "tutorials/haskell/*/*.md"
tutorials <- recentFirst =<< loadAll markdownPattern
let
archiveContext =
listField "tutorials" tutorialCtx (return tutorials)
Expand All @@ -68,7 +85,7 @@ rules env = do
match "tutorials/index.html" $ do
route idRoute
compile $ do
tutorials <- recentFirst =<< loadAll "tutorials/haskell/*/*.md"
tutorials <- recentFirst =<< loadAll markdownPattern
let
indexContext =
listField "tutorials" tutorialCtx (return tutorials)
Expand All @@ -87,7 +104,7 @@ rules env = do

match "templates/*" (compile templateCompiler)

match "tutorials/haskell/*/*.md" $ do
match markdownPattern $ do
let
tutorialRoute i = takeDirectory p </> "index.html"
where p = toFilePath i
Expand All @@ -99,14 +116,14 @@ rules env = do
>>= relativizeUrls
>>= cleanIndexUrls

match "tutorials/haskell/*/*.png" $ do
match imagePattern $ do
route idRoute
compile copyFileCompiler

create ["tutorials/sitemap.xml"] $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "tutorials/haskell/*/*.md"
posts <- recentFirst =<< loadAll markdownPattern
let allPosts = return posts
let sitemapCtx = listField "entries" tutorialCtx allPosts

Expand All @@ -115,7 +132,7 @@ rules env = do
>>= cleanIndexHtmls

let pumpFeedPosts =
fmap (take 10) . recentFirst =<< loadAll "tutorials/haskell/*/*.md"
fmap (take 10) . recentFirst =<< loadAll markdownPattern

create ["tutorials/atom.xml"] $ do
route idRoute
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
backend/.stack-work/
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# purescript-bridge Tutorial
This tutorial shows how to use purescript-bridge
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Author Stack Builders (c) 2017

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 Stack Builders 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Lib

main :: IO ()
main = startApp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: backend
version: 0.1.0.0
synopsis: Initial project template from stack
description: Please see README.md
homepage: https://github.com/githubuser/backend#readme
license: BSD3
license-file: LICENSE
author: Author name here
maintainer: example@example.com
copyright: 2017 Author name here
category: Web
build-type: Simple
extra-source-files: README.md
cabal-version: >=1.10

library
hs-source-dirs: src
exposed-modules: Lib
, Types
build-depends: base >= 4.7 && < 5
, aeson
, servant-server
, wai
, wai-cors
, warp
default-language: Haskell2010

executable backend-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, backend
default-language: Haskell2010

executable bridge
hs-source-dirs: bridge
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, backend
, purescript-bridge
default-language: Haskell2010

test-suite backend-test
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
build-depends: base
, backend
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010

source-repository head
type: git
location: https://github.com/githubuser/backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Main where

import Types (Scientist)
import Language.PureScript.Bridge (writePSTypes, buildBridge, defaultBridge, mkSumType)
import Data.Proxy (Proxy(..))

main :: IO ()
main = writePSTypes "../frontend/src" (buildBridge defaultBridge) myTypes
where
myTypes = [ mkSumType (Proxy :: Proxy Scientist)
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module Lib
( startApp
) where

import Data.Aeson
import Data.Aeson.TH
import Network.Wai
import Network.Wai.Handler.Warp
import Servant
import Network.Wai.Middleware.Cors
import Types (Scientist, scientists)

type API = "scientist" :> Get '[JSON] [Scientist]

startApp :: IO ()
startApp = do
putStrLn "Starting"
run 8080 app
putStrLn "Finished"

app :: Application
app = simpleCors (serve api server)

api :: Proxy API
api = Proxy

server :: Server API
server = return scientists
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveGeneric #-}
module Types where

import Data.Aeson
import Data.Aeson.TH
import GHC.Generics (Generic)

data Scientist = Scientist
{
sNames :: [String]
, sPhotoUrl :: String
} deriving (Eq, Show, Generic)

$(deriveJSON defaultOptions ''Scientist)

scientists :: [Scientist]
scientists = [ Scientist ["Isaac", "Newton"] "https://upload.wikimedia.org/wikipedia/commons/3/39/GodfreyKneller-IsaacNewton-1689.jpg"
, Scientist ["Albert", "Einstein"] "https://upload.wikimedia.org/wikipedia/commons/d/d3/Albert_Einstein_Head.jpg"
, Scientist ["Gottfried", "Wilhelm", "Leibniz"] "http://apusepress.booktype.pro/early-readings-in-the-philosophy-of-science/gottfried-wilhelm-leibniz-1646-1716/static/Leibniz.jpg"
, Scientist ["Stephen", "Hawking"] "https://upload.wikimedia.org/wikipedia/commons/e/eb/Stephen_Hawking.StarChild.jpg"
, Scientist ["Pythagoras"] "http://www.thefamouspeople.com/profiles/images/pythagoras-4.jpg"
, Scientist ["Wernher", "von", "Braun"] "https://upload.wikimedia.org/wikipedia/commons/5/56/Wernher_von_Braun_1960.jpg"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resolver: lts-7.17
packages:
- '.'
extra-deps: []
flags: {}
extra-package-dbs: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
main :: IO ()
main = putStrLn "Test suite not yet implemented"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
bower_components/
output/
dist/
static/dist
.psci_modules
npm-debug.log
**DS_Store
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2016, Alexander C. Mingoia
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 the <organization> nor the
names of its 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 <COPYRIGHT HOLDER> 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Basic Proof of Concept for purescript-bridge

This is a basic Proof-of-concept frontend for a functional fullstack app.
Based on [Pux-starter-app](https://github.com/alexmingoia/pux-starter-app).

See the [Tutorial](https://www.stackbuilders.com/tutorials/functional-full-stack/purescript-bridge/) for more context on how to use this.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "pux-starter-app",
"homepage": "https://github.com/alexmingoia/pux-starter-app",
"authors": [
"Alex Mingoia <talk@alexmingoia.com>"
],
"description": "Starter Pux application using webpack with hot-reloading.",
"main": "support/index.js",
"license": "BSD3",
"dependencies": {
"purescript-pux": "^7.0.0",
"purescript-pux-devtool": "^4.1.0",
"purescript-affjax": "^3.0.2",
"purescript-argonaut-codecs": "^2.1.0",
"purescript-argonaut-generic-codecs": "5.2.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "pux-starter-app",
"version": "9.0.0",
"description": "Starter Pux application using webpack with hot-reloading.",
"main": "support/index.js",
"keywords": [
"pux",
"purescript-pux",
"boilerplate",
"starter-app"
],
"scripts": {
"postinstall": "bower cache clean && bower install",
"clean": "rimraf static/dist && rimraf dist && rimraf output",
"build": "npm run clean && webpack --config ./webpack.production.config.js --progress --profile --colors",
"watch": "npm run clean && node ./webpack.config.js",
"serve": "http-server static --cors -p 3000",
"start": "npm run watch",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git://github.com/alexmingoia/pux-starter-app.git"
},
"author": "Alexander C. Mingoia",
"license": "BSD-3-Clause",
"bugs": {
"url": "https://github.com/alexmingoia/pux-starter-app/issues"
},
"dependencies": {
"bower": "^1.7.9",
"connect-history-api-fallback": "^1.2.0",
"express": "^4.13.4",
"html-webpack-plugin": "^2.15.0",
"http-server": "^0.9.0",
"purescript": "^0.10.1",
"purescript-psa": "^0.3.9",
"purs-loader": "^2.0.0",
"react": "^15.0.0",
"react-dom": "^15.0.0",
"rimraf": "^2.5.2",
"webpack": "^2.1.0-beta.25"
},
"devDependencies": {
"source-map-loader": "^0.1.5",
"webpack-dev-middleware": "^1.8.3",
"webpack-hot-middleware": "^2.12.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module App.Counter where

import Prelude ((+), (-), const, show)
import Pux.Html (Html, div, span, button, text)
import Pux.Html.Events (onClick)

data Action = Increment | Decrement

type State = Int

init :: State
init = 0

update :: Action -> State -> State
update Increment state = state + 1
update Decrement state = state - 1

view :: State -> Html Action
view state =
div
[]
[ button [ onClick (const Increment) ] [ text "Increment" ]
, span [] [ text (show state) ]
, button [ onClick (const Decrement) ] [ text "Decrement" ]
]
Loading