Skip to content

Commit

Permalink
Add support for RailsLiveReload
Browse files Browse the repository at this point in the history
Automatically reloads the dummy app (or any other app that has
`rails_live_reload`gem installed) if changes to Alchemy files have
been made.
  • Loading branch information
tvdeyen committed Dec 8, 2023
1 parent 7aab57d commit 9e1b1df
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ if Gem.ruby_version >= Gem::Version.new("3.1.0")
end

gem "web-console", "~> 4.2", group: :development

gem "rails_live_reload", "~> 0.3.5"
13 changes: 13 additions & 0 deletions config/initializers/rails_live_reload.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

if defined?(RailsLiveReload)
RailsLiveReload.configure do |config|
# Default watched folders & files
config.watch %r{app/views/.+\.(erb)$}
config.watch %r{(app|vendor)/(assets|javascript)/\w+/(.+\.(s?css|coffee|js|html|png|jpg)).*}, reload: :always

# More examples:
config.watch %r{app/(helpers|components|decorators)/.+\.rb}, reload: :always
config.watch %r{config/locales/.+\.yml}, reload: :always
end
end
5 changes: 5 additions & 0 deletions lib/alchemy/dev_support/live_reload_watcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Alchemy
class LiveReloadWatcher < RailsLiveReload::Watcher
def root = Alchemy::Engine.root
end
end
6 changes: 6 additions & 0 deletions lib/alchemy/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class Engine < Rails::Engine
Alchemy.user_class.stampable(stamper_class_name: Alchemy.user_class.name)
end
end

if defined?(RailsLiveReload) && Rails.env.development?
require "alchemy/dev_support/live_reload_watcher"

Alchemy::LiveReloadWatcher.init
end
end

initializer "alchemy.webp-mime_type" do
Expand Down

0 comments on commit 9e1b1df

Please sign in to comment.