I’ve got a light-weight haml-based site that I’m building with Middleman (not Rails, but I’m tagging this with Rails because I think Rails people might know the answer).
Is it possible to define a function in-line in the haml file and then use it later in that same file?
(Yes, I know how to use separately-defined helper files. That’s not the question.)
I have a page with a function that is uniquely specialized to that page. Defining it in a helper file is to me an unnecessary separation.
Example:
-def foo(color,text)
-content_tag :p, style: "color: #{color}" do
-text
%html
%head
%title Demo page
%body
%h1 demo page
=foo("red", "this is red")
=foo("blue", "this is blue")
Rendering the above page results in undefined method 'foo'
.
Is there a way to make that work? (Did I define the function incorrectly?)