3 ms·
For more complicated sites I use Rails and a rake task to generate the html files, e.g., ```ruby namespace :app do desc "Generate static pages" task
by andersonmvd 10y ago
For more complicated sites I use Rails and a rake task to generate the html files, e.g.,
```ruby
namespace :app do
desc "Generate static pages"
task static: :environment do
pages = {
'/' => 'index.html'
}
app = ActionDispatch::Integration::Session.new(Rails.application)
pages.each do |route, output|
puts "Generating #{output}..."
outpath = File.join ([Rails.root, 'public', output])
resp = app.get(route)
if resp == 200
File.delete(outpath) if File.exists?(outpath)
if app.response.body.empty?
puts "[ no content ]"
else
encoded_body = app.response.body.encode(
'UTF-8',
{:invalid => :replace, :undef => :replace, :replace => '?'}
)
File.open(outpath, 'w') do |f|
f.write(encoded_body)
end
end
else
puts "Error generating #{output}!"
end
end
end
end
```
- eli 10y agoThe Python equivalent is something like Flask-Frozen.