Skip to content
Open
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
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ nav_order: 6
* Add Carwow to list of companies using ViewComponent.

*Tom Lord*
* ViewComponent now works without `rails` and `railties` gems loaded.

*Michal Cichra*

## 4.0.2

Expand Down
2 changes: 1 addition & 1 deletion lib/view_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module ViewComponent
autoload :Preview
autoload :Translatable

if Rails.env.test?
if defined?(Rails.env) && Rails.env.test?
autoload :TestHelpers
autoload :SystemSpecHelpers
autoload :SystemTestHelpers
Expand Down
6 changes: 3 additions & 3 deletions lib/view_component/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def config
end

include ActionView::Helpers
include Rails.application.routes.url_helpers if defined?(Rails) && Rails.application
include Rails.application.routes.url_helpers if defined?(Rails.application.routes)
include ERB::Escape
include ActiveSupport::CoreExt::ERBUtil

Expand Down Expand Up @@ -302,7 +302,7 @@ def helpers
@__vc_helpers ||= __vc_original_view_context || controller.view_context
end

if ::Rails.env.development? || ::Rails.env.test?
if defined?(Rails.env) && (::Rails.env.development? || ::Rails.env.test?)
# @private
def method_missing(method_name, *args) # rubocop:disable Style/MissingRespondToMissing
super
Expand Down Expand Up @@ -331,7 +331,7 @@ def view_cache_dependencies
[]
end

if Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 1
if defined?(Rails::VERSION) && (Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 1)
# Rails expects us to define `format` on all renderables,
# but we do not know the `format` of a ViewComponent until runtime.
def format
Expand Down
2 changes: 1 addition & 1 deletion lib/view_component/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def each(&block)
components.each(&block)
end

if Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 1
if defined?(Rails::VERSION) && (Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 1)
# Rails expects us to define `format` on all renderables,
# but we do not know the `format` of a ViewComponent until runtime.
def format
Expand Down
2 changes: 1 addition & 1 deletion lib/view_component/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def default_previews_options
options = ActiveSupport::OrderedOptions.new
options.controller = "ViewComponentsController"
options.route = "/rails/view_components"
options.enabled = Rails.env.development? || Rails.env.test?
options.enabled = defined?(Rails.env) && (Rails.env.development? || Rails.env.test?)
options.default_layout = nil
options.paths = default_preview_paths
options
Expand Down
Loading