• Stars
    star
    219
  • Rank 174,403 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 1 year ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Power-pack for Turbo Streams

TurboPower for Rails

GEM Version Gem Downloads

Getting Started

TurboPower Rails is a power-pack for Turbo Streams. This gem provides server-side Ruby helpers for the NPM package turbo_power.

Important Note

This is very much a work in progress right now. This requires the NPM package @hotwired/turbo >= 7.2.0 or @hotwired/turbo-rails >= 7.2.0 and the gem turbo-rails >= 1.3.0.

Also: I can't guarantee that the current API stays that way, there might be even more ways to improve it.

Installation

Install the gem and add to the application's Gemfile by executing:

bundle add turbo_power

Install the JavaScript package:

yarn add turbo_power

Initialize TurboPower in application.js:

// application.js
import * as Turbo from '@hotwired/turbo'

+import TurboPower from 'turbo_power'
+TurboPower.initialize(Turbo.StreamActions)

Installation on a stock Rails 7 install with importmaps

  1. ./bin/importmap pin turbo_power

  2. You'll then have to make sure the following files are modified as such:

config/importmaps.rb

pin "application", preload: true
- pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
+ pin "@hotwired/turbo", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
- pin "@hotwired/turbo", to: "https://ga.jspm.io/npm:@hotwired/[email protected]/dist/turbo.es2017-esm.js"
pin "turbo_power", to: "https://ga.jspm.io/npm:[email protected]/dist/index.js"

app/javascript/application.js

- import '@hotwired/turbo-rails'
+ import { Turbo } from '@hotwired/turbo'
import 'controllers'
+ import TurboPower from 'turbo_power'
+ TurboPower.initialize(Turbo.StreamActions)

Note: These modifications will continue to work when upgrading Turbo via the turbo-rails gem. You can read more for the reasoning behind these adjustments.

Custom Actions

DOM Actions

  • turbo_stream.graft(targets, parent, **attributes)
  • turbo_stream.morph(targets, html = nil, **attributes, &block)
  • turbo_stream.inner_html(targets, html = nil, **attributes, &block)
  • turbo_stream.insert_adjacent_html(targets, html = nil, position: 'beforeend', **attributes, &block)
  • turbo_stream.insert_adjacent_text(targets, text, position: 'beforebegin', **attributes)
  • turbo_stream.outer_html(targets, html = nil, **attributes, &block)
  • turbo_stream.text_content(targets, text, **attributes)
  • turbo_stream.set_meta(name, content, **attributes)

Attribute Actions

  • turbo_stream.add_css_class(targets, classes, **attributes)
  • turbo_stream.remove_attribute(targets, attribute, **attributes)
  • turbo_stream.remove_css_class(targets, classes, **attributes)
  • turbo_stream.set_attribute(targets, attribute, value, **attributes)
  • turbo_stream.set_dataset_attribute(targets, attribute, value, **attributes)
  • turbo_stream.set_property(targets, name, value, **attributes)
  • turbo_stream.set_style(targets, name, value, **attributes)
  • turbo_stream.set_styles(targets, styles, **attributes)
  • turbo_stream.set_value(targets, value, **attributes)

Event Actions

  • turbo_stream.dispatch_event(targets, name, detail: {}, **attributes)

Form Actions

  • turbo_stream.reset_form(targets, **attributes)

Storage Actions

  • turbo_stream.clear_storage(type, **attributes)
  • turbo_stream.clear_local_storage(**attributes)
  • turbo_stream.clear_session_storage(**attributes)
  • turbo_stream.remove_storage_item(key, type, **attributes)
  • turbo_stream.remove_local_storage_item(key, **attributes)
  • turbo_stream.remove_session_storage_item(key, **attributes)
  • turbo_stream.set_storage_item(key, value, type, **attributes)
  • turbo_stream.set_local_storage_item(key, value, **attributes)
  • turbo_stream.set_session_storage_item(key, value, **attributes)

Browser Actions

  • turbo_stream.reload(**attributes)
  • turbo_stream.scroll_into_view(targets, **attributes)
  • turbo_stream.set_focus(targets, **attributes)
  • turbo_stream.set_title(title, **attributes)

Document Actions

  • turbo_stream.set_cookie(cookie, **attributes)
  • turbo_stream.set_cookie_item(key, value, **attributes)

Browser History Actions

  • turbo_stream.history_back(**attributes)
  • turbo_stream.history_forward(**attributes)
  • turbo_stream.history_go(delta = 0, **attributes)
  • turbo_stream.push_state(url, title = "", state = {}, **attributes)
  • turbo_stream.replace_state(url, title = "", state = {}, **attributes)

Debug Actions

  • turbo_stream.console_log(message, level = :log, **attributes)
  • turbo_stream.console_table(data, columns, **attributes)

Notification Actions

  • turbo_stream.notification(title, **options)

Turbo Actions

  • turbo_stream.redirect_to(url, turbo_action = nil, **attributes)
  • turbo_stream.turbo_clear_cache()

Turbo Progress Bar Actions

  • turbo_stream.turbo_progress_bar_show(**attributes)
  • turbo_stream.turbo_progress_bar_hide(**attributes)
  • turbo_stream.turbo_progress_bar_set_value(value, **attributes)

Turbo Frame Actions

  • turbo_stream.turbo_frame_reload(frame_id, **attributes)
  • turbo_stream.turbo_frame_set_src(frame_id, src, **attributes)

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/turbo_power-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

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

