Skip to content

Commit

Permalink
Remove support for unsupported versions of ruby and rails (#1898)
Browse files Browse the repository at this point in the history
* edit: remove support for unsuported versions of ruby and rails

* edit: compatability in docs

* edit: compatability in docs

* edit: compatability in docs

* add: changelog entry

* Update docs/compatibility.md

Co-authored-by: Blake Williams <blakewilliams@github.com>

* Update docs/compatibility.md

Co-authored-by: Blake Williams <blakewilliams@github.com>

* Update docs/compatibility.md

Co-authored-by: Hans Lemuet <Spone@users.noreply.github.com>

* Update docs/compatibility.md

Co-authored-by: Hans Lemuet <Spone@users.noreply.github.com>

* Update docs/compatibility.md

Co-authored-by: Hans Lemuet <Spone@users.noreply.github.com>

* Update docs/CHANGELOG.md

Co-authored-by: Hans Lemuet <Spone@users.noreply.github.com>

* edit: remove coverage of eol rails

* fix: lint issues

* edit: remove coverage of eol rails

* edit: remove coverage of eol rails

* edit: remove coverage of eol rails

* edit: remove coverage of eol rails

* edit: remove coverage of eol rails

* fix: lint issues

* fix: lint issues

* fix: lint issues

* fix: lint issues

* fix: lint issues

---------

Co-authored-by: Blake Williams <blakewilliams@github.com>
Co-authored-by: Hans Lemuet <Spone@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 16, 2023
1 parent 1680c6f commit bfee458
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 54 deletions.
16 changes: 2 additions & 14 deletions .github/workflows/ci.yml
Expand Up @@ -27,14 +27,8 @@ jobs:
fail-fast: false
matrix:
include:
- rails_version: "5.2.6"
ruby_version: "2.7"
mode: "capture_patch_enabled"
- rails_version: "6.0.4.4"
ruby_version: "2.7"
mode: "capture_patch_enabled"
- rails_version: "6.1.4.4"
ruby_version: "2.7"
ruby_version: "3.0"
mode: "capture_patch_enabled"
- rails_version: "7.0.2.3"
ruby_version: "3.0"
Expand All @@ -48,14 +42,8 @@ jobs:
- rails_version: "main"
ruby_version: "3.2"
mode: "capture_patch_enabled"
- rails_version: "5.2.6"
ruby_version: "2.7"
mode: "capture_patch_disabled"
- rails_version: "6.0.4.4"
ruby_version: "2.7"
mode: "capture_patch_disabled"
- rails_version: "6.1.4.4"
ruby_version: "2.7"
ruby_version: "3.0"
mode: "capture_patch_disabled"
- rails_version: "7.0.2.3"
ruby_version: "3.0"
Expand Down
13 changes: 0 additions & 13 deletions Appraisals
@@ -1,18 +1,5 @@
# frozen_string_literal: true

if RUBY_VERSION < "3.0.0"
appraise "rails-5.2" do
gem "rails", "~> 5.2.0"
end
else
puts "WARNING: Skipping Rails 5.2, as it is not compatible with Ruby >= 3.0.0"
end

appraise "rails-6.0" do
gem "rails", "~> 6.0.0"
gem "tailwindcss-rails", "~> 2.0"
end

appraise "rails-6.1" do
gem "rails", "~> 6.1.0"
gem "tailwindcss-rails", "~> 2.0"
Expand Down
6 changes: 6 additions & 0 deletions app/helpers/preview_helper.rb
@@ -1,7 +1,9 @@
# 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 @@ -28,6 +30,7 @@ def find_template_data(lookup_context:, template_identifier:)
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
Expand All @@ -53,6 +56,7 @@ def find_template_data(lookup_context:, template_identifier:)
prism_language_name: prism_language_name
}
end
# :nocov:
end

private
Expand All @@ -65,13 +69,15 @@ def prism_language_name_by_template(template:)
language
end

# :nocov:
def prism_language_name_by_template_path(template_file_path:)
language = template_file_path.gsub(".html", "").split(".").last

return FALLBACK_LANGUAGE unless AVAILABLE_PRISM_LANGUAGES.include? language

language
end
# :nocov:

def serve_static_preview_assets?
ViewComponent::Base.config.show_previews && Rails.application.config.public_file_server.enabled
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Expand Up @@ -10,6 +10,10 @@ nav_order: 5

## main

* Remove unsupported versions of Rails & Ruby from CI matrix.

*Reegan Viljoen*

* Raise error when uncountable slot names are used in `renders_many`

*Hugo Chantelauze*
Expand Down
4 changes: 2 additions & 2 deletions docs/compatibility.md
Expand Up @@ -8,9 +8,9 @@ nav_order: 6

