# RERB: WebAssembly Embedded Ruby
Use ERB/rhtml to build DOMs in [ruby.wasm](https://github.com/ruby/ruby.wasm).
RERB is an unopinionated tool for compiling ERB/rhtml into ruby.wasm DOM operations for building the DOM tree described in the source file. Specifically, it generates code which, when run on a Ruby VM on WASM, generate the desired DOM.
RERB is experimental and very young, so there are some usage caveats which you can read about [here](docs/capabilities.md).
## Installation
Install the gem and add to the application's Gemfile by executing:
$ bundle add RERB
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install RERB
## Usage
### For Developers
The CLI is the recommended way to use RERB in development. The simplest way to call rerb would be to just do
```bash
rerb your-file.erb
```
RERB will compile this erb file into a HTML file which internally uses ruby.wasm DOM operations to generate the DOM in the erb file. If you want to save this output to a file, you can simply use the shell `>` operator to write the output into a file.
```bash
rerb your-file.erb > your-file.html
```
`your-file.html` is a fully valid HTML file, and is ready to be rendered on the browser, assuming the erb code itself contains all the necessary logic.
There are other flags which help you customize some aesthetics of the generated code. For example,
```bash
rerb --template nil your-file.erb
```
will generate just the DOM operations without the HTML boilerplate. This would be useful if you already have a HTML file and are simply looking to extend.
### For Browsers
Running the code generated by RERB in a browser does not require RERB. It only needs `ruby.wasm` with the JS interop extension. This is easily available via CDN as shown [here](https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-head-wasm-wasi).
Alternatively, you can use one of the templates which have all of this automatically set up.
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`.
## Contributing
Reading the [capabilities (and limitations)](docs/capabilities.md) is highly recommended. The current limitations of RERB listed in the document would be a great place to start looking for places to possibly contribute.
Bug reports and pull requests are welcome on GitHub at https://github.com/forthoney/rerb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/forthoney/rerb/blob/main/CODE_OF_CONDUCT.md).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the rerb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/forthoney/rerb/blob/main/CODE_OF_CONDUCT.md).