railcar 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/railcar.js.erb +47 -0
- data/lib/railcar.rb +8 -0
- data/lib/railcar/version.rb +3 -0
- data/railcar.gemspec +21 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Railcar
|
2
|
+
|
3
|
+
Client Auto-Reload for Ruby on Rails.
|
4
|
+
|
5
|
+
This gem will cause your visitor's browsers to automatically reload when a new release of your Rails app is deployed. This helps ensure that the DOM and JS running in a browser are not outdated.
|
6
|
+
|
7
|
+
Railcar achieves this by running as client-side javascript, monitoring the server-side availability of the currently loaded assets. If they are no longer available, Railcar assumes that a new, fingerprinted version has been generated and forces a reload.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'railcar'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install railcar
|
22
|
+
|
23
|
+
Finally, require the Railcar logic in your script pipeline (this generally goes in `app/assets/javascripts/application.js`, after the jquery-related requires):
|
24
|
+
|
25
|
+
//= require railcar
|
26
|
+
|
27
|
+
That's it!
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
If you followed the installation steps, you're done.
|
32
|
+
|
33
|
+
**Note:** Because Rails, by default, only fingerprints assets when running in production mode, Railcar will not run while in development.
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
var Railcar = {
|
2
|
+
interval: 60,
|
3
|
+
|
4
|
+
check: function() {
|
5
|
+
|
6
|
+
// Gather list of includes
|
7
|
+
|
8
|
+
var includes = [];
|
9
|
+
$('script[src], link[href]').each(function() {
|
10
|
+
includes.push( $(this).attr('src') || $(this).attr('href') );
|
11
|
+
});
|
12
|
+
|
13
|
+
// Remove remote and non-fingerprinted includes
|
14
|
+
|
15
|
+
includes = $.grep(includes, function(include) {
|
16
|
+
var isPath = /^http/i.exec(include) == null;
|
17
|
+
var hasFingerprint = /\-[0-9a-f]+\.(js|css)$/i.exec(include) != null;
|
18
|
+
|
19
|
+
return isPath && hasFingerprint;
|
20
|
+
});
|
21
|
+
|
22
|
+
// Reload page if expired includes exist
|
23
|
+
|
24
|
+
$.each(includes, function(_i, include) {
|
25
|
+
$.ajax({
|
26
|
+
type: 'HEAD',
|
27
|
+
cache: false,
|
28
|
+
url: include,
|
29
|
+
error: function() {
|
30
|
+
window.location.reload(true);
|
31
|
+
}
|
32
|
+
});
|
33
|
+
});
|
34
|
+
|
35
|
+
this.scheduleCheck();
|
36
|
+
},
|
37
|
+
|
38
|
+
run: function() {
|
39
|
+
this.scheduleCheck();
|
40
|
+
},
|
41
|
+
|
42
|
+
scheduleCheck: function() {
|
43
|
+
setTimeout('Railcar.check()', this.interval * 1000);
|
44
|
+
}
|
45
|
+
};
|
46
|
+
|
47
|
+
$(function(){ Railcar.run(); });
|
data/lib/railcar.rb
ADDED
data/railcar.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'railcar/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "railcar"
|
8
|
+
gem.version = Railcar::VERSION
|
9
|
+
gem.authors = ["Taylor Boyko"]
|
10
|
+
gem.email = ["taylorboyko@gmail.com"]
|
11
|
+
gem.description = %q{Client Auto-Reload for Ruby on Rails}
|
12
|
+
gem.summary = %q{Automatically refresh client browsers upon Rails application deployment}
|
13
|
+
gem.homepage = "https://github.com/tboyko/railcar"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency('rake')
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: railcar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Taylor Boyko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Client Auto-Reload for Ruby on Rails
|
31
|
+
email:
|
32
|
+
- taylorboyko@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- app/assets/javascripts/railcar.js.erb
|
43
|
+
- lib/railcar.rb
|
44
|
+
- lib/railcar/version.rb
|
45
|
+
- railcar.gemspec
|
46
|
+
homepage: https://github.com/tboyko/railcar
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
hash: 930120150054146986
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
hash: 930120150054146986
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.24
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Automatically refresh client browsers upon Rails application deployment
|
76
|
+
test_files: []
|