Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4.0.0 #2085

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

v4.0.0 #2085

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ jobs:
fail-fast: false
matrix:
include:
- ruby_version: "3.0"
rails_version: "6.1"
mode: "capture_patch_enabled"
- ruby_version: "3.0"
rails_version: "6.1"
mode: "capture_patch_disabled"
- ruby_version: "3.1"
rails_version: "7.0"
mode: "capture_patch_enabled"
- ruby_version: "3.1"
rails_version: "7.0"
mode: "capture_patch_disabled"
- ruby_version: "3.2"
rails_version: "7.1"
mode: "capture_patch_enabled"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.gem
*.rbc
.ruby-version
.DS_Store
/.config
/coverage/assets
/coverage/index.html
Expand Down
17 changes: 0 additions & 17 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
# frozen_string_literal: true

appraise "rails-6.1" do
gem "rails", "~> 6.1"
gem "tailwindcss-rails", "~> 2.0"

# Required for Ruby 3.1.0
gem "net-smtp", require: false
gem "net-imap", require: false
gem "net-pop", require: false
gem "turbo-rails", "~> 1"
end

appraise "rails-7.0" do
gem "rails", "~> 7.0"
gem "tailwindcss-rails", "~> 2.0"
gem "turbo-rails", "~> 1"
end

appraise "rails-7.1" do
gem "rails", "~> 7.1"
gem "tailwindcss-rails", "~> 2.0"
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source "https://rubygems.org"
gemspec

rails_version = (ENV["RAILS_VERSION"] || "~> 7.0.0").to_s
rails_version = (ENV["RAILS_VERSION"] || "~> 7.1.0").to_s
gem "rails", (rails_version == "main") ? {git: "https://github.com/rails/rails", ref: "main"} : rails_version

ruby_version = (ENV["RUBY_VERSION"] || "~> 3.3").to_s
Expand Down
150 changes: 83 additions & 67 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,86 @@ PATH
remote: .
specs:
view_component (3.20.0)
activesupport (>= 5.2.0, < 8.1)
activesupport (>= 7.1.0, < 8.1)
concurrent-ruby (~> 1.0)
method_source (~> 1.0)

GEM
remote: https://rubygems.org/
specs:
actioncable (7.0.8.6)
actionpack (= 7.0.8.6)
activesupport (= 7.0.8.6)
actioncable (7.1.4)
actionpack (= 7.1.4)
activesupport (= 7.1.4)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.8.6)
actionpack (= 7.0.8.6)
activejob (= 7.0.8.6)
activerecord (= 7.0.8.6)
activestorage (= 7.0.8.6)
activesupport (= 7.0.8.6)
zeitwerk (~> 2.6)
actionmailbox (7.1.4)
actionpack (= 7.1.4)
activejob (= 7.1.4)
activerecord (= 7.1.4)
activestorage (= 7.1.4)
activesupport (= 7.1.4)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.8.6)
actionpack (= 7.0.8.6)
actionview (= 7.0.8.6)
activejob (= 7.0.8.6)
activesupport (= 7.0.8.6)
actionmailer (7.1.4)
actionpack (= 7.1.4)
actionview (= 7.1.4)
activejob (= 7.1.4)
activesupport (= 7.1.4)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.8.6)
actionview (= 7.0.8.6)
activesupport (= 7.0.8.6)
rack (~> 2.0, >= 2.2.4)
rails-dom-testing (~> 2.2)
actionpack (7.1.4)
actionview (= 7.1.4)
activesupport (= 7.1.4)
nokogiri (>= 1.8.5)
racc
rack (>= 2.2.4)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.8.6)
actionpack (= 7.0.8.6)
activerecord (= 7.0.8.6)
activestorage (= 7.0.8.6)
activesupport (= 7.0.8.6)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actiontext (7.1.4)
actionpack (= 7.1.4)
activerecord (= 7.1.4)
activestorage (= 7.1.4)
activesupport (= 7.1.4)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.8.6)
activesupport (= 7.0.8.6)
actionview (7.1.4)
activesupport (= 7.1.4)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.8.6)
activesupport (= 7.0.8.6)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activejob (7.1.4)
activesupport (= 7.1.4)
globalid (>= 0.3.6)
activemodel (7.0.8.6)
activesupport (= 7.0.8.6)
activerecord (7.0.8.6)
activemodel (= 7.0.8.6)
activesupport (= 7.0.8.6)
activestorage (7.0.8.6)
actionpack (= 7.0.8.6)
activejob (= 7.0.8.6)
activerecord (= 7.0.8.6)
activesupport (= 7.0.8.6)
activemodel (7.1.4)
activesupport (= 7.1.4)
activerecord (7.1.4)
activemodel (= 7.1.4)
activesupport (= 7.1.4)
timeout (>= 0.4.0)
activestorage (7.1.4)
actionpack (= 7.1.4)
activejob (= 7.1.4)
activerecord (= 7.1.4)
activesupport (= 7.1.4)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.8.6)
activesupport (7.1.4)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
Expand Down Expand Up @@ -105,6 +114,7 @@ GEM
xpath (~> 3.2)
coderay (1.1.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crass (1.0.6)
cuprite (0.15.1)
capybara (~> 3.0)
Expand Down Expand Up @@ -191,37 +201,43 @@ GEM
puma (6.4.3)
nio4r (~> 2.0)
racc (1.8.1)
rack (2.2.10)
rack (2.2.9)
rack-session (1.0.2)
rack (< 3)
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.8.6)
actioncable (= 7.0.8.6)
actionmailbox (= 7.0.8.6)
actionmailer (= 7.0.8.6)
actionpack (= 7.0.8.6)
actiontext (= 7.0.8.6)
actionview (= 7.0.8.6)
activejob (= 7.0.8.6)
activemodel (= 7.0.8.6)
activerecord (= 7.0.8.6)
activestorage (= 7.0.8.6)
activesupport (= 7.0.8.6)
rackup (1.0.0)
rack (< 3)
webrick
rails (7.1.4)
actioncable (= 7.1.4)
actionmailbox (= 7.1.4)
actionmailer (= 7.1.4)
actionpack (= 7.1.4)
actiontext (= 7.1.4)
actionview (= 7.1.4)
activejob (= 7.1.4)
activemodel (= 7.1.4)
activerecord (= 7.1.4)
activestorage (= 7.1.4)
activesupport (= 7.1.4)
bundler (>= 1.15.0)
railties (= 7.0.8.6)
railties (= 7.1.4)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.0.8.6)
actionpack (= 7.0.8.6)
activesupport (= 7.0.8.6)
method_source
railties (7.1.4)
actionpack (= 7.1.4)
activesupport (= 7.1.4)
irb
rackup (>= 1.0.0)
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.2.1)
rdoc (6.7.0)
Expand Down Expand Up @@ -356,7 +372,7 @@ DEPENDENCIES
net-smtp
pry (~> 0.13)
puma (~> 6)
rails (~> 7.0.0)
rails (~> 7.1.0)
rake (~> 13.0)
rspec-rails (~> 5)
rubocop-md (~> 1)
Expand Down
40 changes: 4 additions & 36 deletions app/helpers/preview_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# frozen_string_literal: true

