Skip to content

Commit f903f4e

Browse files
committed
Get ViewComponent working in Superview
1 parent 8cbbdfb commit f903f4e

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

Gemfile.lock

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,24 @@ PATH
88
GEM
99
remote: https://rubygems.org/
1010
specs:
11-
actionpack (8.0.1)
12-
actionview (= 8.0.1)
13-
activesupport (= 8.0.1)
11+
actionpack (7.2.2.1)
12+
actionview (= 7.2.2.1)
13+
activesupport (= 7.2.2.1)
1414
nokogiri (>= 1.8.5)
15-
rack (>= 2.2.4)
15+
racc
16+
rack (>= 2.2.4, < 3.2)
1617
rack-session (>= 1.0.1)
1718
rack-test (>= 0.6.3)
1819
rails-dom-testing (~> 2.2)
1920
rails-html-sanitizer (~> 1.6)
2021
useragent (~> 0.16)
21-
actionview (8.0.1)
22-
activesupport (= 8.0.1)
22+
actionview (7.2.2.1)
23+
activesupport (= 7.2.2.1)
2324
builder (~> 3.1)
2425
erubi (~> 1.11)
2526
rails-dom-testing (~> 2.2)
2627
rails-html-sanitizer (~> 1.6)
27-
activesupport (8.0.1)
28+
activesupport (7.2.2.1)
2829
base64
2930
benchmark (>= 0.3)
3031
bigdecimal
@@ -36,7 +37,6 @@ GEM
3637
minitest (>= 5.1)
3738
securerandom (>= 0.3)
3839
tzinfo (~> 2.0, >= 2.0.5)
39-
uri (>= 0.13.1)
4040
base64 (0.2.0)
4141
benchmark (0.4.0)
4242
bigdecimal (3.1.8)
@@ -58,6 +58,7 @@ GEM
5858
loofah (2.23.1)
5959
crass (~> 1.0.2)
6060
nokogiri (>= 1.12.0)
61+
method_source (1.1.0)
6162
minitest (5.25.4)
6263
nokogiri (1.17.2-arm64-darwin)
6364
racc (~> 1.4)
@@ -85,9 +86,9 @@ GEM
8586
rails-html-sanitizer (1.6.2)
8687
loofah (~> 2.21)
8788
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
88-
railties (8.0.1)
89-
actionpack (= 8.0.1)
90-
activesupport (= 8.0.1)
89+
railties (7.2.2.1)
90+
actionpack (= 7.2.2.1)
91+
activesupport (= 7.2.2.1)
9192
irb (~> 1.13)
9293
rackup (>= 1.0.0)
9394
rake (>= 12.2)
@@ -120,8 +121,11 @@ GEM
120121
thor (1.3.2)
121122
tzinfo (2.0.6)
122123
concurrent-ruby (~> 1.0)
123-
uri (1.0.2)
124124
useragent (0.16.11)
125+
view_component (3.0.0)
126+
activesupport (>= 5.2.0, < 8.0)
127+
concurrent-ruby (~> 1.0)
128+
method_source (~> 1.0)
125129
zeitwerk (2.7.1)
126130

127131
PLATFORMS
@@ -134,6 +138,7 @@ DEPENDENCIES
134138
rake (~> 13.0)
135139
rspec-rails (~> 7.0)
136140
superview!
141+
view_component (~> 3.0.0)
137142

138143
BUNDLED WITH
139144
2.4.8

spec/rails_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require "rspec/rails"
44
require "spec_helper"
55
require "phlex-rails"
6+
require "view_component"
67

78
# Configure a minimal application for ActionController
89
class TestApplication < Rails::Application

spec/superview_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ def view_template
2121
end
2222
end
2323

24+
class Edit < ViewComponent::Base
25+
attr_writer :post
26+
27+
def call
28+
<<~HTML
29+
h1 { "Edit #{@post.title}" }
30+
div(class: "prose") { "#{@post.body}" }
31+
HTML
32+
end
33+
end
34+
2435
def new
2536
render inline: "Don't hit new"
2637
end
@@ -54,6 +65,7 @@ def load_post
5465
Rails.application.routes.draw do
5566
get "posts/show", to: "posts#show"
5667
get "posts/new", to: "posts#new"
68+
get "posts/edit", to: "posts#edit"
5769
get "posts/a_class", to: "posts#a_class"
5870
get "posts/an_instance", to: "posts#an_instance"
5971
get "posts/a_string", to: "posts#a_string"
@@ -88,6 +100,14 @@ def load_post
88100
end
89101
end
90102

103+
describe "GET #edit" do
104+
it "renders the Phlex view for the action" do
105+
get :edit
106+
expect(response.body).to include("Edit Test Post")
107+
expect(response.body).to include("This is a test body.")
108+
end
109+
end
110+
91111
describe "GET #an_instance" do
92112
it "renders the Phlex view for the action" do
93113
get :an_instance

superview.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ Gem::Specification.new do |spec|
3737

3838
# For more information and examples about making a new gem, check out our
3939
# guide at: https://bundler.io/guides/creating_gem.html
40+
spec.add_development_dependency "view_component", "~> 3.0.0"
4041
end

0 commit comments

Comments
 (0)