More Repositories

1

turbo_power

Power-pack for Turbo Streams
TypeScript
323
star
2

current.js

A tiny 🀏 library (only 410 B) that allows you to access current `<meta>` elements
TypeScript
159
star
3

stimulus-lsp

Intelligent Stimulus tooling for Visual Studio Code and Neovim
TypeScript
127
star
4

gem.sh

Beautiful documentation for any Ruby gem.
Ruby
95
star
5

hotwire.io

Community-driven documentation and resource Hub for Hotwire.
HTML
94
star
6

turbo-morph

Morph action for Turbo Streams
JavaScript
90
star
7

boxdrop

Dropbox Clone built with StimulusReflex
Ruby
76
star
8

formulus

Client-side HTML form validations based on the browser HTML Form Validation API
TypeScript
72
star
9

phlexing

Simple ERB to Phlex converter
Ruby
71
star
10

turbo-ruby

Turbo helpers without the requirement for Rails
Ruby
41
star
11

cable-streams

Extend Turbo Streams with Custom Turbo Stream Actions and CableReady operations
TypeScript
26
star
12

stimulus-parser

Statically analyze Stimulus controllers in your project.
TypeScript
25
star
13

rails7-stimulus-reflex-esbuild

Example StimulusReflex installation using Rails 7 and esbuild
Ruby
24
star
14

stimulus-render

[PoC] HTML rendering mechanism for Stimulus Controllers
TypeScript
18
star
15

type_fusion

Collaborative Ruby type sampling
Ruby
16
star
16

local-time

Modern fork of Basecamp's `local-time`
TypeScript
12
star
17

easy_enum

Turn any Ruby class in an easy to use enum.
Ruby
12
star
18

cable_ready.cr

[WIP] CableReady Crystal port
Crystal
10
star
19

dependabot-bump-together-action

GitHub Action to bump multiple dependencies with dependabot in a single pull request
Ruby
8
star
20

rubocop-stimulus_reflex

Code style checking for StimulusReflex
Ruby
8
star
21

netatmo-ruby

Ruby gem to interact with the Netatmo REST API
Ruby
7
star
22

railsbytes-cli

CLI to apply Railsbytes.com templates to your Rails application
Ruby
7
star
23

cable-streams-rails

Rails companion gem for the `cable-streams` NPM package
Ruby
6
star
24

ShortLook-WhatsApp

Show WhatsApp users' profile pictures in ShortLook when you receive a WhatsApp notification
Objective-C
5
star
25

rubocop-cable_ready

Code style checking for CableReady
Ruby
4
star
26

ShortLook-Bandsintown

Show Bandsintown artists' profile pictures in ShortLook when you receive a Bandsintown notification
Objective-C
4
star
27

shortlook-cli

ShortLook CLI for scaffoling a ShortLook Provider
Ruby
3
star
28

stimulus-blurhash

Stimulus Controller for BlurHash
JavaScript
2
star
29

ShortLook-GitHub

Show GitHub users' profile pictures in ShortLook when you receive a GitHub notification
Objective-C
2
star
30

ShortLook-RocketChat

Show RocketChat users' profile pictures in ShortLook when you receive a RocketChat notification
Objective-C
2
star
31

ShortLook-VK

Show VK users' profile pictures in ShortLook when you receive a VK notification
Objective-C
2
star
32

ShortLook-Line

Show Line users' profile pictures in ShortLook when you receive a Line notification
Objective-C
2
star
33

ShortLook-KakaoTalk

Show KakaoTalk Contact Photos in ShortLook when you receive a KakaoTalk notification
Objective-C
2
star
34

usersnap-stimulus-repro

HTML
1
star
35

rcrdshp-market-extension

Small extension for the RCRDSHP Marketplace
JavaScript
1
star
36

POC2u

Ruby
1
star
37

cable_ready-dsl

[PoC] An opinionated DSL for CableReady.
Ruby
1
star
38

spritpreisrechner-ruby

Ruby Wrapper for the e-control.at Spritpreisrechner HTTP API
Ruby
1
star
39

tankerkoenig-ruby

Ruby Wrapper for the Tankerkoenig API
Ruby
1
star
40

ShortLook-Mixcloud

Show Mixcloud covers in ShortLook when you receive a Mixcloud notification
Objective-C
1
star
41

async-websocket-with-inactive-tab

HTML
1
star
42

stimulus_reflex-form-serialize-app

Ruby
1
star
43

mirrOS_spotify

Modul zum Anzeigen des zurzeit spielenden Track auf Spotify.
PHP
1
star
44

ShortLook-LinkedIn

Show LinkedIn users' profile pictures in ShortLook when you receive a LinkedIn notification
Objective-C
1
star
45

openmensa-parsers

OpenMensa.org parsers
Ruby
1
star
46

ShortLook-Slack

Show Slack users' profile pictures in ShortLook when you receive a Slack notification
Objective-C
1
star
47

ShortLook-SteamChat

Show SteamChat Profile Pictures in ShortLook when you receive a SteamChat notification!
Objective-C
1
star
48

ShortLook-Xing

Show Xing users' profile pictures in ShortLook when you receive a Xing notification
Objective-C
1
star
49

ShortLook-Viber

Show Viber users' profile pictures in ShortLook when you receive a Viber notification
Objective-C
1
star
50

mirrOS_todoist

Dieses mirrOS Modul zeigt deine Aufgaben aus einer Todoist-Liste an.
PHP
1
star