Class: SassC::FunctionsHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/sassc/embedded.rb

Instance Method Summary collapse

Instance Method Details

#setup(_native_options, functions: Script::Functions) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/sassc/embedded.rb', line 135

def setup(_native_options, functions: Script::Functions)
  functions_wrapper = Class.new do
    attr_accessor :options

    include functions
  end.new
  functions_wrapper.options = @options

  Script.custom_functions(functions:).each_with_object({}) do |custom_function, callbacks|
    callback = lambda do |native_argument_list|
      function_arguments = arguments_from_native_list(native_argument_list)
      result = functions_wrapper.send(custom_function, *function_arguments)
      to_native_value(result)
    rescue StandardError => e
      error(e.message)
      raise
    end

    callbacks[Script.formatted_function_name(custom_function, functions:)] = callback
  end
end