ruwi 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. checksums.yaml +7 -0
  2. data/.cursor/rules/ruby_comments.mdc +29 -0
  3. data/.github/workflows/playwright.yml +74 -0
  4. data/.github/workflows/rspec.yml +31 -0
  5. data/.node-version +1 -0
  6. data/CODE_OF_CONDUCT.md +132 -0
  7. data/LICENSE.txt +21 -0
  8. data/Makefile +56 -0
  9. data/README.md +237 -0
  10. data/Rakefile +4 -0
  11. data/docs/conditional-rendering.md +119 -0
  12. data/docs/lifecycle-hooks.md +75 -0
  13. data/docs/list-rendering.md +51 -0
  14. data/examples/.gitignore +4 -0
  15. data/examples/Gemfile +5 -0
  16. data/examples/Gemfile.lock +39 -0
  17. data/examples/Makefile +15 -0
  18. data/examples/npm-packages/runtime/counter/index.html +28 -0
  19. data/examples/npm-packages/runtime/counter/index.rb +62 -0
  20. data/examples/npm-packages/runtime/counter/index.spec.js +42 -0
  21. data/examples/npm-packages/runtime/hello/index.html +28 -0
  22. data/examples/npm-packages/runtime/hello/index.rb +29 -0
  23. data/examples/npm-packages/runtime/hello/index.spec.js +53 -0
  24. data/examples/npm-packages/runtime/input/index.html +28 -0
  25. data/examples/npm-packages/runtime/input/index.rb +46 -0
  26. data/examples/npm-packages/runtime/input/index.spec.js +58 -0
  27. data/examples/npm-packages/runtime/list/index.html +27 -0
  28. data/examples/npm-packages/runtime/list/index.rb +33 -0
  29. data/examples/npm-packages/runtime/list/index.spec.js +46 -0
  30. data/examples/npm-packages/runtime/on_mounted_demo/index.html +40 -0
  31. data/examples/npm-packages/runtime/on_mounted_demo/index.rb +59 -0
  32. data/examples/npm-packages/runtime/on_mounted_demo/index.spec.js +50 -0
  33. data/examples/npm-packages/runtime/r_if_attribute_demo/index.html +34 -0
  34. data/examples/npm-packages/runtime/r_if_attribute_demo/index.rb +113 -0
  35. data/examples/npm-packages/runtime/r_if_attribute_demo/index.spec.js +140 -0
  36. data/examples/npm-packages/runtime/random_cocktail/index.html +27 -0
  37. data/examples/npm-packages/runtime/random_cocktail/index.rb +69 -0
  38. data/examples/npm-packages/runtime/random_cocktail/index.spec.js +101 -0
  39. data/examples/npm-packages/runtime/search_field/index.html +27 -0
  40. data/examples/npm-packages/runtime/search_field/index.rb +39 -0
  41. data/examples/npm-packages/runtime/search_field/index.spec.js +59 -0
  42. data/examples/npm-packages/runtime/todos/index.html +28 -0
  43. data/examples/npm-packages/runtime/todos/index.rb +239 -0
  44. data/examples/npm-packages/runtime/todos/index.spec.js +161 -0
  45. data/examples/npm-packages/runtime/todos/todos_repository.rb +23 -0
  46. data/examples/package.json +12 -0
  47. data/examples/src/counter/index.html +23 -0
  48. data/examples/src/counter/index.rb +60 -0
  49. data/examples/src/index.html +21 -0
  50. data/examples/src/index.rb +26 -0
  51. data/examples/src/todos/index.html +23 -0
  52. data/examples/src/todos/index.rb +237 -0
  53. data/examples/src/todos/todos_repository.rb +23 -0
  54. data/exe/ruwi +6 -0
  55. data/lib/ruwi/cli/command/base.rb +192 -0
  56. data/lib/ruwi/cli/command/dev.rb +207 -0
  57. data/lib/ruwi/cli/command/pack.rb +36 -0
  58. data/lib/ruwi/cli/command/rebuild.rb +38 -0
  59. data/lib/ruwi/cli/command/setup.rb +159 -0
  60. data/lib/ruwi/cli/command.rb +48 -0
  61. data/lib/ruwi/runtime/app.rb +53 -0
  62. data/lib/ruwi/runtime/component.rb +215 -0
  63. data/lib/ruwi/runtime/dispatcher.rb +46 -0
  64. data/lib/ruwi/runtime/dom/attributes.rb +105 -0
  65. data/lib/ruwi/runtime/dom/destroy_dom.rb +63 -0
  66. data/lib/ruwi/runtime/dom/events.rb +40 -0
  67. data/lib/ruwi/runtime/dom/mount_dom.rb +108 -0
  68. data/lib/ruwi/runtime/dom/patch_dom.rb +237 -0
  69. data/lib/ruwi/runtime/dom/scheduler.rb +51 -0
  70. data/lib/ruwi/runtime/dom.rb +13 -0
  71. data/lib/ruwi/runtime/nodes_equal.rb +45 -0
  72. data/lib/ruwi/runtime/template/build_conditional_group.rb +150 -0
  73. data/lib/ruwi/runtime/template/build_for_group.rb +125 -0
  74. data/lib/ruwi/runtime/template/build_vdom.rb +220 -0
  75. data/lib/ruwi/runtime/template/parser.rb +134 -0
  76. data/lib/ruwi/runtime/template.rb +11 -0
  77. data/lib/ruwi/runtime/utils/arrays.rb +185 -0
  78. data/lib/ruwi/runtime/utils/objects.rb +37 -0
  79. data/lib/ruwi/runtime/utils/props.rb +25 -0
  80. data/lib/ruwi/runtime/utils/strings.rb +19 -0
  81. data/lib/ruwi/runtime/utils.rb +11 -0
  82. data/lib/ruwi/runtime/vdom.rb +84 -0
  83. data/lib/ruwi/version.rb +5 -0
  84. data/lib/ruwi.rb +14 -0
  85. data/package-lock.json +73 -0
  86. data/package.json +32 -0
  87. data/packages/npm-packages/runtime/README.md +5 -0
  88. data/packages/npm-packages/runtime/eslint.config.mjs +16 -0
  89. data/packages/npm-packages/runtime/package-lock.json +6668 -0
  90. data/packages/npm-packages/runtime/package.json +38 -0
  91. data/packages/npm-packages/runtime/rollup.config.mjs +147 -0
  92. data/packages/npm-packages/runtime/src/__tests__/sample.test.js +5 -0
  93. data/packages/npm-packages/runtime/src/index.js +37 -0
  94. data/packages/npm-packages/runtime/src/ruwi +1 -0
  95. data/packages/npm-packages/runtime/src/ruwi.rb +1 -0
  96. data/packages/npm-packages/runtime/vitest.config.js +8 -0
  97. data/playwright.config.js +78 -0
  98. data/sig/ruwi.rbs +4 -0
  99. data/spec/ruwi/cli/command/base_spec.rb +503 -0
  100. data/spec/ruwi/cli/command/dev_spec.rb +442 -0
  101. data/spec/ruwi/cli/command/pack_spec.rb +131 -0
  102. data/spec/ruwi/cli/command/rebuild_spec.rb +95 -0
  103. data/spec/ruwi/cli/command/setup_spec.rb +251 -0
  104. data/spec/ruwi/cli/command_spec.rb +118 -0
  105. data/spec/ruwi/runtime/component_spec.rb +416 -0
  106. data/spec/ruwi/runtime/dom/scheduler_spec.rb +98 -0
  107. data/spec/ruwi/runtime/nodes_equal_spec.rb +190 -0
  108. data/spec/ruwi/runtime/template/build_conditional_group_spec.rb +505 -0
  109. data/spec/ruwi/runtime/template/build_for_group_spec.rb +377 -0
  110. data/spec/ruwi/runtime/template/build_vdom_spec.rb +573 -0
  111. data/spec/ruwi/runtime/template/parser_spec.rb +627 -0
  112. data/spec/ruwi/runtime/utils/arrays_spec.rb +228 -0
  113. data/spec/ruwi/runtime/utils/objects_spec.rb +127 -0
  114. data/spec/ruwi/runtime/utils/props_spec.rb +205 -0
  115. data/spec/ruwi/runtime/utils/strings_spec.rb +107 -0
  116. data/spec/spec_helper.rb +16 -0
  117. metadata +229 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 23dcf163b84bd3dcfc1813eda7b733fab7329a6cced1032d4bc7b4c39b9c0502
