Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

# Specify your gem's dependencies in ruby_wasm_ui.gemspec
# Specify your gem's dependencies in ruwi.gemspec
gemspec

gem "irb"
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
ruby_wasm_ui (0.9.1)
ruwi (0.9.1)
js (~> 2.7)
listen (~> 3.8)
puma (~> 6.0)
Expand Down Expand Up @@ -94,7 +94,7 @@ DEPENDENCIES
irb
rake (~> 13.0)
rspec
ruby_wasm_ui!
ruwi!

BUNDLED WITH
2.7.2
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ help:
@echo "Example: make bump 0.9.0"
@echo ""
@echo "This command updates the version number in the following files:"
@echo " - lib/ruby_wasm_ui/version.rb"
@echo " - lib/ruwi/version.rb"
@echo " - package.json"
@echo " - packages/npm-packages/runtime/package.json"
@echo " - README.md"
Expand All @@ -27,9 +27,9 @@ bump:
exit 1; \
fi
@echo "Bumping version to $(VERSION)..."
@# Update lib/ruby_wasm_ui/version.rb
@sed -i '' 's/VERSION = ".*"/VERSION = "$(VERSION)"/' lib/ruby_wasm_ui/version.rb
@echo "✓ Updated lib/ruby_wasm_ui/version.rb"
@# Update lib/ruwi/version.rb
@sed -i '' 's/VERSION = ".*"/VERSION = "$(VERSION)"/' lib/ruwi/version.rb
@echo "✓ Updated lib/ruwi/version.rb"
@# Update Gemfile.lock
@bundle install
@echo "✓ Updated Gemfile.lock"
Expand All @@ -40,7 +40,7 @@ bump:
@sed -i '' 's/"version": ".*"/"version": "$(VERSION)"/' packages/npm-packages/runtime/package.json
@echo "✓ Updated packages/npm-packages/runtime/package.json"
@# Update README.md (unpkg.com URL)
@sed -i '' 's|unpkg.com/ruby-wasm-ui@[0-9.]*|unpkg.com/ruby-wasm-ui@$(VERSION)|' README.md
@sed -i '' 's|unpkg.com/ruwi@[0-9.]*|unpkg.com/ruwi@$(VERSION)|' README.md
@echo "✓ Updated README.md"
@echo ""
@echo "Updating package-lock.json files..."
Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ruby-wasm-ui
# ruwi