module PreviewHelper
# :nocov:
include ActionView::Helpers::AssetUrlHelper if Rails.version.to_f < 6.1
# :nocov:

AVAILABLE_PRISM_LANGUAGES = %w[ruby erb haml]
FALLBACK_LANGUAGE = "ruby"

Expand All @@ -25,38 +21,10 @@ def prism_js_source_url
def find_template_data(lookup_context:, template_identifier:)
template = lookup_context.find_template(template_identifier)

if Rails.version.to_f >= 6.1 || template.source.present?
{
source: template.source,
prism_language_name: prism_language_name_by_template(template: template)
}
# :nocov:
else
# Fetch template source via finding it through preview paths
# to accomodate source view when exclusively using templates
# for previews for Rails < 6.1.
all_template_paths = ViewComponent::Base.config.preview_paths.map do |preview_path|
Dir.glob("#{preview_path}/**/*")
end.flatten

# Search for templates the contain `html`.
matching_templates = all_template_paths.find_all do |path|
path =~ /#{template_identifier}*.(html)/
end

raise ViewComponent::NoMatchingTemplatesForPreviewError.new(template_identifier) if matching_templates.empty?
raise ViewComponent::MultipleMatchingTemplatesForPreviewError.new(template_identifier) if matching_templates.size > 1

template_file_path = matching_templates.first
template_source = File.read(template_file_path)
prism_language_name = prism_language_name_by_template_path(template_file_path: template_file_path)

{
source: template_source,
prism_language_name: prism_language_name
}
end
# :nocov:
{
source: template.source,
prism_language_name: prism_language_name_by_template(template: template)
}
end

private
Expand Down
6 changes: 1 addition & 5 deletions app/views/view_components/preview.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<% if @render_args[:component] %>
<% if ViewComponent::Base.config.render_monkey_patch_enabled || Rails.version.to_f >= 6.1 %>
<%= render(@render_args[:component], @render_args[:args], &@render_args[:block]) %>
<% else %>
<%= render_component(@render_args[:component], &@render_args[:block]) %>
<% end %>
<%= render(@render_args[:component], @render_args[:args], &@render_args[:block]) %>
<% else %>
<%= render template: @render_args[:template], locals: @render_args[:locals] || {} %>
<% end %>
Expand Down
18 changes: 18 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ nav_order: 5

## main

## 4.0.0

* BREAKING: Require [non-EOL](https://endoflife.date/rails) Rails (`>= 7.1.0`).

*Joel Hawksley*

* BREAKING: Require [non-EOL](https://www.ruby-lang.org/en/downloads/branches/) Ruby (`>= 3.2.0`).

*Joel Hawksley*

* BREAKING: Remove `render_component` and `render` monkey patch configured with `render_monkey_patch_enabled`.

*Joel Hawksley*

* BREAKING: Remove support for variant names containing `.` to be consistent with Rails.

*Stephen Nelson*

* Ensure HTML output safety wrapper is used for all inline templates.

*Joel Hawksley*
Expand Down
6 changes: 0 additions & 6 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,6 @@ Defaults to `['test/components/previews']` relative to your Rails root.
The entry route for component previews.
Defaults to `"/rails/view_components"`.

### `.render_monkey_patch_enabled`

If this is disabled, use `#render_component` or
`#render_component_to_string` instead.
Defaults to `true`.

### `.show_previews`

Whether component previews are enabled.
Expand Down
Loading
Loading