tuix_rails 0.1.0 → 0.2.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 +4 -4
- data/README.md +26 -14
- data/lib/tuix_rails/helper.rb +29 -0
- data/lib/tuix_rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7709c6ce025779c0fdc7f6a31f535b5d7f816b649fb9472ec7c3358d4a2b44f5
|
|
4
|
+
data.tar.gz: 7a5b77dd9c370ea6531fa1842e45066c9a68f7499a21ddd230a901c56ffb4f3c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10baca16212eebd66168e79e61657c44e8f3f0eab8581fcb398832a1a8d909278a946ac196ae03d633843690437323e415f8e4f3760de8bb5eeacf0c604331d8
|
|
7
|
+
data.tar.gz: e091941eeae31eb0edef34848a6ca94d71bc5885095f2ff0dcc08b52409c4da69345d90c181cb1a302b2e0e18c13bd47c5fe3f0914cf16129d89552338176fe4
|
data/README.md
CHANGED
|
@@ -5,26 +5,20 @@ widget delivery, CSP nonces and Turbo navigation. Requires Ruby 3.2+ and Rails
|
|
|
5
5
|
7.2–8.x (Rails itself may require a newer Ruby). No database, npm installation,
|
|
6
6
|
asset precompile or separate Tuix login is needed by the host application.
|
|
7
7
|
|
|
8
|
-
MIT licensed
|
|
9
|
-
repository or from a built gem, as below.
|
|
8
|
+
MIT licensed, on [RubyGems](https://rubygems.org/gems/tuix_rails).
|
|
10
9
|
|
|
11
10
|
## Install
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
repository or an unpacked gem artifact:
|
|
15
|
-
|
|
16
|
-
```ruby
|
|
17
|
-
gem "tuix_rails", path: "/absolute/path/to/tuix/packages/rails"
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
For the built artifact, run `gem unpack output/releases/tuix_rails-0.1.0.gem`
|
|
21
|
-
and point `path:` at the resulting `tuix_rails-0.1.0` directory.
|
|
12
|
+
In the host application:
|
|
22
13
|
|
|
23
14
|
```sh
|
|
24
|
-
bundle
|
|
15
|
+
bundle add tuix_rails
|
|
25
16
|
bin/rails generate tuix:install
|
|
26
17
|
```
|
|
27
18
|
|
|
19
|
+
To try a change before its release, use `gem "tuix_rails", path: "/absolute/path/to/packages/rails"`
|
|
20
|
+
in the Gemfile instead.
|
|
21
|
+
|
|
28
22
|
The generator creates `config/initializers/tuix.rb`. It prints the layout steps
|
|
29
23
|
instead of guessing your authentication library or rewriting custom layouts.
|
|
30
24
|
Re-running it uses Rails' normal file conflict handling; `--skip` preserves a
|
|
@@ -95,6 +89,19 @@ shared full-page cache. Browser back/forward cache follows the host's existing
|
|
|
95
89
|
session policy; the bridge destroys the widget on `pagehide` and re-reads the
|
|
96
90
|
current page on `pageshow`. See the [Turbo lifecycle documentation](https://turbo.hotwired.dev/handbook/building).
|
|
97
91
|
|
|
92
|
+
## Component names
|
|
93
|
+
|
|
94
|
+
`tuix_component` writes the `data-tuix-component` attribute the widget reads, so a report says which view or partial it is about. Put it on the root element of a partial or layout, in either ERB form:
|
|
95
|
+
|
|
96
|
+
```erb
|
|
97
|
+
<%= tag.form class: "f", **tuix_component do %> ... <% end %>
|
|
98
|
+
<form class="f" <%= tag.attributes(tuix_component) %>> ... </form>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
It returns `{ data: { tuix_component: "orders/_form" } }`. Without an argument the name is the virtual path of the template being rendered (`orders/_form`, `layouts/application`); it is right inside nested partials and collections, and back in the parent after a partial returns. Pass a name to choose your own: `tuix_component("Checkout.Button")`. In a ViewComponent call `helpers.tuix_component(self.class.name)`, since the helper cannot see a component's own template. A block you write in one template and render inside a layout partial (`render layout: "box" do ... end`) runs while that partial is current, so give elements in it an explicit name.
|
|
102
|
+
|
|
103
|
+
A name the widget would ignore (it must start with a letter or underscore, continue with letters, digits and `_ . : / -`, and have at most 100 characters), or no name at all (an inline template has no virtual path), gives `{}`: no attribute is rendered and nothing raises.
|
|
104
|
+
|
|
98
105
|
## Content security policy
|
|
99
106
|
|
|
100
107
|
Helpers use Rails' `content_security_policy_nonce` by default; an explicit
|
|
@@ -110,7 +117,7 @@ previews need `blob:` and `data:`. Capture requires `style-src-attr 'unsafe-inli
|
|
|
110
117
|
and the empty stylesheet hash
|
|
111
118
|
`'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='` in the applicable style
|
|
112
119
|
directive. Account for `script-src-elem`/`style-src-elem` when present. Test capture
|
|
113
|
-
against the real host policy; Tuix → Project settings →
|
|
120
|
+
against the real host policy; Tuix → Project settings → Installation → Content
|
|
114
121
|
Security Policy lists the exact sources for your project.
|
|
115
122
|
|
|
116
123
|
## Development
|
|
@@ -130,7 +137,7 @@ npm run test:browser -w @tuix/rails
|
|
|
130
137
|
CI covers Rails 7.2/Ruby 3.2, Rails 8.0/Ruby 3.3 and Rails 8.1/Ruby 3.4.
|
|
131
138
|
Integration tests boot a real Rails application, render helpers, fetch the asset
|
|
132
139
|
through middleware, check identity signing/escaping, and exercise the generator.
|
|
133
|
-
The package command builds `output/releases/tuix_rails-0.
|
|
140
|
+
The package command builds `output/releases/tuix_rails-0.2.0.gem`, verifies its
|
|
134
141
|
contents and reruns integration tests against a temporary gem installation before copying
|
|
135
142
|
the artifact into place. It never publishes. CI uploads the same local artifact, and the
|
|
136
143
|
release workflow publishes that artifact.
|
|
@@ -149,3 +156,8 @@ its remote run is separate from these local results.
|
|
|
149
156
|
|
|
150
157
|
Before rolling out to your users, try report creation, screenshots and notifications
|
|
151
158
|
against a real Tuix project using the host's authentication, origin and CSP.
|
|
159
|
+
|
|
160
|
+
## Version history
|
|
161
|
+
|
|
162
|
+
- **0.2.0**: adds the view helper `tuix_component` (see Component names), which writes the `data-tuix-component` attribute, so a report says which view or partial it is about. Nothing changes until you call it.
|
|
163
|
+
- **0.1.0**: the first release.
|
data/lib/tuix_rails/helper.rb
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
require_relative "assets"
|
|
2
2
|
|
|
3
3
|
module TuixRails
|
|
4
|
+
# A component name the widget accepts (`data-tuix-component`).
|
|
5
|
+
COMPONENT_NAME = /\A[A-Za-z_][A-Za-z0-9_.:\/-]{0,99}\z/
|
|
6
|
+
|
|
4
7
|
module Helper
|
|
5
8
|
def tuix_assets(nonce: content_security_policy_nonce)
|
|
6
9
|
path = "#{request.script_name}#{Assets::PATH}"
|
|
@@ -14,5 +17,31 @@ module TuixRails
|
|
|
14
17
|
content_tag(:div, "", id: "tuix-rails", hidden: true,
|
|
15
18
|
data: { tuix_rails: payload && JSON.generate(payload), turbo_temporary: true })
|
|
16
19
|
end
|
|
20
|
+
|
|
21
|
+
# Names the component a feedback report is about. Returns a hash for tag
|
|
22
|
+
# helpers (`tag.form **tuix_component`, `tag.attributes(tuix_component)`):
|
|
23
|
+
# `{ data: { tuix_component: "orders/_form" } }`. Without an argument the name
|
|
24
|
+
# is the virtual path of the template being rendered (`orders/_form`,
|
|
25
|
+
# `layouts/application`); pass a String for any other
|
|
26
|
+
# explicit name. In a ViewComponent call `helpers.tuix_component(self.class.name)`.
|
|
27
|
+
#
|
|
28
|
+
# Returns `{}` (renders no attribute) when there is no name or the widget
|
|
29
|
+
# would ignore it. It never raises in a view.
|
|
30
|
+
def tuix_component(name = nil)
|
|
31
|
+
name = name.nil? ? tuix_template_path : name
|
|
32
|
+
name = name.to_s if name.is_a?(Symbol)
|
|
33
|
+
return {} unless name.is_a?(String) && name.valid_encoding? && name.match?(TuixRails::COMPONENT_NAME)
|
|
34
|
+
{ data: { tuix_component: name } }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
# `@virtual_path` is the template Action View is rendering right now: each
|
|
40
|
+
# compiled template sets it on entry and `ActionView::Base#_run` restores the
|
|
41
|
+
# caller's value on exit, so it is right inside nested partials and after
|
|
42
|
+
# they return. It is the same ivar Rails' own `t(".key")` lookup reads.
|
|
43
|
+
def tuix_template_path
|
|
44
|
+
@virtual_path
|
|
45
|
+
end
|
|
17
46
|
end
|
|
18
47
|
end
|
data/lib/tuix_rails/version.rb
CHANGED