## Ruby & Rails

ViewComponent is [supported natively](https://edgeguides.rubyonrails.org/layouts_and_rendering.html#rendering-objects) in Rails 6.1, and compatible with Rails 5.2+ via an included [monkey patch](https://github.com/viewcomponent/view_component/blob/main/lib/view_component/render_monkey_patch.rb).
ViewComponent supports all actively supported versions of Ruby (3.0+) and Ruby on Rails (6.1+) and is tested against a combination of these versions of Ruby on Rails.

ViewComponent is tested for compatibility [with combinations of](https://github.com/viewcomponent/view_component/blob/22e3d4ccce70d8f32c7375e5a5ccc3f70b22a703/.github/workflows/ruby_on_rails.yml#L10-L11) Ruby v2.5+ and Rails v5.2+. Ruby 2.4 is likely compatible, but is no longer tested.
While EOL (end-of-life) versions of Ruby and Ruby on Rails may still work with ViewComponent, they're not actively supported and no longer tested. We will still accept patches on a case-by-case basis to support older Ruby & Rails versions based on the complexity and maintenance burden. Please open an issue before submitting such a Pull Request.

## Template languages

Expand Down
8 changes: 0 additions & 8 deletions gemfiles/rails_5.2.gemfile

This file was deleted.

17 changes: 0 additions & 17 deletions gemfiles/rails_6.0.gemfile

This file was deleted.

2 changes: 2 additions & 0 deletions lib/view_component/compiler.rb
Expand Up @@ -258,6 +258,7 @@ def compile_template(template, handler)

if handler.method(:call).parameters.length > 1
handler.call(component_class, template)
# :nocov:
else
handler.call(
OpenStruct.new(
Expand All @@ -267,6 +268,7 @@ def compile_template(template, handler)
)
)
end
# :nocov:
end

def call_method_name(variant)
Expand Down
4 changes: 4 additions & 0 deletions lib/view_component/engine.rb
Expand Up @@ -80,6 +80,7 @@ class Engine < Rails::Engine # :nodoc:
initializer "view_component.monkey_patch_render" do |app|
next if Rails.version.to_f >= 6.1 || !app.config.view_component.render_monkey_patch_enabled

# :nocov:
ActiveSupport.on_load(:action_view) do
require "view_component/render_monkey_patch"
ActionView::Base.prepend ViewComponent::RenderMonkeyPatch
Expand All @@ -91,11 +92,13 @@ class Engine < Rails::Engine # :nodoc:
ActionController::Base.prepend ViewComponent::RenderingMonkeyPatch
ActionController::Base.prepend ViewComponent::RenderToStringMonkeyPatch
end
# :nocov:
end

initializer "view_component.include_render_component" do |_app|
next if Rails.version.to_f >= 6.1

# :nocov:
ActiveSupport.on_load(:action_view) do
require "view_component/render_component_helper"
ActionView::Base.include ViewComponent::RenderComponentHelper
Expand All @@ -107,6 +110,7 @@ class Engine < Rails::Engine # :nodoc:
ActionController::Base.include ViewComponent::RenderingComponentHelper
ActionController::Base.include ViewComponent::RenderComponentToStringHelper
end
# :nocov:
end

initializer "static assets" do |app|
Expand Down
2 changes: 2 additions & 0 deletions lib/view_component/errors.rb
Expand Up @@ -200,6 +200,7 @@ class ControllerCalledBeforeRenderError < BaseError
"`#controller` to a [`#before_render` method](https://viewcomponent.org/api.html#before_render--void)."
end

# :nocov:
class NoMatchingTemplatesForPreviewError < StandardError
MESSAGE = "Found 0 matches for templates for TEMPLATE_IDENTIFIER."

Expand All @@ -215,6 +216,7 @@ def initialize(template_identifier)
super(MESSAGE.gsub("TEMPLATE_IDENTIFIER", template_identifier))
end
end
# :nocov:

class SystemTestControllerOnlyAllowedInTestError < BaseError
MESSAGE = "ViewComponent SystemTest controller must only be called in a test environment for security reasons."
Expand Down
4 changes: 4 additions & 0 deletions lib/view_component/test_helpers.rb
Expand Up @@ -48,10 +48,14 @@ def render_inline(component, **args, &block)
@rendered_content =
if Rails.version.to_f >= 6.1
vc_test_controller.view_context.render(component, args, &block)

# :nocov:
else
vc_test_controller.view_context.render_component(component, &block)
end

# :nocov:

Nokogiri::HTML.fragment(@rendered_content)
end

Expand Down

0 comments on commit bfee458

Please sign in to comment.