how to migrate ruby-sass custom functions to sassc?

Viewed 207

How do I migrate this ruby sass custom function to SassC? In a rails project, I just included this module in my application.rb and the likes of my-method would be available in my sass files.

The ruby sass EOL blog post suggests I should just sub "SassC" for "Sass" but that doesn't work. Digging in I don't see any of these methods (assert_type or prepend_host) defined in SassC either.

Thanks!

module Sass::Script::Functions

  def my_method(string)
    assert_type string, :String

    prepend_host('https://cdn.host.com', string)
  end
  declare :my_method, [:string]
end

Other blog post describing the implementation: http://www.seancolombo.com/2010/07/28/how-to-make-and-use-a-custom-sass-function/

1 Answers

For the assert_type function, you can try something from here https://github.com/sass/sassc-ruby/blob/61a02d1d88b489f83b5b3d0da48a9b62f210691b/lib/sassc/script/value_conversion.rb

SassC::Native.value_get_tag(string) == :sass_string

You could try to replicate the assert_type function if you want to raise an error too, check this https://github.com/sass/ruby-sass/blob/1ed4e31033dd0bff4da27d1f21c531e1fdaccaab/lib/sass/script/functions.rb#L533

I can't find that prepend_host method on ruby-sass codebase. I'm not sure what it actually do to suggest a replacement.

Related