Skip to content

Commit

Permalink
Astro-expressive-code added, added console on CJ code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielaReyna committed Sep 14, 2023
1 parent 981dd92 commit 8a654d6
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 28 deletions.
2 changes: 2 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import robotsTxt from "astro-robots-txt";
import pagefind from "astro-pagefind";
import svelte from "@astrojs/svelte";
import prefetch from "@astrojs/prefetch";
import astroExpressiveCode from "astro-expressive-code";
const prod = process.env.NODE_ENV === "production";

// https://astro.build/config
export default defineConfig({
site: "https://labs.leaningtech.com",
integrations: [
astroExpressiveCode(),
mdx(),
sitemap(),
tailwind(),
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@astrojs/tailwind": "^4.0.0",
"@tailwindcss/typography": "^0.5.9",
"astro": "^2.8.5",
"astro-expressive-code": "^0.22.2",
"astro-icon": "^0.8.1",
"astro-pagefind": "^1.2.3",
"astro-robots-txt": "^0.5.0",
Expand Down
66 changes: 66 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/content/docs/cheerpj2/01-demos.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ A few selected Java Swing examples to demonstrate how complex Swing GUI apps can

## JavaFiddle

<h>

<img src="/cheerpj2/assets/demo_fiddle.png" width="400">

A playground to compile and run Java programs directly in the browser. Both console and GUI applications are supported. The standard `javac` compiler is used, since `javac` is also written in Java the whole compiler runs in the browser, together with the compiled application.
Expand Down
12 changes: 6 additions & 6 deletions src/content/docs/cheerpj2/03-getting-started/00-Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ CheerpJ is very easy to use, this tutorial will guide you step by step into comp

Visit [our download page](https://leaningtech.com/download-cheerpj/) and download the CheerpJ archive for your platform. CheerpJ is available for Linux, Mac OS X and Windows.

CheerpJ is distributed as an archive for all the platforms, you can unpack the archive anywhere in the system. During the tutorial we will assume that CheerpJ has been unpacked in the home directory and its root is `~/cheerpj_2.3/`. Please keep in mind to use a different path in the following commands if you have chosen a different position or you are using a different version of CheerpJ.
CheerpJ is distributed as an archive for all the platforms, you can unpack the archive anywhere in the system. During the tutorial we will assume that CheerpJ has been unpacked in the Applications directory `/Applications/cheerpj_2.3/`. Please keep in mind to use a different path in the following commands if you have chosen a different position or you are using a different version of CheerpJ.

## Using CheerpJ AOT compiler
## Using CheerpJ's AOT compiler

### Build or download the JAR file

Expand All @@ -20,9 +20,9 @@ CheerpJ compiles unmodified JAR files to JavaScript so that they can run in the

CheerpJ provides a convenient python program to convert whole JARs to JavaScript: `cheerpjfy.py`. It supports several options for advanced users, but it's basic syntax is very simple. The following command will generate `TextDemo.jar.js`

```
```shell
cd ~/cheerpj_tutorial/
~/cheerpj_2.3/cheerpjfy.py TextDemo.jar
/Applications/cheerpj_2.3/cheerpjfy.py TextDemo.jar
```

**NOTE**: `cheerpjfy.py` it's a python3 program, you need to have python3 installed on your system.
Expand All @@ -32,7 +32,7 @@ cd ~/cheerpj_tutorial/

Copy the following HTML code into `~/cheerpj_tutorial/cheerpj_tutorial.html`

```html
```html title="cheerpj_tutorial/cheerpj_tutorial.html"
<!doctype html>
<html lang="en">
<head>
Expand Down Expand Up @@ -80,7 +80,7 @@ To test CheerpJ you _must_ use a local Web Server. Opening the `cheerpj_tutorial

To run TextDemo.jar in the browser using CheerpJ, do the following

```
```console
cd ~/cheerpj_tutorial/
python3 -m http.server 8080
```
Expand Down
20 changes: 10 additions & 10 deletions src/content/docs/cheerpj2/03-getting-started/01-Getting-Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Getting started

This page will help you getting started with CheerpJ and converting your first Java application to JavaScript in no time.

To start, make sure to download the latest available version of CheerpJ [here](https://leaningtech.com/download-cheerpj/). Decompress the Cheerpj 2.3 archive anywhere, for example in `~/cheerpj_2.3`.
To start, make sure to download the latest available version of CheerpJ [here](https://leaningtech.com/download-cheerpj/). Decompress the Cheerpj 2.3 archive anywhere, for example in `~/cheerpj_2.3` or `/Applications/cheerpj_2.3/`.

**Important:** Converting an applet is documented at the bottom of this page.

Expand All @@ -16,8 +16,8 @@ To start, make sure to download the latest available version of CheerpJ [here](h

The basic usage is very simple:

```
~/cheerpj_2.3/cheerpjfy.py my_application_archive.jar
```shell
/Applications/cheerpj_2.3/cheerpjfy.py my_application_archive.jar
```

This command will generate a file called `my_application_archive.jar.js`, which needs to be deployed in the same folder of the original .JAR archive, and hosted on a web server. Instructions on how to serve the converted JavaScript on a web page are provided below.
Expand All @@ -26,16 +26,16 @@ This command will generate a file called `my_application_archive.jar.js`, which

**Note to Windows users:** You will need to have python3 installed on the system. Python provides a launcher called `py` that will automatically detect and use the right version of python for a given script. To use `cheerpjfy.py` on Windows you need to prefix all the commands with `py`, for example:

```
```shell
py c:\cheerpj_2.3\cheerpjfy.py application.jar
```

### Converting multiple .jar files

If your JAR has any dependencies in the form of further JAR archives, the `cheerpjfy.py` command line must be modified as follows:

```
~/cheerpj_2.3/cheerpjfy.py --deps my_dependency_archive.jar my_application_archive.jar
```shell
/Applications/cheerpj_2.3/cheerpjfy.py --deps my_dependency_archive.jar my_application_archive.jar
```

This command will generate `my_application_archive.jar.js` but **not** `my_dependency_archive.jar.js`. Each archive should be compiled separately by invoking `~/cheerpj_2.3/cheerpjfy.py my_dependency_archive.jar`.
Expand All @@ -51,7 +51,7 @@ done

## Basic HTML page for testing a Java application

```html
```html title="index.html"
<!doctype html>
<html lang="en">
<head>
Expand All @@ -75,8 +75,8 @@ This page will initialize the CheerpJ system, create a graphical environment to

You can now serve this web page on a simple http server, such as the http-server utility.

```
http-server ~/cheerpj_2.3/
```shell
http-server [path] [options]
```

## Converting an applet
Expand All @@ -98,7 +98,7 @@ To avoid potential conflicts with native Java we recommend replacing the origina

## Basic HTML page for testing a Java applet

```html
```html title="index.html"
<!doctype html>
<html lang="en">
<head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The `com.leaningtech.client.Global` is a representation of the global namespace

## Basic example

```java
```java title="DomExample.java"
import com.leaningtech.client.Document;
import com.leaningtech.client.Element;
import com.leaningtech.client.Global;
Expand Down Expand Up @@ -60,7 +60,7 @@ The various methods behave the same, with the only difference being the expected

Assuming the example above is contained in `DomExample.java`, you need to first build the program using the standard `javac` compiler, create a JAR and then create the JAR.JS from it using CheerpJ. In both steps the `cheerpj-dom.jar` must be explicitly added to the command line as a dependency.

```
```shell
# The CHEERPJ_INSTALL_PATH is assumed to be set to the location where the CheerpJ archive has been installed
javac -cp $CHEERPJ_INSTALL_PATH/cheerpj-dom.jar DomExample.java
jar cvf domexample.jar DomExample.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ With CheerpJ, it is possible to implement Java 'native' methods (that would norm

Take as an example the following Java class

```java
```java title="SomeClass.java"
public class SomeClass {
public static void someStaticMethod() {
...
Expand All @@ -32,7 +32,7 @@ Since this is a rather involved process, the `cheerpjfy.py` script provides func

Assume the previous class has been compiled and packaged in `some.jar`, to generate a directory tree for JS native code you can do:

```
```shell
mkdir native/
cheerpjfy.py --stub-natives=native/ some.jar
```
Expand All @@ -41,7 +41,7 @@ This will generate a tree of directories under the `native` folder, which will r

Once all have been implemented, native methods can be packaged with the compiled code using the following command:

```
```shell
cheerpjfy.py --natives=native/ some.jar
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Command line options

The basic usage of the `cheerpjfy.py` build script is:

```
```shell
./cheerpjfy.py application.jar
```

Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/cheerpj2/05-reference/Runtime-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CheerpJ exposes a simple API to interact with a Java application converted to Ja

A basic HTML file to load a CheerpJ application will look as follows:

```html
```html title="index.html"
<!doctype html>
<html lang="en">
<head>
Expand Down
6 changes: 3 additions & 3 deletions src/content/docs/cheerpj2/05-reference/WebWorker-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ w.cjResolveCall("ClassName", "methodName", null).then( // or array of parameter

CheerpJ exposes a custom API to access this feature directly from Java code. The API is equivalent in terms of capabilities. This API is blocking, so to actually take advantage of concurrency between the main thread and Web Workers it is necessary to use this API from a Java thread.

```java
```java title="Worker.java"
package com.leaningtech.cheerpj;

public class Worker
Expand Down Expand Up @@ -98,7 +98,7 @@ The Java version of the API is also extended to support `long`s in parameters an

Example usage:

```java
```java title="WW.java"
import com.leaningtech.cheerpj.Worker;

public class WW
Expand All @@ -113,6 +113,6 @@ public class WW

To build the class you need to add `cheerpj-public.jar` to the classpath

```
```shell
javac -cp cheerpj_install_dir/cheerpj-public.jar WW.java
```

0 comments on commit 8a654d6

Please sign in to comment.