Coder Social home page Coder Social logo

ianrandmckenzie / messaged Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 167 KB

A gem for quickly and easily implementing Hotwire Turbo chat modules on Ruby on Rails apps.

Home Page: https://rubygems.org/gems/messaged

License: MIT License

Ruby 74.04% JavaScript 0.52% CSS 2.10% HTML 23.35%
hotwire-turbo instant-messaging ruby ruby-on-rails

messaged's Introduction

Messaged

A Rails Engine for Hotwire Turbo-powered instant messaging.

The author would personally recommend against using this Gem if your Rails application is not built for Turbo Rails.

As seen on PalmerTrolls on YouTube! Watch on YouTube:

Video of Ben Palmer using messaged through a prank website

Installation

Add this line to your application's Gemfile:

gem "messaged"

And then execute:

bundle

Or install it yourself as:

gem install messaged

Generate the needed migrations and initializer:

rails generate messaged:install
rails messaged:install:migrations

Importmap

If you do not yet have importmap-rails added to your application, be sure to add config/importmap.rb:

# config/importmap.rb
pin "application", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true

Usage

Messages broadcast to the DOM element id messages

<div id="messages"></div>

To get started with a basic HTML structure, run in your terminal: rails generate messaged:views

If you're using this engine or turbo-rails for the first time, it is recommended to generate the views to familiarize yourself with how turbo tags are used when turbo streaming.

Routes

If you're starting a fresh application, ensure your application has a root path.

# For example:
root to: "home#index"

Next, set up your ActionCable routes if you haven't already.

mount ActionCable.server => '/cable'

Lastly, mount the Messaged engine's paths.

mount Messaged::Engine => "/messaged"

Users

Messaged assumes you have a user model. You may customize the user model name in the initializer. For example, if your user model is called Member:

# config/initializers/messaged.rb
Messaged.user_class = 'Member'
Messaged.current_user_method = :current_member

Tenants

Messaged does not assume the application is multi-tenant, but does support it. By default, Messaged.tenant_class is set to nil.

# config/initializers/messaged.rb
Messaged.tenant_class = 'Account'
Messaged.current_tenant_method = :current_account

Dependencies

It is recommended, particularly for development, to have a websockets compatible web server. This is true for production as well, but puma adds an easy way to support websockets without needing additional infrastructure from external services.

gem "puma"

By default, Messaged is powered by:

gem "rails", ">= 7.0.2.3"
gem "importmap-rails", "1.1.5"
gem "turbo-rails", "1.3.0"

If your application cannot support these gems, it is recommended that you do not use the Messaged engine. Alternatively, feel free to work this engine and add support for your desired setup. Pull requests are welcome, see: CONTRIBUTING.md

Contributing

See CONTRIBUTING.md

License

The gem is available as open source under the terms of the MIT License. See also: LICENSE.txt

Other Info

Messaged is intended to be named through the nomenclature used in Noticed, in part because Collin and I met through the GoRails Discord server (owned by @excid3). β€”Ian

TODO

  • Complete adding rich_text support
  • Complete multi-tenant support
  • Create and finish the test suite via TestKit

TODO on bleeding pre-merge

  • Add documentation about how to extend messages and rooms
    • If not for anyone else, do it for future you
  • Add to docs about how it is up to the dev to determine how messages/rooms are authorized

messaged's People

Contributors

ianrandmckenzie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.