Ruby2JS began in October 2013, forked from Marcos Castoria’s original maca/Ruby2JS project. The timing was notable: JavaScript was still in its ES5 era. Classes required prototype chain manipulation. Modules didn’t exist—you used AMD, CommonJS, or globals. Destructuring? Arrow functions? Forget it. The appeal of transpiling Ruby to JavaScript was straightforward: write elegant Ruby syntax and…
At long last, Ruby2JS 5.1 is here! It comes packed with several very welcome features: A brand-new Ruby-based configuration DSL A “preset” option for sane defaults Magic comment support for sharing portable Ruby2JS code (based on the preset) In addition, the esbuild plugin has reached 1.0 status and has been re-architected to use the Ruby version of the compiler rather than the Node (aka Opal)…
Originally, CoffeeScript had a coffeescript/register module, which would automatically compile CoffeeScript files on the fly. Originally, Babel later adopted it, producing the @babel/register module, which will automatically compile .es6 , .es , .jsx , .mjs , and .js files the fly. Now, Ruby2JS has adopted the idea, and in fact uses the same hook , and makes available the @ruby2js/register module,…
As far as I know, this is a new design pattern for Stimulus. At the very least, it isn’t something I was able to readily find with Google searches. First, let’s gets some standard stuff out of the way. The Ruby2JS.com is built using the Bridgetown static site generator. Opal is used to generate the bulk of the scripts to be executed. HTTP caching ensures that these scripts are only downloaded when…
Check it out here . Because the conversion from Ruby to JavaScript is fast and runs right in your browser, this demo will update the converted output keystroke-by-keystroke as you enter your code. Find and fix your syntax errors, select the right filters and options, and ensure the JavaScript to be generated is what you intend before you commit your code. Or just use it to learn idiomatic…
While filters can do one-for-one transformations, they can also do much more. The react filter will, for example, do the following: Support multiple syntaxes for HTML, including JSX and direct calls to React.createElement . Unifying all of the mechanisms to initialize, reference, and update state with assignments and references to instance variables. Automatically bind all event handlers.…
There’s only so much you can do with a README on GitHub and then it’s time for an upgrade. 😎 So here it is! The brand new Ruby2JS documentation site. Now that we have a spiffy new home on the interwebs, we’ll be polishing up and adding additional documentation and examples, as well as posting news updates as features and improvements get added to the project. Many thanks to Sam Ruby for giving me…