Skip to content

Commit

Permalink
Code style
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Oct 17, 2024
1 parent 39b3710 commit d321cc8
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions lib/sassc/embedded.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,14 @@ class FunctionsHandler
remove_method(:setup) if public_method_defined?(:setup, false)

def setup(_native_options, functions: Script::Functions)
@callbacks = {}

functions_wrapper = Class.new do
attr_accessor :options

include functions
end.new
functions_wrapper.options = @options

Script.custom_functions(functions:).each do |custom_function|
Script.custom_functions(functions:).map.with_object({}) do |custom_function, callbacks|
callback = lambda do |native_argument_list|
function_arguments = arguments_from_native_list(native_argument_list)
begin
Expand All @@ -162,10 +160,8 @@ def setup(_native_options, functions: Script::Functions)
raise e
end

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

@callbacks
end

private
Expand Down Expand Up @@ -375,8 +371,7 @@ def import_to_native(import, parent_dir, from_import, canonicalize)
canonical_url = Uri.path_to_file_url(File.absolute_path(import.path, parent_dir))
@importer_results[canonical_url] = if import.source.is_a?(Hash)
{
contents: import.source[:contents],
syntax: import.source[:syntax],
**import.source,
source_map_url: canonical_url
}
else
Expand Down Expand Up @@ -500,7 +495,7 @@ def self.from_native(value, options)
)
when ::Sass::Value::Map
::SassC::Script::Value::Map.new(
value.contents.to_a.to_h { |k, v| [from_native(k, options), from_native(v, options)] }
value.contents.map.with_object({}) { |(k, v), h| h[from_native(k, options)] = from_native(v, options) }
)
when ::Sass::Value::Number
::SassC::Script::Value::Number.new(
Expand Down Expand Up @@ -563,7 +558,7 @@ def self.to_native(value)
)
when ::SassC::Script::Value::Map
::Sass::Value::Map.new(
value.value.to_a.to_h { |k, v| [to_native(k), to_native(v)] }
value.value.map.with_object({}) { |(k, v), h| h[to_native(k)] = to_native(v) }
)
when ::SassC::Script::Value::Number
::Sass::Value::Number.new(
Expand Down Expand Up @@ -629,8 +624,8 @@ def parse(...)
decode_uri_hash_with_preserve_escaped = if unescaped.nil? || unescaped.empty?
decode_uri_hash
else
decode_uri_hash.to_h do |key, value|
[key, unescaped.include?(value) ? key : value]
decode_uri_hash.map.with_object({}) do |(key, value), hash|
hash[key] = unescaped.include?(value) ? key : value
end.freeze
end

Expand Down

0 comments on commit d321cc8

Please sign in to comment.