product_tours 0.1.1 → 0.1.2
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/AGENTS.md +149 -0
- data/CHANGELOG.md +15 -0
- data/README.md +5 -0
- data/lib/product_tours/version.rb +1 -1
- data/lib/product_tours/widget.rb +5 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fab25758d2c1f8d2c5671555ddfcc04a1c473c60271635ec1e1c191bf9791718
|
|
4
|
+
data.tar.gz: 42217e9e5f0f89d25c5bebafb93ad3918e77933707d98cd4d3277f9cc0e3920e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3f2943f106b77da806858a18c719bd63311ad744b1fe08f637a747cf4f0f6dddb89d5399afe53d121acd6bb81da0b9db5cf560c5a307de39d45fe1440c6adc0f
|
|
7
|
+
data.tar.gz: 75b8e54316db23fecbe7ab4398993afd616893bd8d2bd75e3c4bf0b0c834b65e29f6a6d97ff0d2302736e3067fe2952509677def0bc2abb607a167f0b98e375c
|
data/AGENTS.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
Instructions for coding agents. Two audiences:
|
|
4
|
+
|
|
5
|
+
- **[Installing product_tours into a Rails app](#installing-into-a-rails-app)** — you are working in a host app and were asked to add product tours, onboarding guides, or video tutorials.
|
|
6
|
+
- **[Working on the gem itself](#working-on-the-gem-itself)** — you are working in this repository.
|
|
7
|
+
|
|
8
|
+
Requirements: Ruby >= 3.2, Rails >= 7.1. Active Storage only for uploaded videos, Action Text only for rich descriptions — both optional and both degrade rather than raise.
|
|
9
|
+
|
|
10
|
+
If you are in a host app and this file is not in front of you, it ships inside the gem: `cat "$(bundle show product_tours)/AGENTS.md"`.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Installing into a Rails app
|
|
15
|
+
|
|
16
|
+
### 1. Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
bundle add product_tours
|
|
20
|
+
bin/rails generate product_tours:install
|
|
21
|
+
bin/rails db:migrate
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The generator writes `config/initializers/product_tours.rb`, one migration (`product_tours_posts`), and `mount_product_tours at: "/product_tours"` into `config/routes.rb`. **In development the migration also inserts working demo tutorials**, so the modal has something to open before anyone has written content. Read the initializer it wrote — it is the source of truth over any summary of it, including this file.
|
|
25
|
+
|
|
26
|
+
### 2. Wire the three things the generator cannot
|
|
27
|
+
|
|
28
|
+
**a. The widget tag**, once, in the layout:
|
|
29
|
+
|
|
30
|
+
```erb
|
|
31
|
+
<%# app/views/layouts/application.html.erb, before </body> %>
|
|
32
|
+
<%= product_tours_tag %>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The helper is injected into ActionView by the engine — no include, no import, no asset pipeline entry.
|
|
36
|
+
|
|
37
|
+
**b. A trigger**, wherever the tutorial is useful. This is the part that makes it different from a SaaS tour builder: nothing auto-attaches to DOM nodes, you put the button where it belongs.
|
|
38
|
+
|
|
39
|
+
```erb
|
|
40
|
+
<button data-product-tour="billing_setup">Watch the billing guide</button>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The value is a tutorial **key**, and the key must exist and be **published** or the trigger does nothing.
|
|
44
|
+
|
|
45
|
+
**c. `authorize_admin` — do this before deploying.** The dashboard at `/product_tours` defaults to **development only**. It fails closed, so shipping without this is not an open dashboard — it is a 403 reading "Forbidden. Set ProductTours.config.authorize_admin to grant access."
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
config.authorize_admin = ->(request) { request.env["warden"]&.user&.admin? }
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
> **`enabled` and `authorize_admin` receive the raw `request`, not a controller.** Writing `->(request) { current_user }` is the most common mistake here — that method does not exist in this scope. Resolve the user *from the request*: Warden env, a signed cookie, `Current.user` if middleware already set it.
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
# Rails 8 built-in auth
|
|
55
|
+
config.authorize_admin = lambda do |request|
|
|
56
|
+
token = request.cookies["session_token"]
|
|
57
|
+
Session.find_signed(token)&.user&.admin? || false
|
|
58
|
+
end
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 3. Verify
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
bin/rails routes | grep product_tours # engine mounted
|
|
65
|
+
bin/rails product_tours:seed_demo # refresh demo tutorials in every locale
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Then in the running app: open `/product_tours`, confirm the demo tutorials are listed, and click a `data-product-tour` button on one of your own pages.
|
|
69
|
+
|
|
70
|
+
### Tutorials are content, not code
|
|
71
|
+
|
|
72
|
+
A tutorial is a row in `product_tours_posts`, written and published in the mounted dashboard. **Do not create tutorials from host-app migrations, seeds, or fixtures** — that is not how this gem is meant to be used, and it puts editorial content in schema history. If the app needs sample content, `bin/rails product_tours:seed_demo` is the supported path.
|
|
73
|
+
|
|
74
|
+
What a tutorial carries: a `key`, a title, an optional rich description, an optional video, and at most one primary action (a URL, or the key of the next tutorial — that link is what makes a walkthrough). Keys must match `/\A[a-z0-9]+(?:[._-][a-z0-9]+)*\z/` — lowercase, digits, and `. _ -` as separators. `Billing Setup` and `billingSetup` are invalid; `billing_setup` and `billing.step-1` are fine. `status` is `draft` or `published`, and the key is unique **per locale**, which is how translations work: one row per language for the same key, with locale fallback at resolve time.
|
|
75
|
+
|
|
76
|
+
### Video providers
|
|
77
|
+
|
|
78
|
+
YouTube, Vimeo, Loom, Tella, Voomly, a direct MP4/WebM URL, or an uploaded file (needs Active Storage). Uploaded videos stream through the engine at `/product_tours/media/:id` — not a public blob URL. Do not build your own blob links.
|
|
79
|
+
|
|
80
|
+
**The engine edits the app's Content Security Policy.** It appends the providers' embed hosts to `frame-src` (or to `default-src` when `frame-src` is unset) in an initializer that runs after the host's own. That is deliberate — an embed silently blocked by CSP is a bad first five minutes — but know it happens, and do not hand-add those `frame-src` entries yourself. If the app sets its CSP somewhere unusual (a middleware, a per-controller override), that is where a blocked embed will come from.
|
|
81
|
+
|
|
82
|
+
### Lifecycle events
|
|
83
|
+
|
|
84
|
+
Subscribe in an initializer; there is no callback config to set.
|
|
85
|
+
|
|
86
|
+
```ruby
|
|
87
|
+
ActiveSupport::Notifications.subscribe("product_tours.completed") do |*, payload|
|
|
88
|
+
# payload has the tutorial key and request context
|
|
89
|
+
end
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Names: `product_tours.viewed`, `product_tours.dismissed`, `product_tours.completed`, and `product_tours.unresolved_trigger` — the last one fires when a `data-product-tour` button names a key that does not resolve. Subscribe to it in development; it turns "my button does nothing" into a log line naming the key.
|
|
93
|
+
|
|
94
|
+
### Do not
|
|
95
|
+
|
|
96
|
+
- **Do not copy the widget JavaScript into `app/javascript`, or add a `<script>` tag for it.** `product_tours_tag` renders what is needed and the engine serves the code. There is no build step and nothing for esbuild/importmap/Tailwind to know about.
|
|
97
|
+
- **Do not create or edit tutorials in code** (see above).
|
|
98
|
+
- **Do not add provider hosts to `frame-src` by hand** — the engine already does it.
|
|
99
|
+
- **Do not serve uploaded videos by blob URL** — the gated media route exists so a leaked signed URL cannot hand over your content.
|
|
100
|
+
- **Do not install Active Storage or Action Text "to make it work"** unless the app actually wants uploads or rich text. Both are optional; the gem checks for them (`Post.video_upload_supported?`, `Post.description_supported?`) and simply offers less.
|
|
101
|
+
|
|
102
|
+
### Configuration
|
|
103
|
+
|
|
104
|
+
There are five options. That is the whole surface.
|
|
105
|
+
|
|
106
|
+
| Option | Default | What it does |
|
|
107
|
+
| --- | --- | --- |
|
|
108
|
+
| `authorize_admin` | development only | **Who can read and edit tutorials. Set before deploying.** |
|
|
109
|
+
| `enabled` | everyone | Per-request gate for the widget and its endpoints |
|
|
110
|
+
| `admin_layout` | `product_tours/application` | Render the dashboard inside your admin shell |
|
|
111
|
+
| `mount_path` | `"/product_tours"` | Keep in sync with `mount_product_tours at:` |
|
|
112
|
+
| `storage_service` | app default | Active Storage service for uploaded video (a `storage.yml` key) |
|
|
113
|
+
|
|
114
|
+
26 locales ship with the gem, RTL included.
|
|
115
|
+
|
|
116
|
+
### Common failure modes
|
|
117
|
+
|
|
118
|
+
| Symptom | Cause |
|
|
119
|
+
| --- | --- |
|
|
120
|
+
| The trigger button does nothing | No tutorial with that key, or it is still a draft, or `product_tours_tag` is missing from the layout. Subscribe to `product_tours.unresolved_trigger` to see which |
|
|
121
|
+
| `/product_tours` returns 403 "Set ProductTours.config.authorize_admin to grant access" | Exactly what it says: still at the development-only default |
|
|
122
|
+
| Key rejected on save | It must match `/\A[a-z0-9]+(?:[._-][a-z0-9]+)*\z/` — no capitals, no spaces |
|
|
123
|
+
| Video area blank for an embed | CSP. The engine appends provider hosts to `frame-src`; a policy set outside `config.content_security_policy` will not have them |
|
|
124
|
+
| No upload option on the form | Active Storage not installed |
|
|
125
|
+
| No rich-text editor for the description | Action Text not installed |
|
|
126
|
+
| Duplicate-key error when adding a translation | The key is unique per locale — add the translation from the tutorial page rather than creating a second record by hand |
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Working on the gem itself
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
bundle exec rake test # minitest, dummy app under test/dummy
|
|
134
|
+
bundle exec rubocop # must be clean
|
|
135
|
+
BUNDLE_GEMFILE=gemfiles/rails_7.1.gemfile bundle exec rake test # 7.1, 7.2, 8.0, 8.1 in gemfiles/
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Layout: `app/` controllers, `Post`, dashboard views · `lib/product_tours/` config, widget JS, seeds, engine, CSP patch · `lib/generators/product_tours/install/` the one generator · `config/locales/` 26 locales · `test/` minitest with `test/dummy` as the host app.
|
|
139
|
+
|
|
140
|
+
Conventions this codebase holds to — follow them rather than the first thing that works:
|
|
141
|
+
|
|
142
|
+
- **Optional dependencies are checked, never assumed.** `has_rich_text` is declared only `if respond_to?`, `has_one_attached` only `if defined?(::ActiveStorage)`, and the model exposes `description_supported?` / `video_upload_supported?` so views can offer less instead of raising. An app with neither gem must boot and work.
|
|
143
|
+
- **Triggers are explicit.** The gem never guesses at DOM nodes or auto-starts a tour; a host puts `data-product-tour="key"` where it wants it. A trigger naming a key that does not resolve is instrumented, not silently swallowed.
|
|
144
|
+
- **The widget is plain JS served by the engine** — no build step, no framework, no CDN.
|
|
145
|
+
- **Uploaded media streams through the engine's gate**, never a public blob URL.
|
|
146
|
+
- **The CSP patch is additive.** It appends to existing sources and drops `'none'` rather than replacing a host's policy — do not let it start overwriting directives.
|
|
147
|
+
- **The dummy app pins `config.active_job.queue_adapter = :test`.** Do not remove it or let it drift back to the `:async` default. Attaching a video enqueues Active Storage's analysis job, and `:async` runs it on a background thread that checks out its own connection — writes no test transaction covers, landing in the middle of whatever runs next. That is a suite that fails order-dependently in a test which never created a row, and it is miserable to trace back.
|
|
148
|
+
- Every user-facing change bumps `lib/product_tours/version.rb` and adds a `CHANGELOG.md` entry (Keep a Changelog format) that says what it costs, not only what it adds.
|
|
149
|
+
- Commit messages are prose that explains the tradeoff — read `git log` before writing one.
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.1.2] - 2026-08-04
|
|
6
|
+
|
|
7
|
+
- Added `AGENTS.md`: install and integration instructions written for coding
|
|
8
|
+
agents — that tutorials are content managed in the dashboard rather than
|
|
9
|
+
created from migrations, the key format, the request-shaped config lambdas,
|
|
10
|
+
that the engine appends provider hosts to the app's `frame-src`, and the
|
|
11
|
+
`product_tours.unresolved_trigger` notification that turns "my button does
|
|
12
|
+
nothing" into a log line. It ships inside the gem, so
|
|
13
|
+
`cat "$(bundle show product_tours)/AGENTS.md"` works from a host app.
|
|
14
|
+
- The dummy app pins `queue_adapter = :test` for the test suite. Attaching a
|
|
15
|
+
video enqueues Active Storage's analysis job, and the default `:async` adapter
|
|
16
|
+
runs it on a background thread with its own database connection — writes no
|
|
17
|
+
test transaction covers, which is how a suite starts failing order-dependently
|
|
18
|
+
in a test that never created a row. No effect on the gem itself.
|
|
19
|
+
|
|
5
20
|
## [0.1.1] - 2026-08-04
|
|
6
21
|
|
|
7
22
|
- Reworked the README into an installation-first, skimmable product guide that
|
data/README.md
CHANGED
|
@@ -54,6 +54,11 @@ small set of working tutorials so you can try the modal immediately.
|
|
|
54
54
|
Ruby >= 3.2 · Rails >= 7.1 · Active Storage only for uploaded videos · Action
|
|
55
55
|
Text only for rich descriptions.
|
|
56
56
|
|
|
57
|
+
Installing with a coding agent? Point it at [AGENTS.md](AGENTS.md) — the same
|
|
58
|
+
steps in the order an agent needs them, plus the gates it tends to get wrong and
|
|
59
|
+
the things it should not do. It ships inside the gem, so
|
|
60
|
+
`cat "$(bundle show product_tours)/AGENTS.md"` works from any app that bundles it.
|
|
61
|
+
|
|
57
62
|
## What you get
|
|
58
63
|
|
|
59
64
|
| | |
|
data/lib/product_tours/widget.rb
CHANGED
|
@@ -16,7 +16,11 @@ module ProductTours
|
|
|
16
16
|
def dashboard_stylesheet = @dashboard_stylesheet ||= File.read(DASHBOARD_STYLESHEET_SOURCE)
|
|
17
17
|
def fingerprint = @fingerprint ||= Digest::MD5.hexdigest(javascript)
|
|
18
18
|
def dashboard_fingerprint = @dashboard_fingerprint ||= Digest::MD5.hexdigest(dashboard_javascript)
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
# Not an endless def like its neighbours: the one-liner is 126 characters.
|
|
21
|
+
def dashboard_stylesheet_fingerprint
|
|
22
|
+
@dashboard_stylesheet_fingerprint ||= Digest::MD5.hexdigest(dashboard_stylesheet)
|
|
23
|
+
end
|
|
20
24
|
|
|
21
25
|
def snippet(locale:, nonce: nil)
|
|
22
26
|
nonce_attr = nonce ? %( nonce="#{ERB::Util.html_escape(nonce)}") : ''
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: product_tours
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yaroslav Shmarov
|
|
@@ -35,6 +35,7 @@ executables: []
|
|
|
35
35
|
extensions: []
|
|
36
36
|
extra_rdoc_files: []
|
|
37
37
|
files:
|
|
38
|
+
- AGENTS.md
|
|
38
39
|
- CHANGELOG.md
|
|
39
40
|
- MIT-LICENSE
|
|
40
41
|
- README.md
|