simple_chat 0.1.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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +178 -0
- data/Rakefile +6 -0
- data/app/assets/stylesheets/simple_chat/application.css +726 -0
- data/app/assets/stylesheets/simple_chat/application.tailwind.css +1 -0
- data/app/controllers/simple_chat/application_controller.rb +16 -0
- data/app/controllers/simple_chat/chat_members_controller.rb +27 -0
- data/app/controllers/simple_chat/chat_rooms_controller.rb +74 -0
- data/app/controllers/simple_chat/messages_controller.rb +77 -0
- data/app/helpers/simple_chat/application_helper.rb +4 -0
- data/app/helpers/simple_chat/chat_rooms_helper.rb +4 -0
- data/app/helpers/simple_chat/messages_helper.rb +4 -0
- data/app/jobs/simple_chat/application_job.rb +4 -0
- data/app/mailers/simple_chat/application_mailer.rb +6 -0
- data/app/models/simple_chat/application_record.rb +5 -0
- data/app/models/simple_chat/chat_member.rb +6 -0
- data/app/models/simple_chat/chat_room.rb +22 -0
- data/app/models/simple_chat/message.rb +8 -0
- data/app/views/layouts/simple_chat/application.html.erb +24 -0
- data/app/views/simple_chat/chat_rooms/_chat_room.html.erb +7 -0
- data/app/views/simple_chat/chat_rooms/_form.html.erb +22 -0
- data/app/views/simple_chat/chat_rooms/edit.html.erb +12 -0
- data/app/views/simple_chat/chat_rooms/index.html.erb +14 -0
- data/app/views/simple_chat/chat_rooms/new.html.erb +11 -0
- data/app/views/simple_chat/chat_rooms/show.html.erb +80 -0
- data/app/views/simple_chat/messages/_form.html.erb +28 -0
- data/app/views/simple_chat/messages/_message.html.erb +28 -0
- data/app/views/simple_chat/messages/create.turbo_stream.erb +10 -0
- data/app/views/simple_chat/messages/edit.html.erb +12 -0
- data/app/views/simple_chat/messages/index.html.erb +14 -0
- data/app/views/simple_chat/messages/new.html.erb +11 -0
- data/app/views/simple_chat/messages/show.html.erb +8 -0
- data/config/routes.rb +7 -0
- data/config/tailwind.config.js +15 -0
- data/db/migrate/20260406070146_create_simple_chat_chat_rooms.rb +9 -0
- data/db/migrate/20260406080846_create_simple_chat_chat_members.rb +11 -0
- data/db/migrate/20260406081003_create_simple_chat_messages.rb +12 -0
- data/db/migrate/20260503095220_add_channel_hash_to_solid_cable_messages.rb +6 -0
- data/lib/generators/simple_chat/install_generator.rb +21 -0
- data/lib/simple_chat/configuration.rb +16 -0
- data/lib/simple_chat/engine.rb +13 -0
- data/lib/simple_chat/version.rb +3 -0
- data/lib/simple_chat.rb +42 -0
- data/lib/tasks/simple_chat_tasks.rake +40 -0
- metadata +146 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SimpleChat
|
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
|
5
|
+
def create_initializer
|
|
6
|
+
initializer "simple_chat.rb" do
|
|
7
|
+
<<~RUBY
|
|
8
|
+
# Initialize SimpleChat
|
|
9
|
+
SimpleChat.configure do |config|
|
|
10
|
+
# Set the user model that will be used for chat members and messages
|
|
11
|
+
# config.chat_user_model = 'User'
|
|
12
|
+
|
|
13
|
+
# Set the method to get the current user in the controller
|
|
14
|
+
# Defaults to :current_user (standard for Devise)
|
|
15
|
+
# config.current_user_method = :current_user
|
|
16
|
+
end
|
|
17
|
+
RUBY
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Usage in Rails application config/initializers/simple_chat.rb)
|
|
4
|
+
# SimpleChat.configure do |config|
|
|
5
|
+
# config.chat_user_model = 'User'
|
|
6
|
+
# end
|
|
7
|
+
module SimpleChat
|
|
8
|
+
class Configuration
|
|
9
|
+
attr_accessor :chat_user_model, :current_user_method
|
|
10
|
+
|
|
11
|
+
def initialize
|
|
12
|
+
@chat_user_model = "User"
|
|
13
|
+
@current_user_method = :current_user
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require "turbo-rails"
|
|
2
|
+
require "solid_cable"
|
|
3
|
+
require "tailwindcss-rails"
|
|
4
|
+
|
|
5
|
+
module SimpleChat
|
|
6
|
+
class Engine < ::Rails::Engine
|
|
7
|
+
isolate_namespace SimpleChat
|
|
8
|
+
|
|
9
|
+
initializer "simple_chat.assets" do |app|
|
|
10
|
+
app.config.assets.precompile += %w( simple_chat/application.css )
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
data/lib/simple_chat.rb
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require "simple_chat/version"
|
|
2
|
+
require "simple_chat/engine"
|
|
3
|
+
require 'simple_chat/configuration'
|
|
4
|
+
|
|
5
|
+
module SimpleChat
|
|
6
|
+
class << self
|
|
7
|
+
attr_writer :configuration
|
|
8
|
+
|
|
9
|
+
# Access the configuration object
|
|
10
|
+
def configuration
|
|
11
|
+
@configuration ||= Configuration.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# The block handler
|
|
15
|
+
def configure
|
|
16
|
+
yield(configuration)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def create_chat(*users, title: nil)
|
|
20
|
+
users = users.flatten.compact
|
|
21
|
+
if title.nil?
|
|
22
|
+
names = users.map { |u| u.respond_to?(:name) ? u.name : u.id }
|
|
23
|
+
if names.size > 2
|
|
24
|
+
title = "Chat between #{names[0...-1].join(", ")} and #{names.last}"
|
|
25
|
+
elsif names.size == 2
|
|
26
|
+
title = "Chat between #{names.first} and #{names.last}"
|
|
27
|
+
elsif names.size == 1
|
|
28
|
+
title = "Chat for #{names.first}"
|
|
29
|
+
else
|
|
30
|
+
title = "Empty Chat"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
ChatRoom.transaction do
|
|
35
|
+
chat_room = ChatRoom.create!(title: title)
|
|
36
|
+
users.each { |user| chat_room.chat_members.create!(user: user) }
|
|
37
|
+
|
|
38
|
+
chat_room
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
namespace :simple_chat do
|
|
2
|
+
desc "Setup User table, model and seed data for testing"
|
|
3
|
+
task setup_test_user: :environment do
|
|
4
|
+
# 1. Create Migration
|
|
5
|
+
migration_name = "CreateUsers"
|
|
6
|
+
if !ActiveRecord::Base.connection.table_exists?(:users)
|
|
7
|
+
puts "Creating migration for users table..."
|
|
8
|
+
system("rails generate migration #{migration_name} name:string")
|
|
9
|
+
system("rails db:migrate")
|
|
10
|
+
else
|
|
11
|
+
puts "Users table already exists."
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# 2. Create Model if not exists
|
|
15
|
+
model_path = Rails.root.join("app", "models", "user.rb")
|
|
16
|
+
if !File.exist?(model_path)
|
|
17
|
+
puts "Creating User model..."
|
|
18
|
+
File.open(model_path, "w") do |f|
|
|
19
|
+
f.write <<~RUBY
|
|
20
|
+
class User < ApplicationRecord
|
|
21
|
+
end
|
|
22
|
+
RUBY
|
|
23
|
+
end
|
|
24
|
+
else
|
|
25
|
+
puts "User model already exists."
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# 3. Seed Users
|
|
29
|
+
puts "Seeding 5 users..."
|
|
30
|
+
user_class = "User".safe_constantize
|
|
31
|
+
if user_class
|
|
32
|
+
5.times do |i|
|
|
33
|
+
user_class.find_or_create_by!(name: "Test User #{i + 1}")
|
|
34
|
+
end
|
|
35
|
+
puts "Successfully seeded 5 users."
|
|
36
|
+
else
|
|
37
|
+
puts "Error: User class not found."
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: simple_chat
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- YiSheng, Lee
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rails
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 8.1.3
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 8.1.3
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: turbo-rails
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: solid_cable
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: tailwindcss-rails
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
type: :runtime
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
description: SimpleChat is a Rails engine that provides a ready-to-use chat system.
|
|
69
|
+
It supports chat rooms, members, and real-time messaging leveraging Turbo Streams
|
|
70
|
+
and Solid Cable for a modern, reactive experience.
|
|
71
|
+
email:
|
|
72
|
+
- yisheng.lee@outlook.com
|
|
73
|
+
executables: []
|
|
74
|
+
extensions: []
|
|
75
|
+
extra_rdoc_files: []
|
|
76
|
+
files:
|
|
77
|
+
- MIT-LICENSE
|
|
78
|
+
- README.md
|
|
79
|
+
- Rakefile
|
|
80
|
+
- app/assets/stylesheets/simple_chat/application.css
|
|
81
|
+
- app/assets/stylesheets/simple_chat/application.tailwind.css
|
|
82
|
+
- app/controllers/simple_chat/application_controller.rb
|
|
83
|
+
- app/controllers/simple_chat/chat_members_controller.rb
|
|
84
|
+
- app/controllers/simple_chat/chat_rooms_controller.rb
|
|
85
|
+
- app/controllers/simple_chat/messages_controller.rb
|
|
86
|
+
- app/helpers/simple_chat/application_helper.rb
|
|
87
|
+
- app/helpers/simple_chat/chat_rooms_helper.rb
|
|
88
|
+
- app/helpers/simple_chat/messages_helper.rb
|
|
89
|
+
- app/jobs/simple_chat/application_job.rb
|
|
90
|
+
- app/mailers/simple_chat/application_mailer.rb
|
|
91
|
+
- app/models/simple_chat/application_record.rb
|
|
92
|
+
- app/models/simple_chat/chat_member.rb
|
|
93
|
+
- app/models/simple_chat/chat_room.rb
|
|
94
|
+
- app/models/simple_chat/message.rb
|
|
95
|
+
- app/views/layouts/simple_chat/application.html.erb
|
|
96
|
+
- app/views/simple_chat/chat_rooms/_chat_room.html.erb
|
|
97
|
+
- app/views/simple_chat/chat_rooms/_form.html.erb
|
|
98
|
+
- app/views/simple_chat/chat_rooms/edit.html.erb
|
|
99
|
+
- app/views/simple_chat/chat_rooms/index.html.erb
|
|
100
|
+
- app/views/simple_chat/chat_rooms/new.html.erb
|
|
101
|
+
- app/views/simple_chat/chat_rooms/show.html.erb
|
|
102
|
+
- app/views/simple_chat/messages/_form.html.erb
|
|
103
|
+
- app/views/simple_chat/messages/_message.html.erb
|
|
104
|
+
- app/views/simple_chat/messages/create.turbo_stream.erb
|
|
105
|
+
- app/views/simple_chat/messages/edit.html.erb
|
|
106
|
+
- app/views/simple_chat/messages/index.html.erb
|
|
107
|
+
- app/views/simple_chat/messages/new.html.erb
|
|
108
|
+
- app/views/simple_chat/messages/show.html.erb
|
|
109
|
+
- config/routes.rb
|
|
110
|
+
- config/tailwind.config.js
|
|
111
|
+
- db/migrate/20260406070146_create_simple_chat_chat_rooms.rb
|
|
112
|
+
- db/migrate/20260406080846_create_simple_chat_chat_members.rb
|
|
113
|
+
- db/migrate/20260406081003_create_simple_chat_messages.rb
|
|
114
|
+
- db/migrate/20260503095220_add_channel_hash_to_solid_cable_messages.rb
|
|
115
|
+
- lib/generators/simple_chat/install_generator.rb
|
|
116
|
+
- lib/simple_chat.rb
|
|
117
|
+
- lib/simple_chat/configuration.rb
|
|
118
|
+
- lib/simple_chat/engine.rb
|
|
119
|
+
- lib/simple_chat/version.rb
|
|
120
|
+
- lib/tasks/simple_chat_tasks.rake
|
|
121
|
+
homepage: https://github.com/yisheng-lee/simple_chat
|
|
122
|
+
licenses:
|
|
123
|
+
- MIT
|
|
124
|
+
metadata:
|
|
125
|
+
allowed_push_host: https://rubygems.org
|
|
126
|
+
homepage_uri: https://github.com/yisheng-lee/simple_chat
|
|
127
|
+
source_code_uri: https://github.com/yisheng-lee/simple_chat
|
|
128
|
+
changelog_uri: https://github.com/yisheng-lee/simple_chat
|
|
129
|
+
rdoc_options: []
|
|
130
|
+
require_paths:
|
|
131
|
+
- lib
|
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
|
+
requirements:
|
|
134
|
+
- - ">="
|
|
135
|
+
- !ruby/object:Gem::Version
|
|
136
|
+
version: '0'
|
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
|
+
requirements:
|
|
139
|
+
- - ">="
|
|
140
|
+
- !ruby/object:Gem::Version
|
|
141
|
+
version: '0'
|
|
142
|
+
requirements: []
|
|
143
|
+
rubygems_version: 4.0.9
|
|
144
|
+
specification_version: 4
|
|
145
|
+
summary: A simple chat engine for Rails applications using Turbo and Solid Cable.
|
|
146
|
+
test_files: []
|