slim icon indicating copy to clipboard operation
slim copied to clipboard

Adding a CGI utility

Open LevitatingBusinessMan opened this issue 1 year ago • 2 comments

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?

LevitatingBusinessMan avatar Dec 11 '24 03:12 LevitatingBusinessMan

We could add an option --cgi to slimrb if that would help?

minad avatar Dec 24 '24 07:12 minad

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.

LevitatingBusinessMan avatar Dec 24 '24 16:12 LevitatingBusinessMan