Adding a CGI utility
Hey!
I personally sometimes use slim as a CGI utility. slimrb works fine for this but to set the headers I use a little ruby prefix like
ruby:
require "cgi"
puts CGI.new.http_header "text/html"
# rest of template
This is needed to adhere to the CGI specifications. Additionally this method cannot be used to correctly set the Content-Size.
So now I use a little helper utility command called slimcgi which looks like this:
#!/usr/bin/env ruby
require "cgi"
require "slim"
$cgi = CGI.new
$cgi.out("text/html") do
Slim::Template.new { ARGF.read }.render
end
It exposes the CGI class to the template and correctly sets the headers.
Do you think a utility like this could be added to this repository?
We could add an option --cgi to slimrb if that would help?
I think that would be a decent solution, with the downside that maybe not all webservers could support it. I can particularly think of lighttpd that does not allow to add arguments to CGI binaries. But as long as ~~spawn-fcgi~~ fcgiwrap works, which is the most common usecase then I think it's fine.
I added such a flag here https://github.com/LevitatingBusinessMan/slim/tree/cgi and am currently trying to do some tests with it.