Skip to content

Commit ad21252

Browse files
committed
Update flask example
1 parent f1261ab commit ad21252

File tree

10 files changed

+34
-24
lines changed

10 files changed

+34
-24
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@ as Flask, MicroBit and many more
1212

1313
## Installation
1414

15+
Prerequisite to compile F# to Python using Fable:
16+
17+
```sh
18+
> dotnet tool install --global fable-py --version 4.0.0-alpha-004
19+
> dotnet add package Fable.Core.Experimental --version 4.0.0-alpha-005
20+
```
21+
22+
To use the `Fable.Python` library:
23+
1524
```sh
16-
dotnet package add Fable.Python
25+
> dotnet package add Fable.Python
1726
```
1827

1928
## Usage

examples/flask/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
dotnet fable-py -c Release src
2+
dotnet fable-py src/Flask.fsproj

examples/flask/src/App.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let htmlPage page =
1010
page |> Render.htmlDocument
1111

1212

13-
let site : Site = {
13+
let model : Model = {
1414
Title="Fable Python |> F# ♥️ Python"
1515
Description="Demo Website, Fable Python running on Flask!"
1616
Banner="https://unsplash.it/1200/900?random"
@@ -24,19 +24,19 @@ let subTitle (str: string) = Html.p [ prop.classes [ Bulma.Subtitle ]; prop.text
2424

2525
let helloWorld () =
2626
let body = Html.div [
27-
title site.Title
28-
subTitle site.Description
27+
title model.Title
28+
subTitle model.Description
2929
]
3030

3131
Html.html [
32-
Head.head site
32+
Head.head model
3333

34-
Navbar.navbar site
35-
Hero.hero site body
34+
Navbar.navbar model
35+
Hero.hero model body
3636
]
3737
|> htmlPage
3838

39-
// Setup the routes. TODO: See if we can use attributes instead
39+
// Setup the routes. See if we can use attributes instead
4040
app.route("/")(helloWorld) |> ignore
4141

4242
[<EntryPoint>]

examples/flask/src/Head.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ namespace Flask
33
open Feliz.ViewEngine
44

55
module Head =
6-
let head (site: Site) =
6+
let head (model: Model) =
77
Html.head [
8-
Html.title [ prop.text site.Title ]
8+
Html.title [ prop.text model.Title ]
99

1010
Html.meta [ prop.charset.utf8 ]
11-
Html.meta [ prop.name "author"; prop.content site.Author ]
12-
Html.meta [ prop.name "description"; prop.content site.Description ]
11+
Html.meta [ prop.name "author"; prop.content model.Author ]
12+
Html.meta [ prop.name "description"; prop.content model.Description ]
1313

1414
Html.meta [ prop.httpEquiv.contentType; prop.content "text/html"; prop.charset.utf8 ]
1515
Html.meta [ prop.name "viewport"; prop.content "width=device-width, initial-scale=1" ]

examples/flask/src/Hero.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ module Hero =
66
let title (str: string) = Html.p [ prop.classes [ Bulma.Title ]; prop.text str ]
77
let subTitle (str: string) = Html.p [ prop.classes [ Bulma.Subtitle ]; prop.text str ]
88

9-
let hero (site: Site) body =
9+
let hero (model: Model) body =
1010
Html.section [
1111
prop.classes [ Bulma.Hero; Bulma.IsFullheightWithNavbar ]
1212
prop.style [
13-
style.backgroundImageUrl (site.Banner)
13+
style.backgroundImageUrl (model.Banner)
1414
style.backgroundPosition "center"
1515
style.backgroundSize.cover
1616
]

examples/flask/src/Model.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ open Zanaptak.TypedCssClasses
44

55
type Bulma = CssClasses<"https://cdnjs.cloudflare.com/ajax/libs/bulma/0.9.3/css/bulma.min.css", Naming.PascalCase>
66

7-
type Site = {
7+
type Model = {
88
Author: string
99
Banner: string
1010
Title: string

examples/flask/src/NavBar.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ open System
55
open Feliz.ViewEngine
66

77
module Navbar =
8-
let navbar (site: Site) =
8+
let navbar (model: Model) =
99
Html.nav [
1010
prop.classes [ Bulma.Navbar; Bulma.IsPrimary ]
1111
prop.children [
@@ -14,12 +14,12 @@ module Navbar =
1414
prop.children [
1515
Html.a [
1616
prop.classes [ Bulma.NavbarItem ]
17-
prop.href site.PermaLink
17+
prop.href model.PermaLink
1818
prop.children [
19-
Html.img [ prop.alt "Brand"; prop.src (site.Brand) ]
19+
Html.img [ prop.alt "Brand"; prop.src (model.Brand) ]
2020
Html.p [
2121
prop.classes [ Bulma.Title; Bulma.Is4 ]
22-
prop.text site.Title
22+
prop.text model.Title
2323
]
2424
]
2525
]

examples/timeflies/Program.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ open Fable.Python.Queue
99

1010
type Msg =
1111
| Place of label: Label * x: int * y: int
12-
//| Place of x: int * y: int
1312
| Empty
1413

1514
let root = Tk()
@@ -50,7 +49,7 @@ let sink (ev: Notification<Label * int * int>) =
5049
match ev with
5150
| OnNext (label, x, y) -> queue.put (Place(label, x, y))
5251
| OnError (err) -> printfn $"Stream Error: {err}"
53-
| _ -> printfn "Stream Completed"
52+
| _ -> printfn "Stream Completed!"
5453

5554
return ()
5655
}

examples/timeflies/TimeFlies.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<Compile Include="Program.fs" />
1010
</ItemGroup>
1111
<ItemGroup>
12-
<PackageReference Include="Fable.Python" Version="0.9.0" />
13-
<PackageReference Include="Fable.Core.Experimental" Version="4.0.0-alpha-003" />
12+
<PackageReference Include="Fable.Python" Version="0.12.0" />
13+
<PackageReference Include="Fable.Core.Experimental" Version="4.0.0-alpha-005" />
1414
<PackageReference Include="FSharp.Control.AsyncRx" Version="1.6.0" />
1515
</ItemGroup>
1616
</Project>

src/jupyter/IPython.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ type IDisplay =
77
abstract Code : data: string -> unit
88
[<Emit("display.Code($1, language=$2)")>]
99
abstract Code : data: string * language: string -> unit
10+
[<Emit("display.Markdown($1)")>]
11+
abstract Markdown : data: string -> unit
1012

1113
[<Import("display", "IPython")>]
1214
let display : IDisplay = nativeOnly

0 commit comments

Comments
 (0)