30
loading...
This website collects cookies to deliver better user experience
public/index.html
:let { app, BrowserWindow } = require("electron")
function createWindow() {
let win = new BrowserWindow({height: 600, width: 800})
win.loadFile(`${__dirname}/public/index.html`)
}
app.on("ready", createWindow)
app.on("window-all-closed", () => {
app.quit()
})
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ruby Opal Application</title>
<link href="app.css" rel="stylesheet" type="text/css" />
</head>
<body>
<button>Click the button</button>
<div>Click count: <span id="count">0</span></div>
<script src="./build/app.js"></script>
</body>
</html>
./build/app.js
.mode: dark; display: center;
except with a few more words:body {
margin: 0;
background-color: #444;
color: #fff;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-size: 300%;
min-height: 100vh;
}
button {
font-size: unset;
}
Gemfile
is like package.json
- and there's Gemfile.lock
corresponding to package-lock.json
gem "opal", "~> 1.3"
app.js
. There are likely some packages for watching the source folder and doing it automatically, but I decided to do it the hard way for now.package.json
scripts
section.require "pathname"
desc "Build JavaScript files"
task "build" do
Pathname("public/build").mkpath
sh "opal src/app.rb -c >public/build/app.js"
end
native
module provides $$
which corresponds to JavaScript window
/global
except it wraps every JavaScript object in an Opal Ruby wrapper:require "native"
counter = 0
button = $$.document.querySelector("button")
count = $$.document.querySelector("#count")
button.addEventListener("click") do
counter += 1
count.innerText = counter
end