SassyHash

Introducing SassyHash

In Sass 3.3 maps were introducted. When creating a map from within a Sass extension you need to pass in a hash that has its keys and values be instances of Sass::Script::Value::*.

hash = {Sass::Script::Value::String.new('foo') => Sass::Script::Value::String.new('bar')}
map = Sass::Script::Value::Map.new(hash)

SassyHash is a courier class for transforming ruby hashes into something that Sass maps can accept.

Examples

Standard Example

hash = {:foo => :bar}
map = Sass::Script::Value::Map.new(SassyHash[hash])
map.class #=> Sass::Script::Value::Map

It also works with nested hashes lists etc..

hash = {:foo => :bar => :baz}
map = Sass::Script::Value::Map.new(SassyHash[hash])
map.value[Sass::Script::Value::String.new('foo')].class #=> Sass::Script::Value::Map

Links

Comments