moonshot-rails 0.0.3 → 0.0.4
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 +4 -4
- data/README.md +72 -0
- data/app/assets/javascripts/moonshot/crisp_controller.js +24 -0
- data/app/assets/javascripts/moonshot/index.js +3 -1
- data/app/assets/javascripts/moonshot.js +4745 -6
- data/app/helpers/moonshot/moonshot_helper.rb +22 -0
- data/lib/moonshot-rails/engine.rb +0 -8
- data/lib/moonshot-rails/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80ae99ac2e3300a7795f3612397bb4c338c3fe4641392ba83bc2d6910f14cdd6
|
4
|
+
data.tar.gz: 0b20b0277be40bc1ac7bb57a2c49e5da29726e4d7a400b1777759ad11c8e74d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a53608e24e4cabd49d5c426124774e526e1f898f1535615a1bb104384a8088f88197550be8a20f62c714565397d6ce3f82ebe494244c03c0a09971ebd28d63d9
|
7
|
+
data.tar.gz: 4813fce7da2d850201bfe19e084f7e3371d8e51370be47539d34a239cf6d9a6415d00bb5f78429dc558b28c4ba56e2f549ebb538894bac1c4446a1a6375c55b8
|
data/README.md
CHANGED
@@ -1,12 +1,84 @@
|
|
1
1
|
# Moonshot Rails
|
2
2
|
|
3
|
+
A collection of Stimulus controllers and other helpers enabling faster building of SaaS applications using modern Rails and Stimulus. Most of these are heavily opinionated.
|
4
|
+
|
5
|
+
1. [Post Hog Analytics Stimulusjs wrapper](#1-post-hog-analytics-stimulusjs-wrapper)
|
6
|
+
2. [Shepherdjs Stimulusjs wrapper](#2-shepherdjs-stimulusjs-wrapper)
|
7
|
+
3. [Crisp Chat Stimulusjs wrapper](#3-crisp-chat-stimulusjs-wrapper)
|
8
|
+
|
3
9
|
## Installation
|
4
10
|
|
5
11
|
```bash
|
6
12
|
bundle add moonshot-rails
|
7
13
|
yarn add moonshot-rails
|
14
|
+
|
8
15
|
```
|
9
16
|
|
17
|
+
### Include all the stimulus controllers
|
18
|
+
|
19
|
+
```bash
|
20
|
+
# append this to `app/javascript/controllers/index.js`
|
21
|
+
|
22
|
+
import { registerControllers } from 'moonshot-rails'
|
23
|
+
registerControllers(application)
|
24
|
+
```
|
25
|
+
|
26
|
+
### You can also pick and choose which controllers to include
|
27
|
+
|
28
|
+
```bash
|
29
|
+
# append this to `app/javascript/controllers/index.js`
|
30
|
+
|
31
|
+
import { PostHogController } from 'moonshot-rails'
|
32
|
+
application.register('post-hog', PostHogController)
|
33
|
+
|
34
|
+
# see the full list at https://github.com/cionescu/moonshot-rails/blob/main/app/assets/javascripts/moonshot/index.js
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contents
|
38
|
+
|
39
|
+
### 1. Post Hog Analytics Stimulusjs wrapper
|
40
|
+
|
41
|
+
I tend to use [PostHog](https://posthog.com/) for session tracking and product usage analytics.
|
42
|
+
|
43
|
+
#### Usage:
|
44
|
+
|
45
|
+
In your layout file, add the following:
|
46
|
+
|
47
|
+
```erb
|
48
|
+
= post_hog_tracker user: @user, enabled: Rails.env.production?, api_key: Settings.post_hog.api_key
|
49
|
+
```
|
50
|
+
|
51
|
+
Your `User` model needs to implement the following methods:
|
52
|
+
* `id` - used to uniquely identify the user. I usually use the `id` column.
|
53
|
+
* `tracker_name` - the display name for the user object. Could be `User#full_name`.
|
54
|
+
* `tracker_email` - another way to identify the user.
|
55
|
+
|
56
|
+
### 2. Shepherdjs Stimulusjs wrapper
|
57
|
+
|
58
|
+
*TODO*
|
59
|
+
|
60
|
+
### 3. Crisp Chat Stimulusjs wrapper
|
61
|
+
|
62
|
+
[Crisp](https://crisp.chat/) is one of the options for a live chat/support widget. I tend to like to like it because it comes with an npm package, meaning I can wrap it in a Stimulus controller.
|
63
|
+
|
64
|
+
In the layout file, add the following:
|
65
|
+
|
66
|
+
```erb
|
67
|
+
= crisp_chat user: current_user, enabled: Rails.env.production?, wrapper: :div, api_key: Settings.crisp.api_key
|
68
|
+
```
|
69
|
+
|
70
|
+
If you want to activate (open) the chat widget when clicking a link on the page, you can follow this pattern:
|
71
|
+
|
72
|
+
```erb
|
73
|
+
You can reach out to us via the
|
74
|
+
= crisp_chat(user: current_user, enabled: Rails.env.production?, wrapper: :span, api_key: Settings.crisp.api_key) do
|
75
|
+
= link_to 'in-app chat', '#', data: { action: 'click->crisp#open' }, class: 'btn-link text-primary'
|
76
|
+
```
|
77
|
+
|
78
|
+
Similarly to the PostHog wrapper, the `User` model needs to implement the following methods:
|
79
|
+
* `tracker_name` - the display name for the user object. Could be `User#full_name`.
|
80
|
+
* `tracker_email` - another way to identify the user.
|
81
|
+
|
10
82
|
## Release
|
11
83
|
|
12
84
|
### Ruby Gem
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { Crisp } from "crisp-sdk-web"
|
2
|
+
import { Controller } from "@hotwired/stimulus"
|
3
|
+
|
4
|
+
export default class extends Controller {
|
5
|
+
static values = {
|
6
|
+
websiteId: String,
|
7
|
+
identification: Object
|
8
|
+
}
|
9
|
+
|
10
|
+
connect() {
|
11
|
+
Crisp.configure(this.websiteIdValue)
|
12
|
+
if (Object.keys(this.identificationValue).length) {
|
13
|
+
const { email, name } = this.identificationValue
|
14
|
+
|
15
|
+
Crisp.user.setEmail(email)
|
16
|
+
Crisp.user.setNickname(name)
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
open(e) {
|
21
|
+
e.preventDefault()
|
22
|
+
Crisp.chat.open()
|
23
|
+
}
|
24
|
+
}
|
@@ -1,11 +1,13 @@
|
|
1
1
|
import PostHogController from './post_hog_controller'
|
2
2
|
import ShepherdController from './shepherd_controller'
|
3
|
+
import CrispController from './crisp_controller'
|
3
4
|
|
4
5
|
export {
|
5
|
-
PostHogController, ShepherdController
|
6
|
+
PostHogController, ShepherdController, CrispController
|
6
7
|
}
|
7
8
|
|
8
9
|
export function registerControllers(application) {
|
9
10
|
application.register('shepherd', ShepherdController)
|
10
11
|
application.register('post-hog', PostHogController)
|
12
|
+
application.register('crisp', CrispController)
|
11
13
|
}
|