Closed rubytastic closed 13 years ago
I'm interested in this feature, but it's currently not implemented. There are other engines that do this kind of thing though. Nanoc is an example: http://nanoc.stoneship.org/
This would be a great feature. I've been a part of many projects where haml is not wanted beyond the prototype stage. A full export would allow mockups in haml, without having to sell the rest of the team on the somewhat tedious task of converting new versions of each page to html as the app progresses.
staticmatic have a nice build module that could do most of the work... http://github.com/staticmatic/staticmatic/blob/master/lib/staticmatic/mixins/build.rb
It would work for Haml, but Serve handles ERB and other formats as well.
I wrote a rake task for exporting a static version.
It copies the static assets and loads from the serve those sass and haml files that don't start with underscore and saves them as css and html files. If links point to regular css and html files, they work in both static and dynamic versions.
Note that your folder structure might be different.
require 'ftools'
require 'open-uri'
site_root = 'http://localhost:4000/'
output_dir = 'deploy/'
desc "Spider the site #{site_root} and save the files under #{output_dir}"
task :spider do
FileUtils.rm_rf(Dir.glob("#{output_dir}*"))
files_to_copy = Dir.glob("public/**/[^_]*.{gif,png,jpg,css,js,ico,html}")
files_to_copy.each do |path|
save_path = output_dir + path.gsub(/^public\//, "")
FileUtils.mkdir_p(File.dirname(save_path))
File.copy(path, save_path, true)
end
files_to_spider = []
files_to_spider += Dir.glob("views/**/[^_]*.html.haml").map{|f|f.gsub(/^views\//, "").gsub(".haml", "")}
files_to_spider += Dir.glob("stylesheets/**/[^_]*.sass").map{|f|f.gsub(".sass", ".css")}
files_to_spider.each do |path|
save_path = output_dir + path
puts "#{path} -> #{output_dir + path}"
FileUtils.mkdir_p(File.dirname(save_path))
open(site_root + path, 'rb') do |input|
File.open(save_path, 'wb') do |output|
output.write(input.read)
end
end
end
end
plus 1 for this feature!
I was thinking of what could be great addition to serve,
adding an option to the command line like: serve --export adding output_dir = /html to config file
Then if run seve --export it will render all haml files to html files inside the output_dir
I found a snippet of code to write the haml to html
http://gist.github.com/17371
Any ideas on this? Currently I copy and paste the html from the browser, is there a better way? ( I do design in haml but need the html output for cms implementation )