diff --git a/context.cpp b/context.cpp index bc6027ddc..fff9adc71 100644 --- a/context.cpp +++ b/context.cpp @@ -467,6 +467,7 @@ namespace Sass { // Path Functions register_function(ctx, image_url_sig, image_url, env); // Misc Functions + register_function(ctx, inspect_sig, inspect, env); register_function(ctx, unique_id_sig, unique_id, env); } diff --git a/functions.cpp b/functions.cpp index 2748acf37..df4331a86 100644 --- a/functions.cpp +++ b/functions.cpp @@ -1481,6 +1481,18 @@ namespace Sass { // MISCELLANEOUS FUNCTIONS ////////////////////////// + Signature inspect_sig = "inspect($value)"; + BUILT_IN(inspect) + { + Expression* v = ARG("$value", Expression); + if (v->concrete_type() == Expression::NULL_VAL) { + return new (ctx.mem) String_Constant(path, position, "null"); + } else if (v->concrete_type() == Expression::BOOLEAN && *v == 0) { + return new (ctx.mem) String_Constant(path, position, "false"); + } + return v; + } + Signature unique_id_sig = "unique-id()"; BUILT_IN(unique_id) { diff --git a/functions.hpp b/functions.hpp index 94d64e7fb..c9df02489 100644 --- a/functions.hpp +++ b/functions.hpp @@ -75,6 +75,7 @@ namespace Sass { extern Signature abs_sig; extern Signature min_sig; extern Signature max_sig; + extern Signature inspect_sig; extern Signature random_sig; extern Signature length_sig; extern Signature nth_sig; @@ -148,6 +149,7 @@ namespace Sass { BUILT_IN(abs); BUILT_IN(min); BUILT_IN(max); + BUILT_IN(inspect); BUILT_IN(random); BUILT_IN(length); BUILT_IN(nth); diff --git a/inspect.cpp b/inspect.cpp index c412922d7..cc0412c6e 100644 --- a/inspect.cpp +++ b/inspect.cpp @@ -232,6 +232,24 @@ namespace Sass { append_to_buffer("@content;"); } + void Inspect::operator()(Map* map) + { + if (map->empty()) return; + if (map->is_invisible()) return; + bool items_output = false; + append_to_buffer("("); + for (auto key : map->keys()) { + if (key->is_invisible()) continue; + if (map->at(key)->is_invisible()) continue; + if (items_output) append_to_buffer(", "); + key->perform(this); + append_to_buffer(": "); + map->at(key)->perform(this); + items_output = true; + } + append_to_buffer(")"); + } + void Inspect::operator()(List* list) { string sep(list->separator() == List::SPACE ? " " : ", "); diff --git a/inspect.hpp b/inspect.hpp index 8e629d503..628de6af1 100644 --- a/inspect.hpp +++ b/inspect.hpp @@ -59,6 +59,7 @@ namespace Sass { virtual void operator()(Mixin_Call*); virtual void operator()(Content*); // expressions + virtual void operator()(Map*); virtual void operator()(List*); virtual void operator()(Binary_Expression*); virtual void operator()(Unary_Expression*);