forked from gi-lunaweb/staticmatic-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
108 lines (93 loc) · 3.19 KB
/
Rakefile
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#change these values if you deploy with rsync
ssh_user = "user@ip" # for rsync deployment
remote_root = "/var/www/html/ path /" # for rsync deployment
source = "src" #source directory (needed to auto-rebuild site on changes)
desc "Runs preview"
task :preview do
system "staticmatic preview ."
end
desc "Builds the site"
task :build => 'styles:clear' do
puts "*** Building the site ***"
system "staticmatic build ."
system "rake css_versioning"
system "rake build_php"
end
desc "Converts includes in html files to php. Usage: %php_include page-to-include.php"
task :build_php do
puts "*** Converting php includes ***"
Dir[File.expand_path('../site/**/*.html', __FILE__)].each do |file|
content = File.open(file).read
if content.index '<php_include>'
content = content.gsub(/<php_include>([^<]+)<\/php_include>/, '<?php include(\'../includes/\\1\'); ?>')
File.open(file.gsub(/\.html$/, '.php'), 'w+').puts content
File.unlink file
end
end
end
desc "Adds versioning to css. ie: application.1300696462.css"
task :css_versioning do
@versionned_css = 'application.' + Time.now.to_i.to_s + '.css'
puts "*** Adding css timestamp ***"
Dir[File.expand_path('../site/**/*.html', __FILE__)].each do |file|
content = File.open(file).read
content = content.gsub(/application.css/, @versionned_css)
File.open(file, 'w+').puts content
end
puts "*** Renaming CSS with timestamp ***"
copy("site/stylesheets/application.css", "site/stylesheets/" + @versionned_css)
end
desc "Clears and generates new styles, builds and deploys"
task :deploy => [:build, :push] do
puts "*** Deploying the site ***"
end
desc "Archives the site to site/archive.tar.gz"
task :zip do
puts "*** Archiving the site ***"
system("rm site/archive.tar.gz")
system("tar -czf archive.tar.gz site")
system("mv archive.tar.gz site/")
end
desc "push"
task :push do
system("rsync -avz --delete --exclude-from=.rsyncexclude site/ #{ssh_user}:#{remote_root}")
end
namespace :styles do
desc "Clears the styles"
task :clear do
puts "*** Clearing styles ***"
system "rm -Rfv site/stylesheets/*"
end
desc "Generates new styles"
task :generate do
puts "*** Generating styles ***"
system "compass compile"
end
end
def rebuild_site(relative)
puts "\n\n>>> Change Detected to: #{relative} <<<"
if (relative.include? ".sass") || (relative.include? ".scss")
IO.popen('rake styles:generate'){|io| print(io.readpartial(512)) until io.eof?}
puts '>>> Update Styles Complete <<<'
else
IO.popen('rake build'){|io| print(io.readpartial(512)) until io.eof?}
puts '>>> Update Site Complete <<<'
end
end
def rebuild_style(relative)
puts "\n\n>>> Change Detected to: #{relative} <<<"
IO.popen('rake styles:generate'){|io| print(io.readpartial(512)) until io.eof?}
puts '>>> Update Complete <<<'
end
desc "Watch the site and regenerate when it changes"
task :watch do
require 'fssm'
puts ">>> Watching for Changes <<<"
FSSM.monitor do
path "#{File.dirname(__FILE__)}/#{source}" do
update {|base, relative| rebuild_site(relative)}
delete {|base, relative| rebuild_site(relative)}
create {|base, relative| rebuild_site(relative)}
end
end
end