rails_tool_views 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/CHANGELOG.md +9 -0
- data/README.md +14 -70
- data/app/controllers/rails_tool_views/surfaces_controller.rb +24 -4
- data/app/helpers/rails_tool_views/surfaces_helper.rb +1 -0
- data/app/views/layouts/rails_tool_views/application.html.erb +24 -0
- data/app/views/rails_tool_views/surfaces/page.html.erb +9 -0
- data/lib/generators/rails_tool_views/component/component_generator.rb +47 -0
- data/lib/generators/rails_tool_views/component/templates/component_test.rb +15 -0
- data/lib/generators/rails_tool_views/component/templates/partial.html.erb +6 -0
- data/lib/generators/rails_tool_views/component/templates/registration.rb +24 -0
- data/lib/generators/rails_tool_views/install/templates/rails_tool_views.rb +2 -1
- data/lib/rails_tool_views/version.rb +1 -1
- metadata +7 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f8d13afb04c0aa3830428d6bf43ad18936b5e5f676bdf80b8bed717fdb5dc5aa
|
|
4
|
+
data.tar.gz: 39be934d3e43b6f7380f89ce42faf3b67ea49f93eebec65fc551dbc3d944fbc4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b7b9b32baaf39558ba998750dd4a181f0be83594ba71a8e21c5407b784960249f17ec8f9d551ea3e863751abd8032f12b7a548a0d447f26bffe4538a0a3b3d43
|
|
7
|
+
data.tar.gz: 2f53bf0cd980e42ee9175115b64b908face277ae907efaafbf7c21a15b70f4c97476dd45093f8d32220041567308f1f6b90c7385d60d268cc0d1e6bf8041e865
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.0] - 2026-10-18
|
|
4
|
+
|
|
5
|
+
- Add `rails_tool_views:component NAME` for a Partial, closed registration schemas and a Minitest scaffold. Component and action policies deny by default. Existing paths, unsafe names and symlink escapes are refused before writing.
|
|
6
|
+
- Render complete Engine HTML read/error pages with accessible document structure, authorized correction fields and a saved-view reload link. Embedded helpers and JSON/Turbo retain their formats.
|
|
7
|
+
- Fix redirects after correcting a non-Turbo error when the referrer is a POST-only Engine route.
|
|
8
|
+
- Add real Chrome E2E tests, including JavaScript-disabled mobile correction, fixture screenshots and a browser CI job. Keep browser dependencies in a development-only bundle.
|
|
9
|
+
- Exercise the installed gem and generated scaffold in a temporary Rails host, both with developer dependencies and an isolated network-resolved GEM_HOME.
|
|
10
|
+
- No database migration or new runtime dependency.
|
|
11
|
+
|
|
3
12
|
## [0.1.0] - 2026-10-18
|
|
4
13
|
|
|
5
14
|
First public release. Earlier version labels below describe unpublished development milestones.
|
data/README.md
CHANGED
|
@@ -1,90 +1,34 @@
|
|
|
1
1
|
# RailsToolViews
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Turn trusted Rails Partials and ViewComponents into persistent, interactive tools. Your Rails application owns authentication, permissions and business data. RubyLLM integration is optional.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[Documentation](https://rails-tool-views.wangyaodi.com) · [Getting started](https://rails-tool-views.wangyaodi.com/getting-started/) · [API](https://rails-tool-views.wangyaodi.com/api/) · [Roadmap](ROADMAP.md)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Version **0.1.0** is the first public release.
|
|
12
|
-
|
|
13
|
-
## Try the workbench
|
|
14
|
-
|
|
15
|
-
Requires Ruby 3.3+ and Bundler. From this checkout:
|
|
16
|
-
|
|
17
|
-
```sh
|
|
18
|
-
bundle install
|
|
19
|
-
bin/demo
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Open **http://127.0.0.1:3100**. Stop with `Ctrl-C` when finished.
|
|
23
|
-
|
|
24
|
-
| Workflow | What to try |
|
|
25
|
-
| --- | --- |
|
|
26
|
-
| Component playground | Present a Partial, chat card or ViewComponent. Save a choice and refresh to restore it. |
|
|
27
|
-
| Customer intake | Submit an invalid email, correct it and create a customer with field-level feedback. |
|
|
28
|
-
| Support workspace | Find a ticket, inspect its account, review a draft reply and confirm the local outbox. |
|
|
29
|
-
| Content review | Edit, regenerate, accept a version and download its text export. |
|
|
30
|
-
|
|
31
|
-
Switch synthetic identities to explore two tenants and two roles. Fixtures run locally, with no provider calls or external messages. The identity switch is a testing aid, not production authentication. See the [demo walkthrough](docs/site/_getting_started/demo.md) for test scenarios and continuation failure/retry.
|
|
32
|
-
|
|
33
|
-
## Add it to a Rails application
|
|
34
|
-
|
|
35
|
-
Add the gem:
|
|
36
|
-
|
|
37
|
-
```ruby
|
|
38
|
-
# Gemfile
|
|
39
|
-
gem "rails_tool_views", "~> 0.1.0"
|
|
40
|
-
```
|
|
9
|
+
Requires Ruby 3.3 or later and a patched Rails release.
|
|
41
10
|
|
|
42
11
|
```sh
|
|
43
|
-
bundle
|
|
12
|
+
bundle add rails_tool_views
|
|
44
13
|
bin/rails generate rails_tool_views:install
|
|
45
14
|
bin/rails db:migrate
|
|
46
15
|
```
|
|
47
16
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
```ruby
|
|
51
|
-
scope = RailsToolViews::Scope.new(actor: current_user.id.to_s, tenant: current_account.id.to_s)
|
|
52
|
-
surface = RailsToolViews.present(:choice_card, props: approved_props, scope: scope)
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
```erb
|
|
56
|
-
<%= rails_tool_views_surface(surface, scope: scope) %>
|
|
57
|
-
```
|
|
17
|
+
Continue with [Getting Started](https://rails-tool-views.wangyaodi.com/getting-started/) to configure authenticated scope and register your first component. Component and action policies deny access until you configure them.
|
|
58
18
|
|
|
59
|
-
|
|
19
|
+
## Try the demo
|
|
60
20
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
Read the [searchable guides](https://rails-tool-views.wangyaodi.com). Preview locally with `docs/bin/serve.sh`; setup and build instructions are in [docs/README.md](docs/README.md).
|
|
64
|
-
|
|
65
|
-
- [Getting Started](docs/site/_getting_started/getting-started.md): installation and a working first component.
|
|
66
|
-
- [Configuration](docs/site/_getting_started/configuration.md): host identity and engine settings.
|
|
67
|
-
- [Core guides](docs/site/_core_features): components, surfaces, actions and validation.
|
|
68
|
-
- [Advanced guides](docs/site/_advanced): optional RubyLLM, continuation and production boundaries.
|
|
69
|
-
- [API reference](docs/site/_reference/api-reference.md): generated Ruby API documentation.
|
|
70
|
-
- [Upgrading](docs/site/_reference/upgrading.md): moving an unpublished development host to the first public version.
|
|
71
|
-
|
|
72
|
-
The dummy host in [`test/dummy`](test/dummy) contains the complete runnable examples and is excluded from the gem runtime. OddlyDock is a planned reference host, not a dependency.
|
|
73
|
-
|
|
74
|
-
## Development
|
|
21
|
+
From this checkout:
|
|
75
22
|
|
|
76
23
|
```sh
|
|
77
|
-
bundle
|
|
78
|
-
|
|
79
|
-
# Optional adapter tests:
|
|
80
|
-
BUNDLE_GEMFILE=gemfiles/adapter.gemfile bundle install
|
|
81
|
-
BUNDLE_GEMFILE=gemfiles/adapter.gemfile bundle exec rake test:adapter
|
|
24
|
+
bundle install
|
|
25
|
+
bin/demo
|
|
82
26
|
```
|
|
83
27
|
|
|
84
|
-
|
|
28
|
+
Open http://127.0.0.1:3100 and stop with Ctrl-C. The demo covers choices, customer forms, support and content review using offline fixtures. See the [walkthrough](https://rails-tool-views.wangyaodi.com/demo/).
|
|
85
29
|
|
|
86
|
-
##
|
|
30
|
+
## Contribute
|
|
87
31
|
|
|
88
|
-
|
|
32
|
+
Read [Contributing](CONTRIBUTING.md) for development and documentation commands. Report vulnerabilities through the [private security channel](SECURITY.md).
|
|
89
33
|
|
|
90
|
-
RailsToolViews is an unofficial community project. Rails marks belong to David Heinemeier Hansson
|
|
34
|
+
Released under the [MIT license](LICENSE.txt). RailsToolViews is an unofficial community project, without affiliation or endorsement. Rails marks belong to David Heinemeier Hansson and are exclusively licensed to the Rails Foundation; see the [trademark policy](https://rubyonrails.org/trademarks).
|
|
@@ -23,7 +23,7 @@ module RailsToolViews
|
|
|
23
23
|
surface = RailsToolViews.restore(params[:id], scope: current_scope)
|
|
24
24
|
respond_to do |format|
|
|
25
25
|
format.json { render json: surface.snapshot }
|
|
26
|
-
format.html {
|
|
26
|
+
format.html { render_surface_page(surface) }
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
@@ -88,9 +88,29 @@ module RailsToolViews
|
|
|
88
88
|
format.turbo_stream { render turbo_stream: turbo_stream.replace(surface.dom_id, RailsToolViews.render(surface, view_context: view_context, scope: current_scope)), status: status }
|
|
89
89
|
# Without Turbo, return to the page that embeds the Surface; it re-renders saved state.
|
|
90
90
|
# The Engine's own helper keeps whatever mount path and name the host chose.
|
|
91
|
-
format.html {
|
|
91
|
+
format.html { redirect_after_action(surface) }
|
|
92
92
|
end
|
|
93
93
|
end
|
|
94
|
+
def redirect_after_action(surface)
|
|
95
|
+
# After correcting a full-page error, Referer can be a POST-only Engine
|
|
96
|
+
# route. Redirect to the readable Surface instead of GET /actions (404).
|
|
97
|
+
referrer_path = begin
|
|
98
|
+
URI.parse(request.referer.to_s).path.to_s
|
|
99
|
+
rescue URI::InvalidURIError
|
|
100
|
+
""
|
|
101
|
+
end
|
|
102
|
+
if referrer_path.start_with?("#{surface_path(surface)}/")
|
|
103
|
+
redirect_to surface_path(surface), status: :see_other
|
|
104
|
+
else
|
|
105
|
+
redirect_back_or_to surface_path(surface), allow_other_host: false, status: :see_other
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
def render_surface_page(surface, error: nil)
|
|
109
|
+
html = surface && RailsToolViews.render(surface, view_context: view_context, scope: current_scope, error: error)
|
|
110
|
+
render template: "rails_tool_views/surfaces/page", layout: "rails_tool_views/application",
|
|
111
|
+
locals: { surface_html: html, reload_path: surface && surface_path(surface), error: error },
|
|
112
|
+
status: error ? error.status : :ok
|
|
113
|
+
end
|
|
94
114
|
def reject_request(error)
|
|
95
115
|
respond_to do |format|
|
|
96
116
|
format.json { render json: error.to_h, status: error.status }
|
|
@@ -107,9 +127,9 @@ module RailsToolViews
|
|
|
107
127
|
format.html do
|
|
108
128
|
begin
|
|
109
129
|
surface = RailsToolViews.restore(params[:id], scope: current_scope)
|
|
110
|
-
|
|
130
|
+
render_surface_page(surface, error: error)
|
|
111
131
|
rescue RailsToolViews::Error
|
|
112
|
-
|
|
132
|
+
render_surface_page(nil, error: error)
|
|
113
133
|
end
|
|
114
134
|
end
|
|
115
135
|
end
|
|
@@ -4,6 +4,7 @@ module RailsToolViews
|
|
|
4
4
|
module SurfacesHelper
|
|
5
5
|
# Engine-owned copy. Translate or reword any of it under rails_tool_views.surface.<key>.
|
|
6
6
|
TEXT = {
|
|
7
|
+
page_title: "Interactive view", page_error_title: "Unable to complete this request", reload: "Reload saved view",
|
|
7
8
|
ready: "View ready.", saved: "Changes saved.", revision: "Saved revision %{revision}",
|
|
8
9
|
saving: "Saving changes…", save_failed: "Changes could not be saved. Review the message and try again.",
|
|
9
10
|
agent_pending: "AI follow-up pending.", agent_completed: "AI follow-up completed.",
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="<%= I18n.locale %>">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title><%= rails_tool_views_text(error ? :page_error_title : :page_title) %></title>
|
|
7
|
+
<%= csrf_meta_tags %>
|
|
8
|
+
<style>
|
|
9
|
+
.rails-tool-views-page { box-sizing: border-box; max-width: 48rem; margin: 2rem auto; padding: 0 1rem; font: 1rem/1.6 system-ui, sans-serif; overflow-wrap: anywhere; }
|
|
10
|
+
.rails-tool-views-page * { box-sizing: border-box; }
|
|
11
|
+
.rails-tool-views-page input, .rails-tool-views-page textarea, .rails-tool-views-page select { max-width: 100%; font: inherit; }
|
|
12
|
+
.rails-tool-views-page label { display: block; }
|
|
13
|
+
.rails-tool-views-page fieldset { min-width: 0; }
|
|
14
|
+
.rails-tool-views-page button, .rails-tool-views-page input[type=submit] { padding: .5rem 1rem; font: inherit; cursor: pointer; }
|
|
15
|
+
.rails-tool-views-page [role=alert], .rails-tool-views-page [aria-invalid=true] { color: #a51d1d; }
|
|
16
|
+
.rails-tool-views-page :focus-visible { outline: 3px solid #215dc4; outline-offset: 3px; }
|
|
17
|
+
</style>
|
|
18
|
+
</head>
|
|
19
|
+
<body class="rails-tool-views-page">
|
|
20
|
+
<main aria-labelledby="rails-tool-views-page-title">
|
|
21
|
+
<%= yield %>
|
|
22
|
+
</main>
|
|
23
|
+
</body>
|
|
24
|
+
</html>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<h1 id="rails-tool-views-page-title"><%= rails_tool_views_text(error ? :page_error_title : :page_title) %></h1>
|
|
2
|
+
<% if surface_html %>
|
|
3
|
+
<%= surface_html %>
|
|
4
|
+
<% elsif error %>
|
|
5
|
+
<%= render partial: "rails_tool_views/surfaces/error", locals: { error: error } %>
|
|
6
|
+
<% end %>
|
|
7
|
+
<% if error && reload_path %>
|
|
8
|
+
<p><%= link_to rails_tool_views_text(:reload), reload_path %></p>
|
|
9
|
+
<% end %>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require "rails/generators"
|
|
3
|
+
|
|
4
|
+
module RailsToolViews
|
|
5
|
+
module Generators
|
|
6
|
+
# Generates a trusted Partial definition with closed schemas and denied policies.
|
|
7
|
+
class ComponentGenerator < Rails::Generators::Base
|
|
8
|
+
source_root File.expand_path("templates", __dir__)
|
|
9
|
+
argument :name, type: :string, required: true, desc: "Flat snake_case component key"
|
|
10
|
+
desc "Generate a Partial, registration and Minitest scaffold. Policies deny access until configured."
|
|
11
|
+
|
|
12
|
+
# Preflights all destinations, then writes the registration, Partial and test.
|
|
13
|
+
def create_component
|
|
14
|
+
unless name.match?(/\A[a-z][a-z0-9_]{0,63}\z/)
|
|
15
|
+
raise Thor::Error, "Use a flat snake_case name of 1 to 64 characters, starting with a letter."
|
|
16
|
+
end
|
|
17
|
+
outputs = {
|
|
18
|
+
"registration.rb" => "config/rails_tool_views/components/#{name}.rb",
|
|
19
|
+
"partial.html.erb" => "app/views/rails_tool_views/components/_#{name}.html.erb",
|
|
20
|
+
"component_test.rb" => "test/rails_tool_views/components/#{name}_test.rb"
|
|
21
|
+
}
|
|
22
|
+
# Preflight every output before writing any file. Even --force must not
|
|
23
|
+
# destroy host code or follow a symlink outside the destination root.
|
|
24
|
+
root = File.realpath(destination_root)
|
|
25
|
+
outputs.each_value do |relative|
|
|
26
|
+
path = File.join(root, relative)
|
|
27
|
+
if File.exist?(path) || File.symlink?(path)
|
|
28
|
+
raise Thor::Error, "Destination exists: #{relative}. Resolve the conflict before generating."
|
|
29
|
+
end
|
|
30
|
+
parent = File.dirname(path)
|
|
31
|
+
parent = File.dirname(parent) until File.exist?(parent) || File.symlink?(parent)
|
|
32
|
+
begin
|
|
33
|
+
real = File.realpath(parent)
|
|
34
|
+
rescue Errno::ENOENT, Errno::ELOOP
|
|
35
|
+
raise Thor::Error, "Invalid destination parent: #{relative}"
|
|
36
|
+
end
|
|
37
|
+
unless File.directory?(real) && (real == root || real.start_with?(root + File::SEPARATOR))
|
|
38
|
+
raise Thor::Error, "Destination escapes the application: #{relative}"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
outputs.each { |source, target| template(source, target) }
|
|
42
|
+
say "Load config/rails_tool_views/components/*.rb inside your shared to_prepare block after reset_registry!."
|
|
43
|
+
say "Replace BOTH denied policies with host authorization before presenting this component."
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require "test_helper"
|
|
3
|
+
|
|
4
|
+
class <%= name.camelize %>ComponentTest < ActiveSupport::TestCase
|
|
5
|
+
test "<%= name %> denies presentation until host policies are configured" do
|
|
6
|
+
error = assert_raises(RailsToolViews::Error) do
|
|
7
|
+
RailsToolViews.present(:<%= name %>, props: { title: "Review" },
|
|
8
|
+
scope: RailsToolViews::Scope.new(actor: "test-user", tenant: "test-tenant"))
|
|
9
|
+
end
|
|
10
|
+
assert_equal "NOT_ALLOWED", error.code
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Replace the denial test when you configure host policies. Add an allowed
|
|
14
|
+
# actor/tenant, a denied actor/tenant, action validation and persisted-state tests.
|
|
15
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Load from the host's shared to_prepare block. Do not reset the registry here.
|
|
3
|
+
RailsToolViews.register(:<%= name %>,
|
|
4
|
+
description: "<%= name.humanize %>",
|
|
5
|
+
partial: "rails_tool_views/components/<%= name %>",
|
|
6
|
+
schema: {
|
|
7
|
+
type: "object", additionalProperties: false, required: ["title"],
|
|
8
|
+
properties: { title: { type: "string", maxLength: 120 } }
|
|
9
|
+
},
|
|
10
|
+
# Replace with host authorization using access.actor and access.tenant.
|
|
11
|
+
policy: ->(_access) { false },
|
|
12
|
+
actions: {
|
|
13
|
+
set_value: {
|
|
14
|
+
schema: {
|
|
15
|
+
type: "object", additionalProperties: false, required: ["value"],
|
|
16
|
+
properties: { value: { type: "string", maxLength: 120 } }
|
|
17
|
+
},
|
|
18
|
+
# Recheck host authorization and trusted allowed values on every action.
|
|
19
|
+
policy: ->(_access) { false },
|
|
20
|
+
handler: ->(access) {
|
|
21
|
+
RailsToolViews::Transition.new(state: { value: access.arguments.fetch("value") })
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
})
|
|
@@ -9,4 +9,5 @@ RailsToolViews.configure do |config|
|
|
|
9
9
|
# config.parent_controller = "::ApplicationController"
|
|
10
10
|
end
|
|
11
11
|
# Register trusted components and explicit policies in Rails.application.config.to_prepare.
|
|
12
|
-
#
|
|
12
|
+
# Generate a safe scaffold: bin/rails generate rails_tool_views:component review_card
|
|
13
|
+
# See https://rails-tool-views.wangyaodi.com/component-generator/ for registration and policies.
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails_tool_views
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andy Wang
|
|
@@ -178,10 +178,16 @@ files:
|
|
|
178
178
|
- app/models/rails_tool_views/presentation.rb
|
|
179
179
|
- app/models/rails_tool_views/redacted_json.rb
|
|
180
180
|
- app/models/rails_tool_views/surface.rb
|
|
181
|
+
- app/views/layouts/rails_tool_views/application.html.erb
|
|
181
182
|
- app/views/rails_tool_views/surfaces/_error.html.erb
|
|
182
183
|
- app/views/rails_tool_views/surfaces/_surface.html.erb
|
|
184
|
+
- app/views/rails_tool_views/surfaces/page.html.erb
|
|
183
185
|
- config/routes.rb
|
|
184
186
|
- db/migrate/20261010000000_create_rails_tool_views.rb
|
|
187
|
+
- lib/generators/rails_tool_views/component/component_generator.rb
|
|
188
|
+
- lib/generators/rails_tool_views/component/templates/component_test.rb
|
|
189
|
+
- lib/generators/rails_tool_views/component/templates/partial.html.erb
|
|
190
|
+
- lib/generators/rails_tool_views/component/templates/registration.rb
|
|
185
191
|
- lib/generators/rails_tool_views/install/install_generator.rb
|
|
186
192
|
- lib/generators/rails_tool_views/install/templates/create_rails_tool_views.rb
|
|
187
193
|
- lib/generators/rails_tool_views/install/templates/rails_tool_views.rb
|