forked from MoOx/compass-recipes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile.rb
69 lines (59 loc) · 2.02 KB
/
Rakefile.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
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
task :default do
sh "compass compile"
end
task :pages do
require 'git'
require 'fileutils'
repo = Git.open('.')
# copy tests into a temp dir before switching branch
FileUtils.rm_rf "tmp"
FileUtils.mkdir("tmp")
(FileList.new('fonts/**/*')+FileList.new('stylesheets/**/*')+FileList.new('templates/**/*')+FileList.new('tests/**/*')).each do |file|
if File.file?(file)
if !File.directory?(File.dirname("tmp/#{file}"))
puts 'Mkdir' + File.dirname("tmp/#{file}")
FileUtils.mkdir_p(File.dirname("tmp/#{file}"))
end
FileUtils.cp(file, "tmp/#{file}")
puts 'File ' + file
else #assume dir
FileUtils.mkdir_p("tmp/#{file}")
puts 'Dir ' + file
end
end
# switch branch
repo.branch("gh-pages").checkout
# Reset gh-pages
FileUtils.rm_rf "fonts"
FileUtils.rm_rf "stylesheets"
FileUtils.rm_rf "templates"
FileUtils.rm_rf "tests"
# Prepare tests addons
headMarker = '<!doctype html>'
htmlHeader = headMarker + File.open("layout/header.html", "r").read
htmlFooter = File.open("layout/footer.html", "r").read
# HTML files need header and footer
FileList.new('tmp/**/*.html').each do |file|
contents = File.open(file, "rb").read
htmlfile = File.open("#{file}", "w")
contents = contents.sub(headMarker, htmlHeader)
htmlFooter += contents
htmlfile.write(contents)
htmlfile.close
end
# just copy all files
FileList.new('tmp/*').each do |file|
#FileUtils.mkdir_p(File.dirname("#{file[4..-1]}"))
puts 'File copy: ' + file + ' to ' + "#{file[4..-1]}"
FileUtils.mv(file, Dir.pwd + "/#{file[4..-1]}")
end
FileUtils.rm_rf("tmp")
# Commit gh-pages changes
# @todo make this optional ?
Dir["fonts/**/*", "stylesheets/**/*", "templates/**/*", "tests/**/*"].each {|f| repo.add(f) }
repo.status.deleted.each {|f, s| repo.remove(f)}
message = ENV["MESSAGE"] || "Updated at #{Time.now.utc}"
repo.commit(message)
# back to master (maybe it's not appropriate if we are not working on master ?!)
repo.branch("master").checkout
end