rails_hotreload 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +56 -0
- data/Rakefile +5 -0
- data/lib/rails_hotreload/railtie.rb +16 -0
- data/lib/rails_hotreload/version.rb +5 -0
- data/lib/rails_hotreload/views/rails_hotreload/_stream.html.erb +13 -0
- data/lib/rails_hotreload.rb +32 -0
- data/lib/tasks/rails_hotreload_tasks.rake +12 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1b8d3ad2ecb83d63ffe91f99a7cd7d7029390557372a3f3c24499b24b22a1346
|
4
|
+
data.tar.gz: 06cb7737098ce18004281217a912ae6715c71970c5e288c6cde8ffc12437f1b5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9307bf9a5ce9e303b3c967f6aa17eb378da34fc44885a4ff50592a0d3d78bd22919a246b3286bd376d9774c19eee824de9dbbe69c5241459af0fe16f78981a04
|
7
|
+
data.tar.gz: 505f5fedba775e09c811c3a1997146b236622b1879706b0b67d2abaa4d3bab3aa1dcfed48f3fde00fbb8fbc6a91df50edb20fcffe896bfca967d7491d08f9338
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# RailsHotreload
|
2
|
+
|
3
|
+
This gem adds hot reloading feature to Rails applications that contains hotwire. The application is automatically reloaded when:
|
4
|
+
- Any file has changed (added, updated or deleted) in `app/assets/builds`
|
5
|
+
- Any app view was changed (added, updated or deleted) in `app/views`
|
6
|
+
|
7
|
+
## Dependencies
|
8
|
+
- This Gem depends on (turbo-rails)[https://github.com/hotwired/turbo-rails] to automatically stream reload message when file changes were detected
|
9
|
+
- This Gem depends on (listen)[https://github.com/guard/listen] to detect file changes
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
- Add this line to your application's Gemfile:
|
13
|
+
```ruby
|
14
|
+
group :development, :test do
|
15
|
+
gem "rails_hotreload"
|
16
|
+
end
|
17
|
+
```
|
18
|
+
- And then execute:
|
19
|
+
```bash
|
20
|
+
$ bundle
|
21
|
+
```
|
22
|
+
- Include this template in your layout
|
23
|
+
```ruby
|
24
|
+
= render '/rails_hotreload/stream'
|
25
|
+
```
|
26
|
+
|
27
|
+
- Start the file watcher
|
28
|
+
```
|
29
|
+
bin/rails rails_hotreload:start
|
30
|
+
```
|
31
|
+
Note: If your project is using Procfile.dev (Foreman), then you can add:
|
32
|
+
```
|
33
|
+
rails_hotreload: bin/rails rails_hotreload:start
|
34
|
+
```
|
35
|
+
- Start your rails application and
|
36
|
+
|
37
|
+
## Configuration
|
38
|
+
- This gem by default is watching changes in: `app/assets/builds,app/views/`. This can be customized as the following:
|
39
|
+
```
|
40
|
+
bin/rails rails_hotreload:start app/javascripts,app/stylesheets,app/views/
|
41
|
+
```
|
42
|
+
- The hot reloader UI can be customized as the following:
|
43
|
+
```
|
44
|
+
= render '/rails_hotreload/stream', custom_style: 'right: 20px; top: 20px;'
|
45
|
+
```
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/owen2345/pub_sub_model_sync. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
49
|
+
You can run the tests with: `docker-compose run test bash`
|
50
|
+
|
51
|
+
## License
|
52
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
53
|
+
|
54
|
+
## **Code of Conduct**
|
55
|
+
|
56
|
+
Everyone interacting in the PubSubModelSync project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/pub_sub_model_sync/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails'
|
4
|
+
module RailsHotreload
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
railtie_name :rails_hotreload
|
7
|
+
|
8
|
+
rake_tasks do
|
9
|
+
load 'rails_hotreload/lib/tasks/rails_hotreload_tasks.rake'
|
10
|
+
end
|
11
|
+
|
12
|
+
config.before_initialize do |app|
|
13
|
+
app.config.paths['app/views'].unshift(File.join(__dir__, 'views').to_s)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<div id="rails_hotreload" style="position: fixed; bottom: 0; left: 0; background: red; padding: 3px; font-size: 10px; <%= local_assigns[:custom_style] %>">
|
2
|
+
<%= turbo_stream_from 'rails_hotreload' %>
|
3
|
+
<span>Hot-reloading: <input type="checkbox" style="vertical-align: middle;" checked></span>
|
4
|
+
<script type="text/javascript">
|
5
|
+
window.addEventListener('DOMContentLoaded', function() {
|
6
|
+
const panel = document.getElementById('rails_hotreload');
|
7
|
+
panel.addEventListener('DOMNodeInserted', () => {
|
8
|
+
const enabled = panel.querySelector('input').checked;
|
9
|
+
if (enabled) window.location.reload();
|
10
|
+
});
|
11
|
+
});
|
12
|
+
</script>
|
13
|
+
</div>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_hotreload/version'
|
4
|
+
require 'rails_hotreload/railtie'
|
5
|
+
|
6
|
+
require 'listen'
|
7
|
+
require 'turbo-rails'
|
8
|
+
|
9
|
+
module RailsHotreload
|
10
|
+
class Checker
|
11
|
+
attr_reader :paths
|
12
|
+
|
13
|
+
def initialize(paths)
|
14
|
+
@paths = paths
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
puts "Listening for changes in #{paths}"
|
19
|
+
listener = Listen.to(*paths, {}) { stream_reload }
|
20
|
+
listener.start
|
21
|
+
sleep
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def stream_reload
|
27
|
+
puts 'Changes detected, reloading...'
|
28
|
+
klass = Turbo::StreamsChannel
|
29
|
+
klass.broadcast_append_to('rails_hotreload', target: 'rails_hotreload', content: '<span />')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$stdout.sync = true
|
4
|
+
require 'listen'
|
5
|
+
namespace :rails_hotreload do
|
6
|
+
desc 'Start watching file changes. Sample: bin/rails rails_hotreload:start app/assets/builds'
|
7
|
+
task start: :environment do
|
8
|
+
paths = (ARGV[0] || 'app/assets/builds,app/views/').to_s.split(',')
|
9
|
+
paths = paths.map { |p| Rails.root.join(p).to_s }
|
10
|
+
RailsHotreload::Checker.new(paths).call
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_hotreload
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Owen Peredo Diaz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: listen
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: turbo-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Auto reloads Rails 7+ applications when assets or views have changed
|
56
|
+
email:
|
57
|
+
- owenperedo@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- README.md
|
63
|
+
- Rakefile
|
64
|
+
- lib/rails_hotreload.rb
|
65
|
+
- lib/rails_hotreload/railtie.rb
|
66
|
+
- lib/rails_hotreload/version.rb
|
67
|
+
- lib/rails_hotreload/views/rails_hotreload/_stream.html.erb
|
68
|
+
- lib/tasks/rails_hotreload_tasks.rake
|
69
|
+
homepage: https://github.com/owen2345/rails-hotreload
|
70
|
+
licenses: []
|
71
|
+
metadata:
|
72
|
+
homepage_uri: https://github.com/owen2345/rails-hotreload
|
73
|
+
source_code_uri: https://github.com/owen2345/rails-hotreload
|
74
|
+
changelog_uri: https://github.com/owen2345/rails-hotreload
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubygems_version: 3.1.2
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Auto reloads Rails 7+ applications when assets or views have changed
|
94
|
+
test_files: []
|