-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphlex.rb
More file actions
45 lines (39 loc) · 1.29 KB
/
phlex.rb
File metadata and controls
45 lines (39 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true
gem "phlex-rails"
after_bundle do
generate "phlex:install"
inject_into_file "app/components/base.rb", after: "class Components::Base < Phlex::HTML\n" do
<<~HELPERS
register_value_helper :admin_tool
register_value_helper :current_user
HELPERS
end
inside "app/components" do
file "inspector.rb", <<~INSPECTOR
# frozen_string_literal: true
class Components::Inspector < Components::Base
def initialize(object:)
@object = object
end
def view_template
admin_tool do
details class: "inspector" do
summary { record_id }
pre class: "inspector-content" do
unless @object.nil?
raw safe(ap @object)
else
plain "nil"
end
end
end
end
end
private
def record_id
"\#{@object.class.name} \#{@object&.try(:public_id) || @object&.id}"
end
end
INSPECTOR
end
end