-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
113 changed files
with
1,520 additions
and
310 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/log/*.log | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
|
||
node_modules | ||
|
||
# rspec failure tracking | ||
.rspec_status | ||
/test/dummy/db/*.sqlite3 | ||
/test/dummy/db/*.sqlite3-* | ||
/test/dummy/log/*.log | ||
/test/dummy/storage/ | ||
/test/dummy/tmp/ | ||
Gemfile.lock | ||
.DS_Store |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | ||
|
||
# Specify your gem's dependencies in turbo-train.gemspec | ||
# Specify your gem's dependencies in turbo-train-test.gemspec. | ||
gemspec | ||
|
||
gem "rake", "~> 13.0" | ||
rails_version = ENV.fetch("RAILS_VERSION", "6.1") | ||
|
||
if rails_version == "main" | ||
rails_constraint = { github: "rails/rails" } | ||
else | ||
rails_constraint = "~> #{rails_version}.0" | ||
end | ||
|
||
group :development, :test do | ||
gem "rails", rails_constraint | ||
gem "sprockets-rails" | ||
gem 'importmap-rails' | ||
gem 'dotenv-rails' | ||
end | ||
|
||
gem "rspec", "~> 3.0" | ||
group :test do | ||
gem 'puma' | ||
gem 'capybara' | ||
gem 'rexml' | ||
gem 'selenium-webdriver' | ||
gem 'webdrivers' | ||
gem 'sqlite3' | ||
end | ||
|
||
gem "rubocop", "~> 1.21" | ||
# Start debugger with binding.b [https://github.com/ruby/debug] | ||
# gem "debug", ">= 1.0.0" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright 2022 goodsign | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,93 @@ | ||
![Build Status](https://github.com/Uscreen-video/turbo-train/actions/workflows/main.yml/badge.svg?branch=main) | ||
|
||
# Turbo::Train | ||
|
||
Broadcasting Rails Turbo actions to SSE receivers. | ||
<img align="right" width="160" title="Turbo::Train logo" | ||
src="./logo.svg"> | ||
|
||
Real-time page updates for your Rails app with [Mercure](https://mercure.rocks) and [Hotwire Turbo](https://github.com/hotwired/turbo-rails). | ||
|
||
* **Uses [SSE](https://html.spec.whatwg.org/multipage/server-sent-events.html)**. No more websockets, client libraries, JS code and handling reconnects. Just an HTTP connection. Let the [browser](https://caniuse.com/eventsource) do the work. | ||
* **Seamless Hotwire integration.** Use it exactly like [ActionCable](https://github.com/hotwired/turbo-rails#come-alive-with-turbo-streams). Drop-in replacement for `broadcast_action_to` and usual helpers. | ||
* **Simple.** Get running in minutes, scale easily in production 🚀 | ||
|
||
Uses [Mercure server](https://mercure.rocks/docs/ecosystem/hotwire) for delivering [Turbo Streams](https://turbo.hotwired.dev/handbook/streams) over SSE. | ||
|
||
## Before your proceed | ||
|
||
Using this gem requires some knowledge of ActionCable and broadcasting turbo stream. Turbo::Train is designed to mimic those, so it is highly recommended to first try the original to understand the concept. | ||
|
||
## Prerequisites | ||
|
||
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/turbo/train`. To experiment with that code, run `bin/console` for an interactive prompt. | ||
1. Rails 7+ | ||
2. Mercure server (setup instructions below) | ||
|
||
TODO: Delete this and the text above, and describe your gem | ||
This should also work for Rails 6, but you will also need to install [turbo-rails](https://github.com/hotwired/turbo-rails#installation) manually before this gem. | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
### Step 1. Mercure | ||
|
||
```ruby | ||
gem 'turbo-train' | ||
Mercure is installed as a plugin to Caddy server. For mac users everything is pretty easy: | ||
|
||
``` | ||
brew install caddy | ||
``` | ||
|
||
And then execute: | ||
``` | ||
caddy add-package github.com/dunglas/mercure/caddy | ||
``` | ||
|
||
$ bundle install | ||
Now you are ready to run 🚀 | ||
|
||
``` | ||
caddy run | ||
``` | ||
|
||
Or install it yourself as: | ||
### Step 2. Turbo::Train | ||
|
||
$ gem install turbo-train | ||
Instructions for Rails 7+ | ||
|
||
1. Add the turbo-train gem to your Gemfile: `gem 'turbo-train'` | ||
2. Run `bundle install` | ||
3. Run `rails turbo_train:install` | ||
|
||
## Usage | ||
|
||
TODO: Write usage instructions here | ||
If you are familiar with broadcasting from ActionCable, usage would be extremely familiar: | ||
|
||
## Development | ||
``` | ||
<%# app/views/chat_messages/index.html.erb %> | ||
<%= turbo_train_from "chat_messages" %> | ||
``` | ||
|
||
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. | ||
And then you can send portions of HTML from your Rails backend to deliver live to all currently open browsers: | ||
|
||
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](https://rubygems.org). | ||
``` | ||
# app/models/chat_message.rb | ||
after_create_commit { Turbo::Train.broadcast_action_to('chat_messages', action: :append, partial: "chat_message") } | ||
``` | ||
|
||
## Contributing | ||
You have the same options as original Rails Turbo helpers: rendering partials, pure html, [same actions](https://turbo.hotwired.dev/reference/streams). | ||
|
||
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/turbo-train. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/turbo-train/blob/main/CODE_OF_CONDUCT.md). | ||
## Configuration | ||
|
||
## License | ||
To specify different Mercure server settings, please adjust the generated `config/initializers/turbo_train.rb` file: | ||
|
||
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). | ||
``` | ||
Turbo::Train.configure do |config| | ||
config.mercure_domain = ... | ||
config.publisher_key = ... | ||
config.subscriber_key = ... | ||
end | ||
``` | ||
|
||
* Your SSE will connect to `https://#{configuration.mercure_domain}/.well-known`. | ||
* The publisher/subscriber key correspond to the [configuration](https://mercure.rocks/docs/hub/config) or your Mercure server. | ||
|
||
## Code of Conduct | ||
By default, these are set to `localhost`/`test`/`testing` to match the configuration of the local development server from the installation instructions above. | ||
|
||
Everyone interacting in the Turbo::Train project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/turbo-train/blob/main/CODE_OF_CONDUCT.md). | ||
*** | ||
|
||
## License | ||
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
# frozen_string_literal: true | ||
require "bundler/setup" | ||
|
||
require "bundler/gem_tasks" | ||
require "rspec/core/rake_task" | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__) | ||
load "rails/tasks/engine.rake" | ||
|
||
require "rubocop/rake_task" | ||
load "rails/tasks/statistics.rake" | ||
|
||
RuboCop::RakeTask.new | ||
|
||
task default: %i[spec rubocop] | ||
require "bundler/gem_tasks" |
Empty file.
Oops, something went wrong.