reactionview README

The project's README from github.com/marcoroth/reactionview. As one markdown file: README.md.

ReActionView

ReActionView

Reactive views for the HTML+ERB you already have.

You get what a client-side framework gives you, without adopting one.

No new syntax · No client framework · No API layer · No build step

Gem Version Documentation License Issues


ReActionView makes your existing HTML+ERB templates reactive.

Rails 8.2 already renders HTML templates with Herb::Engine, which reads the HTML and the Ruby in a template together. ReActionView builds on that. A template declares state the browser owns, changes it with an HTML attribute, and has your controller answer when the server is needed. There is no second copy of the page to keep in sync.

It also brings Herb's error overlays, the dev tools and per-tag instrumentation to the page, so a mismatched tag or a <div> inside a <p> shows up in the browser with the file and the line while you work. On Rails 8.1 and earlier, it brings the engine itself.

Documentation

reactionview.dev

Installation

bundle add reactionview
bin/rails generate reactionview:install

The generator creates config/initializers/reactionview.rb and imports the client from app/javascript/application.js. On importmap-rails the gem pins the client for you. With a bundler, install the reactionview npm package as well.

ReActionView needs Ruby 3.2 or newer and Rails 7.0 or newer. Setup covers turning on reactive templates and checking that it works, and the Quick Start builds a first reactive page.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test 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. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/reactionview. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

Code of Conduct

Everyone interacting in the ReActionView project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

License

This project is available as open source under the terms of the MIT License.

reactionview (marcoroth/reactionview)

Searching Database…

这是什么?ReActionView 让你在 Rails 中已有的 HTML+ERB 模板在客户端具备响应性,而无需引入单独的 JavaScript 框架、API 层或构建步骤。状态保存在一个 HTML 属性中,由浏览器更新页面,只在真正需要时才回调服务器。
这是一种新的模板语言,还是能与我已有的 ERB 配合使用?它不是新的语法。它直接构建在你现有的 HTML+ERB 模板之上,使用的是 Herb::Engine——Rails 8.2 已经在用这个引擎把模板的 HTML 和内嵌 Ruby 一起解析。
怎么把它添加到 Rails 应用?添加这个 gem 并运行它的生成器,它会创建 config/initializers/reactionview.rb,并在 app/javascript/application.js 中引入客户端。使用 importmap-rails 时,gem 会替你锁定客户端版本;使用打包器时,你还要安装 reactionview npm 包。
我需要什么版本的 Rails 和 Ruby?你需要 Ruby 3.2+ 和 Rails 7.0+。在 Rails 8.1 及更早版本中 Herb::Engine 尚未内置,ReActionView 会自带这个引擎。
我是不是最终会有两份页面状态需要保持同步?不会——模板通过一个 HTML 属性声明由浏览器拥有和修改的状态,控制器只在真正需要服务器时才响应,因此不存在需要与服务器渲染页面协调的独立客户端状态。
开发时它提供了哪些调试帮助?它把 Herb 的错误覆盖层、开发工具和逐标签检测带到了浏览器中,因此你工作时一旦出现不匹配的标签,就会连同其确切的文件和行号一起显示出来。
在哪里能找到完整的安装和使用文档?完整文档位于 reactionview.dev,包括安装指南和构建第一个响应式页面的快速上手教程。
Herb 是什么?这个 gem 为什么依赖它?Herb(Herb::Engine)是 Rails 8.2 原生的解析引擎,能把模板的 HTML 和内嵌 Ruby 一起读取;ReActionView 的响应式特性就构建在这个引擎之上。
Creator
marcoroth
Size
0.8 MB
Stars
529
Age
1y
Commits · 90 Days