A modern web frontend framework for Ruby using [ruby.wasm](https://github.com/ruby/ruby.wasm). Write reactive web applications using familiar Ruby syntax and patterns.

Expand All @@ -21,7 +21,7 @@ Create an HTML file:
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/ruby-wasm-ui@0.9.1"></script>
<script src="https://unpkg.com/ruwi@0.9.1"></script>
<script defer type="text/ruby" src="app.rb"></script>
</head>
<body>
Expand All @@ -36,15 +36,15 @@ Create `app.rb`:
require "js"

# Define a Counter component
CounterComponent = RubyWasmUi.define_component(
CounterComponent = Ruwi.define_component(
# Initialize component state
state: ->(props) {
{ count: props[:count] || 0 }
},

# Render the counter component
template: ->() {
RubyWasmUi::Template::Parser.parse_and_eval(<<~HTML, binding)
Ruwi::Template::Parser.parse_and_eval(<<~HTML, binding)
<div>
<div>{state[:count]}</div>
<!-- Both ButtonComponent and button-component are valid -->
Expand Down Expand Up @@ -72,9 +72,9 @@ CounterComponent = RubyWasmUi.define_component(
)

# Button component - reusable button with click handler
ButtonComponent = RubyWasmUi.define_component(
ButtonComponent = Ruwi.define_component(
template: ->() {
RubyWasmUi::Template::Parser.parse_and_eval(<<~HTML, binding)
Ruwi::Template::Parser.parse_and_eval(<<~HTML, binding)
<button on="{ click: ->() { emit('click_button') } }">
{props[:label]}
</button>
Expand All @@ -83,25 +83,25 @@ ButtonComponent = RubyWasmUi.define_component(
)

# Create and mount the app
app = RubyWasmUi::App.create(CounterComponent, count: 5)
app = Ruwi::App.create(CounterComponent, count: 5)
app_element = JS.global[:document].getElementById("app")
app.mount(app_element)
```

## Using as a Gem

You can also use `ruby_wasm_ui` as a Ruby gem with `rbwasm` to build your application as a WASM file.
You can also use `ruwi` as a Ruby gem with `rbwasm` to build your application as a WASM file.

### Setup

1. Add `ruby_wasm_ui` to your `Gemfile`:
1. Add `ruwi` to your `Gemfile`:

```ruby
# frozen_string_literal: true

source "https://rubygems.org"

gem "ruby_wasm_ui"
gem "ruwi"
```

2. Install dependencies:
Expand All @@ -115,7 +115,7 @@ bundle install
Set up your project (first time only):

```bash
bundle exec ruby-wasm-ui setup
bundle exec ruwi setup
```

This command will:
Expand All @@ -139,7 +139,7 @@ my-app/

- **Development server**: Start a development server with file watching and auto-build:
```bash
bundle exec ruby-wasm-ui dev
bundle exec ruwi dev
```

Create an HTML file in the `src` directory that loads the WASM file:
Expand All @@ -156,7 +156,7 @@ Create an HTML file in the `src` directory that loads the WASM file:
const module = await WebAssembly.compileStreaming(response);
const { vm } = await DefaultRubyVM(module);
vm.evalAsync(`
require "ruby_wasm_ui"
require "ruwi"
require_relative './src/index.rb'
`);
</script>
Expand All @@ -167,15 +167,15 @@ Create an HTML file in the `src` directory that loads the WASM file:
</html>
```

Your `src/index.rb` file can use `ruby_wasm_ui` just like in the Quick Start example:
Your `src/index.rb` file can use `ruwi` just like in the Quick Start example:

```ruby
CounterComponent = RubyWasmUi.define_component(
CounterComponent = Ruwi.define_component(
state: ->(props) {
{ count: props[:count] || 0 }
},
template: ->() {
RubyWasmUi::Template::Parser.parse_and_eval(<<~HTML, binding)
Ruwi::Template::Parser.parse_and_eval(<<~HTML, binding)
<div>
<div>{state[:count]}</div>
<button on="{ click: -> { increment } }">Increment</button>
Expand All @@ -189,7 +189,7 @@ CounterComponent = RubyWasmUi.define_component(
}
)

app = RubyWasmUi::App.create(CounterComponent, count: 0)
app = Ruwi::App.create(CounterComponent, count: 0)
app_element = JS.global[:document].getElementById("app")
app.mount(app_element)
```
Expand All @@ -201,15 +201,15 @@ See the [examples](examples) directory for a complete working example.

- **Rebuild Ruby WASM**: Rebuild the Ruby WASM file when you add new gems:
```bash
bundle exec ruby-wasm-ui rebuild
bundle exec ruwi rebuild
```

### Deployment

Pack your application files for deployment:

```bash
bundle exec ruby-wasm-ui pack
bundle exec ruwi pack
```

This command packs your Ruby files from the `./src` directory into the WASM file and outputs to the `dist` directory for deployment.
Expand Down
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true

require "bundler/setup"
require "ruby_wasm_ui"
require "ruwi"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
10 changes: 5 additions & 5 deletions docs/conditional-rendering.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Conditional Rendering with r-if

ruby-wasm-ui provides the `r-if` directive for conditional rendering of elements based on state or computed values:
ruwi provides the `r-if` directive for conditional rendering of elements based on state or computed values:

```ruby
# Component demonstrating r-if conditional rendering
ConditionalComponent = RubyWasmUi.define_component(
ConditionalComponent = Ruwi.define_component(
state: ->() {
{
show_message: false,
Expand All @@ -13,7 +13,7 @@ ConditionalComponent = RubyWasmUi.define_component(
},

template: ->() {
RubyWasmUi::Template::Parser.parse_and_eval(<<~HTML, binding)
Ruwi::Template::Parser.parse_and_eval(<<~HTML, binding)
<div>
<!-- Simple boolean condition -->
<div r-if="{state[:show_message]}">
Expand Down Expand Up @@ -81,7 +81,7 @@ All conditional expressions are evaluated as Ruby code within curly braces `{}`:

```ruby
# Real-world example with loading states and data
LoadingComponent = RubyWasmUi.define_component(
LoadingComponent = Ruwi.define_component(
state: ->() {
{
is_loading: false,
Expand All @@ -91,7 +91,7 @@ LoadingComponent = RubyWasmUi.define_component(
},

template: ->() {
RubyWasmUi::Template::Parser.parse_and_eval(<<~HTML, binding)
Ruwi::Template::Parser.parse_and_eval(<<~HTML, binding)
<div>
<!-- Loading state -->
<p r-if="{state[:is_loading]}">Loading...</p>
Expand Down
6 changes: 3 additions & 3 deletions docs/lifecycle-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Components support lifecycle hooks to execute code at specific points in a component's lifecycle:

```ruby
RandomCocktailComponent = RubyWasmUi.define_component(
RandomCocktailComponent = Ruwi.define_component(
state: ->() {
{
is_loading: false,
Expand Down Expand Up @@ -54,7 +54,7 @@ RandomCocktailComponent = RubyWasmUi.define_component(
</div>
HTML

RubyWasmUi::Template::Parser.parse_and_eval(template, binding)
Ruwi::Template::Parser.parse_and_eval(template, binding)
}
)
```
Expand All @@ -72,4 +72,4 @@ The `on_mounted` hook is called after the component is mounted to the DOM. This

## Asynchronous Operations

Note: Unlike JavaScript frameworks, asynchronous operations in ruby-wasm-ui are designed to use Ruby's Fiber system rather than Promises.
Note: Unlike JavaScript frameworks, asynchronous operations in ruwi are designed to use Ruby's Fiber system rather than Promises.
12 changes: 6 additions & 6 deletions docs/list-rendering.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# List Rendering with r-for

ruby-wasm-ui provides the `r-for` directive for rendering lists of items. You can use `r-for` with both components and regular HTML elements:
ruwi provides the `r-for` directive for rendering lists of items. You can use `r-for` with both components and regular HTML elements:

```ruby
# Define a reusable list item component
ListItem = RubyWasmUi.define_component(
ListItem = Ruwi.define_component(
template: ->() {
RubyWasmUi::Template::Parser.parse_and_eval(<<~HTML, binding)
Ruwi::Template::Parser.parse_and_eval(<<~HTML, binding)
<li>{props[:todo]}</li>
HTML
}
)

# Main list component demonstrating r-for usage
List = RubyWasmUi.define_component(
List = Ruwi.define_component(
template: ->() {
RubyWasmUi::Template::Parser.parse_and_eval(<<~HTML, binding)
Ruwi::Template::Parser.parse_and_eval(<<~HTML, binding)
<ul>
<!-- Using r-for with a component -->
<ListItem
Expand All @@ -33,7 +33,7 @@ List = RubyWasmUi.define_component(
)

# Create and mount the app with initial data
app = RubyWasmUi::App.create(List, { todos: ['foo', 'bar', 'baz'] })
app = Ruwi::App.create(List, { todos: ['foo', 'bar', 'baz'] })
app_element = JS.global[:document].getElementById("app")
app.mount(app_element)
```
Expand Down
2 changes: 1 addition & 1 deletion examples/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

source "https://rubygems.org"

gem "ruby_wasm_ui", path: "../../"
gem "ruwi", path: "../../"
4 changes: 2 additions & 2 deletions examples/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../..
specs:
ruby_wasm_ui (0.9.0)
ruwi (0.9.1)
js (~> 2.7)
listen (~> 3.8)
puma (~> 6.0)
Expand Down Expand Up @@ -33,7 +33,7 @@ PLATFORMS
arm64-darwin

DEPENDENCIES
ruby_wasm_ui!
ruwi!

BUNDLED WITH
2.7.2
4 changes: 2 additions & 2 deletions examples/npm-packages/runtime/counter/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
const script = document.createElement("script");
script.defer = true;
script.src = isDev
? "../../../../packages/npm-packages/runtime/dist/ruby-wasm-ui.js"
: "https://unpkg.com/ruby-wasm-ui@latest";
? "../../../../packages/npm-packages/runtime/dist/ruwi.js"
: "https://unpkg.com/ruwi@latest";
document.head.appendChild(script);
</script>
<script defer type="text/ruby" src="index.rb"></script>
Expand Down
12 changes: 6 additions & 6 deletions examples/npm-packages/runtime/counter/index.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require "js"

# Counter component using the latest component-based API with TemplateParser
CounterComponent = RubyWasmUi.define_component(
CounterComponent = Ruwi.define_component(
# Initialize component state
state: ->(props) {
{ count: props[:count] || 0 }
},

# Render the counter component
template: ->() {
RubyWasmUi::Template::Parser.parse_and_eval(<<~HTML, binding)
Ruwi::Template::Parser.parse_and_eval(<<~HTML, binding)
<div>
<div>{state[:count]}</div>
<!-- Both ButtonComponent and button-component are valid -->
Expand Down Expand Up @@ -40,9 +40,9 @@
)

# Button component - reusable button with click handler
ButtonComponent = RubyWasmUi.define_component(
ButtonComponent = Ruwi.define_component(
template: ->() {
RubyWasmUi::Template::Parser.parse_and_eval(<<~HTML, binding)
Ruwi::Template::Parser.parse_and_eval(<<~HTML, binding)
<button on="{ click: ->() { emit('click_button') } }">
{props[:label]}
</button>
Expand All @@ -51,12 +51,12 @@
)

# app_a to be destroyed
app_a = RubyWasmUi::App.create(CounterComponent, count: 0)
app_a = Ruwi::App.create(CounterComponent, count: 0)
app_element_a = JS.global[:document].getElementById("app-a")
app_a.mount(app_element_a)
app_a.unmount

# app_b to be mounted
app_b = RubyWasmUi::App.create(CounterComponent, count: 10)
app_b = Ruwi::App.create(CounterComponent, count: 10)
app_element_b = JS.global[:document].getElementById("app-b")
app_b.mount(app_element_b)
Loading
Loading