Skip to content

Commit

Permalink
custom examples from projects
Browse files Browse the repository at this point in the history
  • Loading branch information
joneugster committed Apr 26, 2024
1 parent bf8578e commit 28b7a2d
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 200 deletions.
5 changes: 3 additions & 2 deletions Projects/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

# But not these files...
!.gitignore
!Wededitor/
!MathlibLatest/
!lean4web-tools/
!mathlib-demo/
!README.md
5 changes: 5 additions & 0 deletions Projects/MathlibLatest/MathlibLatest.lean
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import Webeditor
import Mathlib
import ProofWidgets

import Examples.Bijection
import MathlibLatest.Logic
import MathlibLatest.Rational
import MathlibLatest.Ring
20 changes: 0 additions & 20 deletions Projects/MathlibLatest/build.sh

This file was deleted.

77 changes: 0 additions & 77 deletions Projects/MathlibLatest/lake-manifest.json

This file was deleted.

17 changes: 0 additions & 17 deletions Projects/MathlibLatest/lakefile.lean

This file was deleted.

1 change: 0 additions & 1 deletion Projects/MathlibLatest/lean-toolchain

This file was deleted.

15 changes: 15 additions & 0 deletions Projects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,18 @@ Projects can be any Lean projects.
3. For a project to appear in the settings, you need to add it to `config.json`:
add a new entry `{folder: "_", name: "_"}` to `projects`, where "folder" is the
folder name inside `Projects/` and "name" is the free-text display name.
* Optionally, you can also specify examples in the `config.json` each of these
examples will appear under "Examples" in the menu. A full project entry would then
look as follows:
```
{ "folder": "folder name inside `Projects/`",
"name": "My Custom Lean Demo",
"examples": [
{ "file": "path/inside/the/lean/package.lean",
"name": "My Cool Example"},
...
]
}
```
* Compare to the entry for the `mathlib-demo` project.
File renamed without changes.
25 changes: 0 additions & 25 deletions client/public/examples/bijection.lean

This file was deleted.

16 changes: 0 additions & 16 deletions client/public/examples/logic.lean

This file was deleted.

16 changes: 0 additions & 16 deletions client/public/examples/rational.lean

This file was deleted.

13 changes: 0 additions & 13 deletions client/public/examples/ring.lean

This file was deleted.

4 changes: 2 additions & 2 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const App: React.FC = () => {

const [content, setContent] = useState<string>('')
const [url, setUrl] = useState<string>(null)
const [project, setProject] = useState<string>('MathlibLatest')
const [project, setProject] = useState<string>('mathlib-demo')
const [contentFromUrl, setContentFromUrl] = useState<string>(null)

const readHash = () => {
Expand Down Expand Up @@ -123,7 +123,7 @@ const App: React.FC = () => {

useEffect(() => {
//let args = parseArgs()
let _project = (project == 'MathlibLatest' ? null : project)
let _project = (project == 'mathlib-demo' ? null : project)
if (content === contentFromUrl) {
let args = {project: _project, url: encodeURIComponent(url), code: null}
history.replaceState(undefined, undefined, formatArgs(args))
Expand Down
2 changes: 1 addition & 1 deletion client/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const Editor: React.FC<{setRestart?, onDidChangeContent?, value: string, theme:

const restart = async (project) => {
if (!project) {
project = 'MathlibLatest'
project = 'mathlib-demo'
}
console.log(`project got to here! ${project}`)
await infoProvider.client.restart(project);
Expand Down
10 changes: 5 additions & 5 deletions client/src/Examples.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react'
import { faStar } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import * as lean4webConfig from './config.json'

const Examples: React.FC<{loadFromUrl:(url: string, project?: string|null) => void, openSubmenu: (ev: React.MouseEvent, component: React.JSX.Element) => void, closeNav: any}> = ({loadFromUrl, openSubmenu, closeNav}) => {

Expand All @@ -10,11 +11,10 @@ const Examples: React.FC<{loadFromUrl:(url: string, project?: string|null) => vo
}

const exampleMenu = <>
<span className="nav-link" onClick={() => load("logic.lean", "MathlibLatest")}>Logic</span>
<span className="nav-link" onClick={() => load("bijection.lean", "MathlibLatest")}>Bijections</span>
<span className="nav-link" onClick={() => load("rational.lean", "MathlibLatest")}>Rational numbers</span>
<span className="nav-link" onClick={() => load("ring.lean", "MathlibLatest")}>Commutative rings</span>
<span className="nav-link" onClick={() => {loadFromUrl("https://raw.githubusercontent.com/JOSHCLUNE/DuperDemo/main/DuperDemo.lean", "DuperDemo"); closeNav()}}>Duper</span>
{lean4webConfig.projects.map(proj => proj.examples?.map(example =>
<span key={`${proj.name}-${example.name}`} className="nav-link" onClick={() => load(`${proj.folder}/${example.file}`, proj.folder)}>{example.name}</span>

))}
</>

return <span className="nav-link" onClick={(ev) => {openSubmenu(ev, exampleMenu)}}>
Expand Down
2 changes: 1 addition & 1 deletion client/src/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const Settings: React.FC<{closeNav, theme, setTheme, project, setProject}> =
console.log(`set Lean project to: ${ev.target.value}`)
}} >
{lean4webConfig.projects.map(proj =>
<option key={proj.folder} value={proj.folder}>{proj.name}</option>
<option key={proj.folder} value={proj.folder}>{proj.name ?? proj.folder}</option>
)}
</select>
</p>
Expand Down
20 changes: 18 additions & 2 deletions client/src/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
{
"projects": [
{"folder": "lean4web-tools", "name": "Stable Lean"},
{"folder": "MathlibLatest", "name": "Latest Mathlib"}
{ "folder": "lean4web-tools",
"name": "Stable Lean",
"examples": [
{"file": "Webeditor.lean", "name": "Test"}
]
},
{ "folder": "mathlib-demo",
"name": "Latest Mathlib",
"examples": [
{ "file": "MathlibLatest/Bijection.lean",
"name": "Bijection"},
{ "file": "MathlibLatest/Logic.lean",
"name": "Logic"},
{ "file": "MathlibLatest/Ring.lean",
"name": "Ring"},
{ "file": "MathlibLatest/Rational.lean",
"name": "Rational"}
]}
]
}
2 changes: 1 addition & 1 deletion client/src/editor/leanclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class LeanClient implements Disposable {
const startTime = Date.now()

if (!project) {
project = 'MathlibLatest'
project = 'mathlib-demo'
}

console.log(`[LeanClient] Restarting Lean Server with project ${project}`)
Expand Down
10 changes: 9 additions & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ const crtFile = process.env.SSL_CRT_FILE
const keyFile = process.env.SSL_KEY_FILE

const app = express()
app.use(express.static(path.join(__dirname, '../client/dist/')))
app.use('/examples/*', (req, res, next) => {
const filename = req.params[0];
console.debug(`trying to load ${filename}`)
req.url = filename;
express.static(path.join(__dirname, '..', 'Projects'))(req, res, next)
// express.static(path.join(__dirname, '..', 'Projects', filename))(req, res, next);
})
app.use(express.static(path.join(__dirname, '..', 'client', 'dist')))

app.use(nocache())

let server;
Expand Down
3 changes: 3 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export default defineConfig({
target: 'ws://localhost:8080',
ws: true
},
'/examples': {
target: 'http://localhost:8080',
},
}
},
resolve: {
Expand Down

0 comments on commit 28b7a2d

Please sign in to comment.