46 lines
918 B
Ruby
46 lines
918 B
Ruby
|
|
||
|
$gemsmith = {
|
||
|
active: nil,
|
||
|
stages: [],
|
||
|
}
|
||
|
|
||
|
def load_site(in_path, out_path)
|
||
|
Dir["#{in_path}/*"].map do |f|
|
||
|
out_f = "#{out_path}/#{File.basename f}"
|
||
|
if File.symlink? f then
|
||
|
$stderr.puts "Warning: Skipping symlink #{f}"
|
||
|
nil
|
||
|
elsif File.directory? f then
|
||
|
[File.basename(f), [:directory, load_site(f, out_f)]]
|
||
|
else
|
||
|
[File.basename(f), [:file, {
|
||
|
created: File.birthtime(f),
|
||
|
modified: File.mtime(f),
|
||
|
source_path: f,
|
||
|
dependencies: f,
|
||
|
out_path: out_f,
|
||
|
stages: [ proc { File.open(f) {|io| io.readlines} } ]
|
||
|
}]]
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
|
||
|
def site(site_name, params = {})
|
||
|
|
||
|
in_path = params.fetch(:src, "src")
|
||
|
out_path = params.fetch(:out, "build/#{site_name}")
|
||
|
|
||
|
$gemsmith[:active] = {
|
||
|
in_path: in_path,
|
||
|
out_path: out_path,
|
||
|
files: load_site(in_path)
|
||
|
}
|
||
|
|
||
|
directory $gemsmith[:active][:in_path]
|
||
|
directory $gemsmith[:active][:out_path]
|
||
|
|
||
|
yield
|
||
|
|
||
|
$gemsmith[:active] = nil
|
||
|
end
|