Closed billsaysthis closed 12 years ago
All Sass functions are evaluated in a context where the options passed to sass can be accessed via a method named options
.
From the docs (http://compass-style.org/reference/compass/helpers/image-dimensions/#image-height) and source[1] I don't see why my code[2] is causing this error.
[1] image_size.rb
# Returns the height of the image relative to the images directory
def image_height(image_file)
_, height = image_dimensions(image_file)
Sass::Script::Number.new(height, ["px"])
end
[2] application_helper.rb
if user.m_logo.is_a?(String)
ih = image_height(Sass::Script::String.new(user.m_logo))
ic = (ih.to_i > 115) ? 'logoHT' : 'logoWD'
link_to image_tag(user.m_logo, :alt => user.name), user.url, :class => ic
else
'Not a string'
end
Because your code doesn't define the options
method.
Where in the docs is this explained? I'm happy if all I need to do is fix my code up a bit but so far you haven't shown me where this is described.
I don't think there are any docs on this use case because your using a sass function in a rails helper which is pretty far outside of the normal use case and chris is right its because your not defining options.
is calling the image_dimensions method which is trying to access the options hash.
try adding
def options {} end
to your application helper that should solve the issue but beware it may just cause another error these methods are not intended to be used this way
It is documented from here:
http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html
You're not using our code as intended, so I expected you to be able to do this research yourself.
Hunt & pecked on my iPhone... Sorry if it's brief!
On Jan 1, 2012, at 5:29 PM, billsaysthisreply@reply.github.com wrote:
Where in the docs is this explained? I'm happy if all I need to do is fix my code up a bit but so far you haven't shown me where this is described.
Reply to this email directly or view it on GitHub: https://github.com/chriseppstein/compass/issues/661#issuecomment-3326852
I guess since this worked properly under previous versions of Rails/Compass I expected it to continue as the app code is unchanged. Thanks for taking the time to respond.
Using Rails 3.1 and asset pipeline with Compass 0.12.alpha3 in Gemfile gets an error using the image_height function (in application_helper.rb):
Calling code is:
Stack trace
Same code works correctly in Rails 3.0.11.