moonshot-rails v0.0.18
Moonshot Rails
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.
JavaScript Helpers
Content Helpers
- Jobs to be Done view component
Background Jobs
- Convertkit Subscribe / Unsubscribe
Installation
  bundle add moonshot-rails
  yarn add moonshot-railsGenerate an initializer
  bundle exec rails generate moonshot_railsInclude all the stimulus controllers
  # append this to `app/javascript/controllers/index.js`
  import { registerControllers } from 'moonshot-rails'
  registerControllers(application)You can also pick and choose which controllers to include
  # append this to `app/javascript/controllers/index.js`
  import { PostHogController } from 'moonshot-rails'
  application.register('post-hog', PostHogController)
  # see the full list at https://github.com/cionescu/moonshot-rails/blob/main/app/assets/javascripts/moonshot/index.jsContents
1. Post Hog Analytics Stimulusjs wrapper
I tend to use PostHog for session tracking and product usage analytics.
Usage:
In your layout file, add the following:
  = post_hog_tracker user: @user, enabled: Rails.env.production?, api_key: Settings.post_hog.api_keyYour User model needs to implement the following methods:
- id- used to uniquely identify the user. I usually use the- idcolumn.
- tracker_name- the display name for the user object. Could be- User#full_name.
- tracker_email- another way to identify the user.
2. Shepherdjs Stimulusjs wrapper
TODO
3. Crisp Chat Stimulusjs wrapper
Crisp 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.
In the layout file, add the following:
  = crisp_chat user: current_user, enabled: Rails.env.production?, wrapper: :div, api_key: Settings.crisp.api_keyIf you want to activate (open) the chat widget when clicking a link on the page, you can follow this pattern:
  You can reach out to us via the
  = crisp_chat(user: current_user, enabled: Rails.env.production?, wrapper: :span, api_key: Settings.crisp.api_key) do
    = link_to 'in-app chat', '#', data: { action: 'click->crisp#open' }, class: 'btn-link text-primary'Similarly to the PostHog wrapper, the User model needs to implement the following methods:
- tracker_name- the display name for the user object. Could be- User#full_name.
- tracker_email- another way to identify the user.
Release
Ruby Gem
  rake releaseJavaScript Package
  npm run release