File tree Expand file tree Collapse file tree 5 files changed +9
-6
lines changed Expand file tree Collapse file tree 5 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ nav_order: 6
1313* Add Carwow to list of companies using ViewComponent.
1414
1515 * Tom Lord*
16+ * ViewComponent now works without ` rails ` and ` railties ` gems loaded.
17+
18+ * Michal Cichra*
1619
1720## 4.0.2
1821
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ module ViewComponent
1616 autoload :Preview
1717 autoload :Translatable
1818
19- if Rails . env . test?
19+ if defined? ( Rails . env ) && Rails . env . test?
2020 autoload :TestHelpers
2121 autoload :SystemSpecHelpers
2222 autoload :SystemTestHelpers
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ def config
4747 end
4848
4949 include ActionView ::Helpers
50- include Rails . application . routes . url_helpers if defined? ( Rails ) && Rails . application
50+ include Rails . application . routes . url_helpers if defined? ( Rails . application . routes )
5151 include ERB ::Escape
5252 include ActiveSupport ::CoreExt ::ERBUtil
5353
@@ -302,7 +302,7 @@ def helpers
302302 @__vc_helpers ||= __vc_original_view_context || controller . view_context
303303 end
304304
305- if ::Rails . env . development? || ::Rails . env . test?
305+ if defined? ( Rails . env ) && ( ::Rails . env . development? || ::Rails . env . test? )
306306 # @private
307307 def method_missing ( method_name , *args ) # rubocop:disable Style/MissingRespondToMissing
308308 super
@@ -331,7 +331,7 @@ def view_cache_dependencies
331331 [ ]
332332 end
333333
334- if Rails ::VERSION :: MAJOR == 7 && Rails ::VERSION ::MINOR == 1
334+ if defined? ( Rails ::VERSION ) && ( Rails :: VERSION :: MAJOR == 7 && Rails ::VERSION ::MINOR == 1 )
335335 # Rails expects us to define `format` on all renderables,
336336 # but we do not know the `format` of a ViewComponent until runtime.
337337 def format
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ def each(&block)
2020 components . each ( &block )
2121 end
2222
23- if Rails ::VERSION :: MAJOR == 7 && Rails ::VERSION ::MINOR == 1
23+ if defined? ( Rails ::VERSION ) && ( Rails :: VERSION :: MAJOR == 7 && Rails ::VERSION ::MINOR == 1 )
2424 # Rails expects us to define `format` on all renderables,
2525 # but we do not know the `format` of a ViewComponent until runtime.
2626 def format
Original file line number Diff line number Diff line change @@ -163,7 +163,7 @@ def default_previews_options
163163 options = ActiveSupport ::OrderedOptions . new
164164 options . controller = "ViewComponentsController"
165165 options . route = "/rails/view_components"
166- options . enabled = Rails . env . development? || Rails . env . test?
166+ options . enabled = defined? ( Rails . env ) && ( Rails . env . development? || Rails . env . test? )
167167 options . default_layout = nil
168168 options . paths = default_preview_paths
169169 options
You can’t perform that action at this time.
0 commit comments