From 34ce4fea7f328b69506045b1ecbd62704f8d7003 Mon Sep 17 00:00:00 2001 From: "M. Bellucci" Date: Sat, 4 May 2024 16:28:58 -0300 Subject: [PATCH] update readme --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index 8aba545..fd7c7af 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +# Website + +https://delbetu.github.io/prawn_box/ + # Getting started To run the application locally, you should: @@ -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 `` tag.