Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
delbetu committed May 4, 2024
1 parent d352a7d commit 34ce4fe
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Website

https://delbetu.github.io/prawn_box/

# Getting started

To run the application locally, you should:
Expand All @@ -7,3 +11,35 @@ To run the application locally, you should:
* `bundle exec rake build_site` to build the site inti `./dist`
* `ruby -run -e httpd './dist' -p 8000` serve the site from dist.
* Open a browser at `localhost:8000`.


# Contributing

The system is composed of:

app.wasm ==> ruby interpreter + gems installed into a virtual file system and compiled to wasm
Gemfile ==> Hold dependencies (prawn, prawn-table) to be included in app.wasm
Rakefile ==> app.wasm task holds the building process for app.wasm
index.html ==> UI (creates a webassembly module for app.wasm using ruby-wasm-wasi npm package from ruby.wasm)

## How pdf generation works
The main view needs to eval ruby code using the prawn library.

```ruby
require "rubygems"
$:.unshift("/lib") # virtual file system has this folder with prawn and prawn-table
require "prawn"
require "prawn/table"

pdf = Prawn::Document.new
pdf.instance_eval do
text "Hello World!"
end
pdf.render
```

For that, it reads the html input (user ruby code) and calls RubyVm.eval(...).
The RubyVm actually is a prepared environment containing.
The interpreter `ruby.wasm` and other gems (`prawn` and `prawn-table`).
This ruby.wasm executes the ruby code and returns a binary string (the pdf)
index.html receives that string and puts it that into the `<embed>` tag.

0 comments on commit 34ce4fe

Please sign in to comment.