Website/lib/gemsmith.rb

46 lines
918 B
Ruby
Raw Normal View History

2016-05-24 14:05:21 -04:00
$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