> Very much like you have middlewares in Rack, you use compilers in Temple (except everything is a compiler in Temple):
So, let me ask the obvious question: why not be like rack and name the
method "call", so we can uses lambdas as compilers?
That would also avoid some of the semantic confusion around using the
term "compile" for parsers and generators.
Thoughts?
-- Ernie P.
Currently a compiler has to be a class, so you can't really use a
lambda. I think, the only reason for this is because I prefer the
options in the initialize-method ("use C, :foo => :bar" == "C.new(:foo
=> :bar)", but maybe we could support both, like:
if C.is_a? Class
C.new(:foo => :bar).call(str)
elsif C.respond_to?(:compile)
C.call(str, :foo => :bar)
else
raise "IMMA LET YOU FINISH, BUT ERUBIS IS THE GREATEST COMPILER OF ALL TIME"
end
//Magnus Holm
On Dec 18, 2009, at 12:18 PM, Magnus Holm wrote:
> Good points. The naming is a bit unfortunately, but (of course) makes
> totally sense in my head :P
>
> Currently a compiler has to be a class, so you can't really use a
> lambda. I think, the only reason for this is because I prefer the
> options in the initialize-method ("use C, :foo => :bar" == "C.new(:foo
> => :bar)", but maybe we could support both, like:
>
> if C.is_a? Class
> C.new(:foo => :bar).call(str)
> elsif C.respond_to?(:compile)
> C.call(str, :foo => :bar)
> else
> raise "IMMA LET YOU FINISH, BUT ERUBIS IS THE GREATEST COMPILER OF ALL TIME"
> end
Okay, I'm showing my ignorance here, but how does Rack handle this? Does it accept instances or classes?
-- Ernie P.
First of all: An endpoint (aka. application) is just a object.respond_to?(:call)
Middlewares are just a convention where you set
Middleware.new(prev_endpoint) as your endpoint. If Middleware has a
#call, it will look exactly as an endpoint to a Rack server/handler,
and it doesn't have to worry about that it's a middleware at all.
In Temple however, we only send output from one compiler as input to
another compiler. Since input/output is the "same" thing, while a
request/response in Rack are completely different.
I'm definitely in for renaming the word "compiling" if it seems to
confuse people though. But, it might actually be a good thing to teach
people that a compiler really isn't magic at all, but only something
which takes some input and generates some output.
//Magnus Holm