4
+ data.tar.gz: 78bf95d820ffb8191296b2aa509fafb0aeb9a63249b08b0dcb601bb66c630603
5
+ SHA512:
6
+ metadata.gz: b4659b38b22738c6ce148e6608896a52484c506780969024d89d809731fccca1853b6f6c85679cbe23a5e5e45402240fa416a82f0b5589fc3a3a8d610bfbc2d9
7
+ data.tar.gz: 6675d612861f03b2ddeb73da56c2fa99c21e6af1e4ecfbd5089b89b6237bfb7c3338e946e28c38e1c52310ce3c0ccbd3be8df72cc41137e3b5c05c000d18a987
@@ -0,0 +1,29 @@
1
+ When writing or modifying Ruby code:
2
+
3
+ 1. Comments and Documentation
4
+ - All comments MUST be written in English
5
+ - Use YARD documentation style for methods and classes
6
+ - Include @param and @return tags for method documentation
7
+ - Keep comments clear and concise
8
+
9
+ 2. Documentation Examples:
10
+
11
+ Good:
12
+ ```ruby
13
+ # Create a new component instance
14
+ # @param props [Hash] Component properties
15
+ def initialize(props = {})
16
+ # Initialize component state
17
+ @state = {}
18
+ end
19
+ ```
20
+
21
+ 3. Documentation Requirements:
22
+ - Document all public methods
23
+ - Include type information for parameters and return values
24
+ - Use descriptive English names for methods and variables
25
+ - Add context when the code's purpose isn't immediately clear
26
+ description:
27
+ globs:
28
+ alwaysApply: false
29
+ ---
@@ -0,0 +1,74 @@
1
+ name: Playwright Tests
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+
9
+ jobs:
10
+ test:
11
+ timeout-minutes: 60
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - name: Setup Node.js
18
+ uses: actions/setup-node@v4
19
+ with:
20
+ node-version: "24.x"
21
+ cache: "npm"
22
+
23
+ - name: Install dependencies
24
+ run: npm ci
25
+
26
+ - name: Get installed Playwright version
27
+ id: playwright-version
28
+ run: echo "PLAYWRIGHT_VERSION=$(node -e "console.log(require('./node_modules/@playwright/test/package.json').version)")" >> $GITHUB_ENV
29
+
30
+ - name: Cache Playwright browsers
31
+ uses: actions/cache@v4
32
+ id: playwright-cache
33
+ with:
34
+ path: ~/.cache/ms-playwright
35
+ key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }}-${{ runner.os }}
36
+
37
+ - name: Install Playwright Browsers (Chromium only)
38
+ if: steps.playwright-cache.outputs.cache-hit != 'true'
39
+ run: npx playwright install chromium --with-deps
40
+
41
+ - name: Cache runtime node_modules
42
+ uses: actions/cache@v4
43
+ with:
44
+ path: packages/npm-packages/runtime/node_modules
45
+ key: runtime-node-modules-${{ hashFiles('packages/npm-packages/runtime/package-lock.json') }}
46
+
47
+ - name: Install runtime dependencies
48
+ run: |
49
+ cd packages/npm-packages/runtime
50
+ npm ci
51
+
52
+ - name: Build runtime package
53
+ run: |
54
+ cd packages/npm-packages/runtime
55
+ npm run build:dev
56
+
57
+ - name: Run Playwright tests
58
+ run: npm run test
59
+
60
+ - name: Upload Playwright Report
61
+ uses: actions/upload-artifact@v4
62
+ if: always()
63
+ with:
64
+ name: playwright-report
65
+ path: playwright-report/
66
+ retention-days: 30
67
+
68
+ - name: Upload test results
69
+ uses: actions/upload-artifact@v4
70
+ if: always() && hashFiles('test-results/**/*') != ''
71
+ with:
72
+ name: test-results
73
+ path: test-results/
74
+ retention-days: 30
@@ -0,0 +1,31 @@
1
+ name: RSpec
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version: ["3.4.0"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby-version }}
23
+ bundler-cache: true
24
+
25
+ - name: Install dependencies
26
+ run: |
27
+ bundle install
28
+
29
+ - name: Run RSpec
30
+ run: |
31
+ bundle exec rspec
data/.node-version ADDED
@@ -0,0 +1 @@
1
+ 23.11.0
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 t0yohei
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,56 @@
1
+ .PHONY: bump help
2
+
3
+ help:
4
+ @echo "Usage: make bump <version>"
5
+ @echo " make bump VERSION=<version>"
6
+ @echo "Example: make bump 0.9.0"
7
+ @echo ""
8
+ @echo "This command updates the version number in the following files:"
9
+ @echo " - lib/ruwi/version.rb"
10
+ @echo " - package.json"
11
+ @echo " - packages/npm-packages/runtime/package.json"
12
+ @echo " - README.md"
13
+ @echo " - package-lock.json (via npm install)"
14
+ @echo " - packages/npm-packages/runtime/package-lock.json (via npm install)"
15
+
16
+ # Get version from position argument (if VERSION is not already set)
17
+ VERSION_ARG := $(word 2,$(MAKECMDGOALS))
18
+ ifndef VERSION
19
+ ifneq ($(VERSION_ARG),)
20
+ VERSION := $(VERSION_ARG)
21
+ endif
22
+ endif
23
+
24
+ bump:
25
+ @if [ -z "$(VERSION)" ]; then \
26
+ echo "Error: VERSION is required. Usage: make bump 0.9.0"; \
27
+ exit 1; \
28
+ fi
29
+ @echo "Bumping version to $(VERSION)..."
30
+ @# Update lib/ruwi/version.rb
31
+ @sed -i '' 's/VERSION = ".*"/VERSION = "$(VERSION)"/' lib/ruwi/version.rb
32
+ @echo "✓ Updated lib/ruwi/version.rb"
33
+ @# Update Gemfile.lock
34
+ @bundle install
35
+ @echo "✓ Updated Gemfile.lock"
36
+ @# Update root package.json
37
+ @sed -i '' 's/"version": ".*"/"version": "$(VERSION)"/' package.json
38
+ @echo "✓ Updated package.json"
39
+ @# Update packages/npm-packages/runtime/package.json
40
+ @sed -i '' 's/"version": ".*"/"version": "$(VERSION)"/' packages/npm-packages/runtime/package.json
41
+ @echo "✓ Updated packages/npm-packages/runtime/package.json"
42
+ @# Update README.md (unpkg.com URL)
43
+ @sed -i '' 's|unpkg.com/ruwi@[0-9.]*|unpkg.com/ruwi@$(VERSION)|' README.md
44
+ @echo "✓ Updated README.md"
45
+ @echo ""
46
+ @echo "Updating package-lock.json files..."
47
+ @npm install --package-lock-only
48
+ @echo "✓ Updated root package-lock.json"
49
+ @cd packages/npm-packages/runtime && npm install --package-lock-only && cd ../../..
50
+ @echo "✓ Updated packages/npm-packages/runtime/package-lock.json"
51
+ @echo ""
52
+ @echo "Version bumped to $(VERSION) successfully!"
53
+
54
+ # Prevent make from treating the version argument as a target
55
+ %:
56
+ @:
data/README.md ADDED
@@ -0,0 +1,237 @@
1
+ # Ruwi(Ruby Wasm Ui)
2
+
3
+ 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.
4
+
5
+ **⚠️ Warning: This library is currently under development and subject to frequent breaking changes. Please use with caution and expect API changes in future versions.**
6
+
7
+ ## Features
8
+
9
+ - **Reactive State Management**: Simple, predictable state updates with actions
10
+ - **Virtual DOM**: Efficient DOM updates using a virtual DOM implementation
11
+ - **Event Handling**: Intuitive event system with Ruby lambdas
12
+ - **Component Architecture**: Build reusable components with clean separation of concerns
13
+ - **Lifecycle Hooks**: Manage component lifecycle with hooks like `on_mounted`
14
+ - **Ruby Syntax**: Write frontend applications using Ruby instead of JavaScript
15
+
16
+ ## Quick Start
17
+
18
+ Create an HTML file:
19
+
20
+ ```html
21
+ <!DOCTYPE html>
22
+ <html>
23
+ <head>
24
+ <script src="https://unpkg.com/ruwi@0.10.0"></script>
25
+ <script defer type="text/ruby" src="app.rb"></script>
26
+ </head>
27
+ <body>
28
+ <div id="app"></div>
29
+ </body>
30
+ </html>
31
+ ```
32
+
33
+ Create `app.rb`:
34
+
35
+ ```ruby
36
+ require "js"
37
+
38
+ # Define a Counter component
39
+ CounterComponent = Ruwi.define_component(
40
+ # Initialize component state
41
+ state: ->(props) {
42
+ { count: props[:count] || 0 }
43
+ },
44
+
45
+ # Render the counter component
46
+ template: ->() {
47
+ Ruwi::Template::Parser.parse_and_eval(<<~HTML, binding)
48
+ <div>
49
+ <div>{state[:count]}</div>
50
+ <!-- Both ButtonComponent and button-component are valid -->
51
+ <ButtonComponent
52
+ label="Increment"
53
+ on="{ click_button: -> { increment } }">
54
+ </ButtonComponent>
55
+ <button-component
56
+ label="Decrement"
57
+ on="{ click_button: -> { decrement } }"
58
+ />
59
+ </div>
60
+ HTML
61
+ },
62
+
63
+ # Component methods
64
+ methods: {
65
+ increment: ->() {
66
+ update_state(count: state[:count] + 1)
67
+ },
68
+ decrement: ->() {
69
+ update_state(count: state[:count] - 1)
70
+ }
71
+ }
72
+ )
73
+
74
+ # Button component - reusable button with click handler
75
+ ButtonComponent = Ruwi.define_component(
76
+ template: ->() {
77
+ Ruwi::Template::Parser.parse_and_eval(<<~HTML, binding)
78
+ <button on="{ click: ->() { emit('click_button') } }">
79
+ {props[:label]}
80
+ </button>
81
+ HTML
82
+ }
83
+ )
84
+
85
+ # Create and mount the app
86
+ app = Ruwi::App.create(CounterComponent, count: 5)
87
+ app_element = JS.global[:document].getElementById("app")
88
+ app.mount(app_element)
89
+ ```
90
+
91
+ ## Using as a Gem
92
+
93
+ You can also use `ruwi` as a Ruby gem with `rbwasm` to build your application as a WASM file.
94
+
95
+ ### Setup
96
+
97
+ 1. Add `ruwi` to your `Gemfile`:
98
+
99
+ ```ruby
100
+ # frozen_string_literal: true
101
+
102
+ source "https://rubygems.org"
103
+
104
+ gem "ruwi"
105
+ ```
106
+
107
+ 2. Install dependencies:
108
+
109
+ ```bash
110
+ bundle install
111
+ ```
112
+
113
+ ### Building Your Application
114
+
115
+ Set up your project (first time only):
116
+
117
+ ```bash
118
+ bundle exec ruwi setup
119
+ ```
120
+
121
+ This command will:
122
+ - Configure excluded gems for WASM build
123
+ - Build Ruby WASM file
124
+ - Update `.gitignore`
125
+ - Create initial `src/index.html` and `src/index.rb` files
126
+
127
+ The setup command will configure your project structure as follows:
128
+
129
+ ```
130
+ my-app/
131
+ ├── Gemfile
132
+ └── src/
133
+ ├── index.rb
134
+ └── index.html
135
+ ```
136
+
137
+
138
+ ### Develop Your Application
139
+
140
+ - **Development server**: Start a development server with file watching and auto-build:
141
+ ```bash
142
+ bundle exec ruwi dev
143
+ ```
144
+
145
+ Create an HTML file in the `src` directory that loads the WASM file:
146
+
147
+ ```html
148
+ <!DOCTYPE html>
149
+ <html lang="en">
150
+ <head>
151
+ <meta charset="UTF-8" />
152
+ <title>My App</title>
153
+ <script type="module">
154
+ import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.7.2/dist/browser/+esm";
155
+ const response = await fetch("../src.wasm");
156
+ const module = await WebAssembly.compileStreaming(response);
157
+ const { vm } = await DefaultRubyVM(module);
158
+ vm.evalAsync(`
159
+ require "ruwi"
160
+ require_relative './src/index.rb'
161
+ `);
162
+ </script>
163
+ </head>
164
+ <body>
165
+ <div id="app"></div>
166
+ </body>
167
+ </html>
168
+ ```
169
+
170
+ Your `src/index.rb` file can use `ruwi` just like in the Quick Start example:
171
+
172
+ ```ruby
173
+ CounterComponent = Ruwi.define_component(
174
+ state: ->(props) {
175
+ { count: props[:count] || 0 }
176
+ },
177
+ template: ->() {
178
+ Ruwi::Template::Parser.parse_and_eval(<<~HTML, binding)
179
+ <div>
180
+ <div>{state[:count]}</div>
181
+ <button on="{ click: -> { increment } }">Increment</button>
182
+ </div>
183
+ HTML
184
+ },
185
+ methods: {
186
+ increment: ->() {
187
+ update_state(count: state[:count] + 1)
188
+ }
189
+ }
190
+ )
191
+
192
+ app = Ruwi::App.create(CounterComponent, count: 0)
193
+ app_element = JS.global[:document].getElementById("app")
194
+ app.mount(app_element)
195
+ ```
196
+
197
+ See the [examples](examples) directory for a complete working example.
198
+
199
+
200
+ **Additional Commands:**
201
+
202
+ - **Rebuild Ruby WASM**: Rebuild the Ruby WASM file when you add new gems:
203
+ ```bash
204
+ bundle exec ruwi rebuild
205
+ ```
206
+
207
+ ### Deployment
208
+
209
+ Pack your application files for deployment:
210
+
211
+ ```bash
212
+ bundle exec ruwi pack
213
+ ```
214
+
215
+ This command packs your Ruby files from the `./src` directory into the WASM file and outputs to the `dist` directory for deployment.
216
+
217
+ ## Documentation
218
+
219
+ - [Conditional Rendering with r-if](docs/conditional-rendering.md)
220
+ - [List Rendering with r-for](docs/list-rendering.md)
221
+ - [Lifecycle Hooks](docs/lifecycle-hooks.md)
222
+
223
+ ## Development
224
+
225
+ This project is currently under active development. To run the examples locally:
226
+
227
+ ```bash
228
+ # Run production examples
229
+ npm run serve:examples
230
+
231
+ # Run development examples
232
+ npm run serve:examples:dev
233
+ ```
234
+
235
+ ## License
236
+
237
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]