Skip to content

Commit 1efb0fd

Browse files
Tidying up a bit (#143)
* Consolidate READMEs, remove some references to backends * Update default gist ID This one uses `gist.github.com` links for the examples so that the links work. * adjust heading levels * Update link pointing to gh-pages branch We probably won't be using this branch once we deploy the current version, and everything is in the main repo README now anyway. * Update README.md Co-Authored-By: Thomas Honeyman <[email protected]> * Update README.md Co-Authored-By: Thomas Honeyman <[email protected]> * Mention defaults with query string parameters * Reword 200 response status rationale Co-authored-by: Thomas Honeyman <[email protected]>
1 parent e772278 commit 1efb0fd

File tree

14 files changed

+65
-189
lines changed

14 files changed

+65
-189
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2013-16 PureScript
1+
Copyright (c) 2013-20 PureScript
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

README.md

+62-38
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,50 @@
1-
# PureScript API
1+
# Try PureScript
22

33
[![Build Status](https://api.travis-ci.org/purescript/trypurescript.svg?branch=master)](http://travis-ci.org/purescript/trypurescript)
44

5-
Very basic web service which wraps the PureScript compiler.
5+
[Try PureScript](https://try.purescript.org) is an online PureScript code editor for quickly experimenting with PureScript code snippets and ideas. It consists of a client and a server component, both of which live within this repository.
66

7-
[Client code](https://github.com/purescript/trypurescript/tree/gh-pages)
7+
## Features:
88

9-
## API
9+
- Writing code using the [Ace Editor](http://ace.c9.io)
10+
- Automatic compilation
11+
- PureScript syntax highlighting
12+
- Run and print output or show resulting JavaScript
13+
- Multiple view modes: code, output or both
14+
- Persistent session
15+
- Load PureScript code from Github Gists
1016

11-
### Compile PureScript code
12-
13-
**POST /compile**
14-
15-
- Request body: PureScript code
16-
- Response body: Either `{ js: "..." }` or `{ error: "..." }`
17-
- Status code: 200 (success)
17+
### Control Features via the Query String
1818

19-
The response does not use error codes, to make it easier to use the API from another domain using CORS.
19+
Most of these features can be controlled not only from the toolbar, but also using the [query parameters](https://en.wikipedia.org/wiki/Query_string):
2020

21-
The output code will contain references to preloaded modules using `require` calls. To run these files in the browser, it is necessary to either use a `require` shim (such as require1k), or replace these calls and deploy a bundle of precompiled modules (the Try PureScript client uses the second approach).
21+
- **Load From Gist**: Load PureScript code from Gist id using the `gist` parameter
22+
- Example: `gist=37c3c97f47a43f20c548` will load the code from this Gist if the file was named `Main.purs`
2223

23-
## Configuration
24+
- **View Mode**: Control the view mode using the `view` parameter
25+
- Options are: `code`, `output`, `both` (default)
26+
- Example: `view=output` will only display the output
2427

25-
The application takes the following arguments on the command line:
28+
- **Auto Compile**: Automatic compilation can be turned off using the `compile` parameter
29+
- Options are: `true` (default), `false`
30+
- Example: `compile=false` will turn auto compilation off
2631

27-
- port number
28-
- a list of input source files
32+
- **JavaScript Code Generation**: Print the resulting JavaScript code in the output window instead of the output of the program using the `js` parameter
33+
- Options are: `true`, `false` (default)
34+
- Example: `js=true` will print JavaScript code instead of the program's output
2935

30-
### Example
36+
- **Session**: Load code from a session which is stored with [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) using the `session` parameter
37+
- Usually managed by Try PureScript
38+
- Example: `session=9162f098-070f-4053-60ea-eba47021450d` (Note: will probably not work for you)
39+
- When used with the `gist` query parameter the code will be loaded from the Gist and not the session
3140

32-
dist/build/trypurescript/trypurescript 8081 'bower_components/purescript-*/src/**/*.purs'
33-
34-
# Development
41+
## Development
3542

36-
## 1. Client setup
43+
### 1. Client setup
3744

38-
```
45+
```sh
3946
git clone [email protected]:purescript/trypurescript.git
40-
cd trypurescript
41-
git co gh-pages
47+
cd trypurescript/client
4248

4349
bower install
4450
npm install
@@ -49,32 +55,50 @@ httpserver 8080 #eg with: alias httpserver='python -m SimpleHTTPServer'
4955
open http://localhost:8080
5056
```
5157

52-
## 2. Work with local compile server
58+
### 2. Local compile server setup
5359

54-
```
60+
```sh
5561
git clone [email protected]:purescript/trypurescript.git
5662
cd trypurescript
5763

5864
stack build
5965

60-
# use one of the backends
61-
cd staging/core
62-
# get the sources of the deps
66+
# Install PureScript dependencies
67+
cd staging
6368
psc-package install
6469

6570
# note: globs like **/src/** do not work
66-
stack exec trypurescript 8081 ".psc-package/psc-0.13.6/*/*/src/**/*.purs" "src/*.purs"
71+
stack exec trypurescript 8081 ".psc-package/psc-0.13.6-*/*/*/src/**/*.purs" "src/*.purs"
6772
# should output that is is compiling the sources (first time)
6873
# then: Setting phasers to stun... (port 8081) (ctrl-c to quit)
6974
```
7075

71-
## 3. Point client to local compile server
76+
## Server API
7277

73-
(instead of the ones at try.purescript.org)
74-
```
75-
# edit API.purs
78+
The server is a very basic web service which wraps the PureScript compiler, allowing clients to send PureScript code to be compiled and receiving either compiled JS or error messages in response.
7679

77-
, compile: compile "http://localhost:8081"
78-
, getBundle: getDefaultBundle "http://localhost:8081"
80+
### Compile PureScript code
7981

80-
```
82+
**POST /compile**
83+
84+
- Request body: PureScript code
85+
- Response body: Either `{ js: "..." }` or `{ error: "..." }`
86+
- Status code: 200 (success)
87+
88+
Note that if the code in the request body fails to compile, this is considered a success from the perspective of the API, so compilation failures will be returned with 2xx status codes.
89+
Among other things, this makes it easier to use the API from another domain using CORS.
90+
91+
The output code will contain references to preloaded modules using `require` calls.
92+
To run these files in the browser, it is necessary to either use a `require` shim (such as require1k), or replace these calls and deploy a bundle of precompiled modules.
93+
The Try PureScript client uses the second approach.
94+
95+
### Configuration
96+
97+
The server application takes the following arguments on the command line:
98+
99+
- port number
100+
- a list of input source files
101+
102+
#### Example
103+
104+
dist/build/trypurescript/trypurescript 8081 'bower_components/purescript-*/src/**/*.purs'

client/README.md

-62
This file was deleted.

client/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<input id="showjs" name="showjs" title="Show resulting JavaScript code instead of output" value="showjs" type="checkbox">
6464
<label id="showjs_label" for="showjs" title="Show resulting JavaScript code instead of output">Show JS</label>
6565
</li><li class="menu-item">
66-
<a id="helplink" href="https://github.com/purescript/trypurescript/tree/gh-pages/README.md" target="trypurs_readme">
66+
<a id="helplink" href="https://github.com/purescript/trypurescript/README.md" target="trypurs_readme">
6767
<label id="help" title="Learn more about Try PureScript">Help</label>
6868
</a>
6969
</li>

client/src/Try/Config.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ compileUrl :: String
77
compileUrl = "http://localhost:8081"
88

99
mainGist :: String
10-
mainGist = "e1d317102aad40207309d8873e301273"
10+
mainGist = "7ad2b2eef11ac7dcfd14aa1585dd8f69"

staging/behaviors/psc-package.json

-10
This file was deleted.

staging/behaviors/src/FRP/Try.purs

-17
This file was deleted.

staging/flare/psc-package.json

-17
This file was deleted.

staging/mathbox/psc-package.json

-8
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.

staging/thermite/psc-package.json

-10
This file was deleted.

staging/thermite/src/Thermite/Try.purs

-24
This file was deleted.

0 commit comments

Comments
 (0)