-
Notifications
You must be signed in to change notification settings - Fork 1
/
update-header-footer
executable file
·71 lines (58 loc) · 1.92 KB
/
update-header-footer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env ruby
require 'open-uri'
class Util
def self.log(params = {})
return if ENV['QUIET']
@complete_log ||= []
params = {message: params} if params.is_a? String
puts ('*' * 120).white if params[:divider]
@complete_log << "#{('*' * 120)}\n" if params[:divider]
puts params[:message] if params[:message]
@complete_log << "#{params[:message]}\n".gsub(/\[1;3[0-9]?m/,"").gsub("\[0m","") if params[:message]
# if(params[:push] and params[:message])
# Pushover.notification(message: params[:message], title: 'Script Ampliar')
# end
end
def self.confirm(params = {})
return true if ENV['CONFIRM']
print "\n#{params[:message]} [Yn] "
return STDIN.gets.chomp.downcase != 'n'
end
end
class Runner
class << self
def run
if ::Util.confirm(message: "Update from #{base_url}?")
update('header')
update('footer')
update_css
update_js
end
end
def update(part)
output = open("#{base_url}/#{part}").read
output = output.gsub('http://localhost:4567','https://www.boletosimples.com.br')
output = output.gsub('https://www.boletosimples.com.br/assets/images/','/img/')
open("_includes/#{part}.html", 'w') do |file|
file << output
end
end
def update_css
output = open("#{base_url}/assets/stylesheets/header-footer.css").read
output = output.gsub('http://localhost:4567','https://www.boletosimples.com.br')
output = output.gsub('https://www.boletosimples.com.br/assets/images/','/img/')
open('css/header-footer.css', 'w') do |file|
file << output
end
end
def update_js
open('js/header-footer.js', 'w') do |file|
file << open("#{base_url}/assets/javascripts/header-footer.js").read
end
end
def base_url
@base_url ||= (ENV['LOCAL'] ? 'http://localhost:4567' : 'https://www.boletosimples.com.br')
end
end
end
Runner.run