frontend_reload_control 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/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +33 -0
- data/Rakefile +6 -0
- data/app/assets/javascripts/frontend_reload_control.js +33 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/frontend_reload_control.gemspec +26 -0
- data/lib/frontend_reload_control.rb +5 -0
- data/lib/frontend_reload_control/engine.rb +15 -0
- data/lib/frontend_reload_control/rails.rb +4 -0
- data/lib/frontend_reload_control/rails/helpers.rb +11 -0
- data/lib/frontend_reload_control/rails/inject.rb +16 -0
- data/lib/frontend_reload_control/version.rb +5 -0
- metadata +103 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: ce57e3e9006ffd80dacc621415dfb14cbfde14ac
|
|
4
|
+
data.tar.gz: 85551c793b9859dceae4fe3cc5842a68f6da8f2b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6f60e5c9506a030640607d92832988b804a5a52a598b37480ea29d36a88c7d2db263813f0a9cec46092868e0a5fddc46e8e679506828e35f26a6d231952803a1
|
|
7
|
+
data.tar.gz: ac85e4a58bd720668ad3b8f89f60d81186db22b4a936629932d26db14d9cf3744f945fe66e5ab9c656e8ca2909807dd53a397d28a8c2406c6d9fad61e00c628b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Requirements
|
|
2
|
+
- angular
|
|
3
|
+
- angular-cookies (ngCookies)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
# Rails setup for angular
|
|
7
|
+
|
|
8
|
+
Add gem
|
|
9
|
+
```
|
|
10
|
+
gem 'frontend_reload_control'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Add in application.js
|
|
14
|
+
```
|
|
15
|
+
//= require frontend_reload_control
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Add on your main modules
|
|
19
|
+
```
|
|
20
|
+
.config(function ($httpProvider) {
|
|
21
|
+
$httpProvider.interceptors.push('FrontendReloadControlInterceptor')
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
# Cors (optional)
|
|
26
|
+
|
|
27
|
+
If your frontend and api has diferents domains you need to configure CORS to expose X-Frontend-Reload-Control-Timestamp header.
|
|
28
|
+
Need help? https://github.com/cyu/rack-cors
|
|
29
|
+
|
|
30
|
+
# Tips
|
|
31
|
+
This gem will looks for timestamp.txt file on root of project to setup the actual version of app, if it doesn't exists it will use Time.now.to_i at APP startup.
|
|
32
|
+
|
|
33
|
+
If you want to avoid browser to reload for each APP restarts you need to fill timestamp.txt when you deploy your APP.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
;(function () {
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
angular.module('frontendReloadControl', []).factory('FrontendReloadControlInterceptor', FrontendReloadControlInterceptor)
|
|
5
|
+
|
|
6
|
+
FrontendReloadControlInterceptor.$inject = ['$cookies']
|
|
7
|
+
|
|
8
|
+
function FrontendReloadControlInterceptor ($cookies) {
|
|
9
|
+
var service = {
|
|
10
|
+
'response': response
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return service
|
|
14
|
+
|
|
15
|
+
function response (res) {
|
|
16
|
+
var newTimestamp = res.headers('X-Frontend-Reload-Control-Timestamp')
|
|
17
|
+
|
|
18
|
+
if (newTimestamp) {
|
|
19
|
+
var currentTimestamp = $cookies.get('X-Frontend-Reload-Control-Timestamp')
|
|
20
|
+
if (!currentTimestamp) {
|
|
21
|
+
console.log("Set New X-Frontend-Reload-Control-Timestamp: " + newTimestamp)
|
|
22
|
+
$cookies.put('X-Frontend-Reload-Control-Timestamp', newTimestamp)
|
|
23
|
+
} else if (parseInt(newTimestamp) > parseInt(currentTimestamp)) {
|
|
24
|
+
console.log("Set New X-Frontend-Reload-Control-Timestamp: " + newTimestamp)
|
|
25
|
+
$cookies.put('X-Frontend-Reload-Control-Timestamp', newTimestamp)
|
|
26
|
+
location.reload()
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return res
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
})()
|
|
33
|
+
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "frontend_reload_control"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'frontend_reload_control/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "frontend_reload_control"
|
|
8
|
+
spec.version = FrontendReloadControl::VERSION
|
|
9
|
+
spec.authors = ["Wagner Caixeta"]
|
|
10
|
+
spec.email = ["wagner.caixeta@al.go.leg.br"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{This gem makes browser to reload the page when the rails APP is updated.}
|
|
13
|
+
spec.description = %q{This gem makes browser to reload the page when the rails APP is updated. This is usefull for Single Page APPs.}
|
|
14
|
+
spec.homepage = "https://github.com/platbr/frontend_reload_control"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
|
18
|
+
end
|
|
19
|
+
spec.bindir = "exe"
|
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
21
|
+
spec.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
26
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module FrontendReloadControl
|
|
4
|
+
class Engine < ::Rails::Engine
|
|
5
|
+
engine_name 'FrontendReloadControl'
|
|
6
|
+
initializer 'FrontendReloadControl.load' do
|
|
7
|
+
timestamp = File.open('timestamp.txt').read.strip rescue nil
|
|
8
|
+
timestamp ||= Time.now.to_i.to_s
|
|
9
|
+
::Rails.cache.write("X-Frontend-Reload-Control-Timestamp", timestamp)
|
|
10
|
+
ActiveSupport.on_load :action_controller do
|
|
11
|
+
include FrontendReloadControl::Rails::Inject
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module FrontendReloadControl
|
|
4
|
+
module Rails
|
|
5
|
+
module Helpers
|
|
6
|
+
def add_frontend_reload_control_timestamp
|
|
7
|
+
response.headers['X-Frontend-Reload-Control-Timestamp'] = ::Rails.cache.fetch("X-Frontend-Reload-Control-Timestamp")
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module FrontendReloadControl
|
|
4
|
+
module Rails
|
|
5
|
+
module Inject
|
|
6
|
+
def self.included(base)
|
|
7
|
+
base.send :include, FrontendReloadControl::Rails::Helpers
|
|
8
|
+
if ::Rails.version.split('.')[0].to_i >= 5
|
|
9
|
+
base.before_action :add_frontend_reload_control_timestamp
|
|
10
|
+
else
|
|
11
|
+
base.before_filter :add_frontend_reload_control_timestamp
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: frontend_reload_control
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Wagner Caixeta
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-01-24 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.14'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.14'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
description: This gem makes browser to reload the page when the rails APP is updated.
|
|
56
|
+
This is usefull for Single Page APPs.
|
|
57
|
+
email:
|
|
58
|
+
- wagner.caixeta@al.go.leg.br
|
|
59
|
+
executables: []
|
|
60
|
+
extensions: []
|
|
61
|
+
extra_rdoc_files: []
|
|
62
|
+
files:
|
|
63
|
+
- ".gitignore"
|
|
64
|
+
- ".rspec"
|
|
65
|
+
- ".travis.yml"
|
|
66
|
+
- Gemfile
|
|
67
|
+
- README.md
|
|
68
|
+
- Rakefile
|
|
69
|
+
- app/assets/javascripts/frontend_reload_control.js
|
|
70
|
+
- bin/console
|
|
71
|
+
- bin/setup
|
|
72
|
+
- frontend_reload_control.gemspec
|
|
73
|
+
- lib/frontend_reload_control.rb
|
|
74
|
+
- lib/frontend_reload_control/engine.rb
|
|
75
|
+
- lib/frontend_reload_control/rails.rb
|
|
76
|
+
- lib/frontend_reload_control/rails/helpers.rb
|
|
77
|
+
- lib/frontend_reload_control/rails/inject.rb
|
|
78
|
+
- lib/frontend_reload_control/version.rb
|
|
79
|
+
homepage: https://github.com/platbr/frontend_reload_control
|
|
80
|
+
licenses: []
|
|
81
|
+
metadata: {}
|
|
82
|
+
post_install_message:
|
|
83
|
+
rdoc_options: []
|
|
84
|
+
require_paths:
|
|
85
|
+
- lib
|
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - ">="
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '0'
|
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
requirements: []
|
|
97
|
+
rubyforge_project:
|
|
98
|
+
rubygems_version: 2.6.8
|
|
99
|
+
signing_key:
|
|
100
|
+
specification_version: 4
|
|
101
|
+
summary: This gem makes browser to reload the page when the rails APP is updated.
|
|
102
|
+
test_files: []
|
|
103
|
+
has_rdoc:
|