-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasset.rb
40 lines (35 loc) · 838 Bytes
/
asset.rb
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
class Asset
@@public_dir = "public/"
def initialize(filename)
@filename = filename
end
def filename(option = "")
:versioned == option ? @filename.split(".").insert(-2, sha[1..8]).join(".") : @filename
end
def filepath(option = "")
@@public_dir + filename(option)
end
def version_control!
File.copy(filepath, filepath(:versioned))
lines = []
LAYOUTS.each do |layout|
File.open(layout, "r") do |file|
lines = file.readlines
end
end
lines.each_with_index do |line, i|
if line.include?(filename)
lines[i] = line.sub(filename, filename(:versioned))
end
end
LAYOUTS.each do |layout|
File.open(layout, "r+") do |file|
file << lines
end
end
end
private
def sha
`git log -n 1 #{filepath}`[7,40]
end
end