Skip to content

Commit

Permalink
Merge pull request #709 from xzyfer/feat/feature-exists
Browse files Browse the repository at this point in the history
Implement feature-exists()
  • Loading branch information
xzyfer committed Dec 10, 2014
2 parents 72f6643 + 439cf3d commit 1738c7f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ namespace Sass {
register_function(ctx, global_variable_exists_sig, global_variable_exists, env);
register_function(ctx, function_exists_sig, function_exists, env);
register_function(ctx, mixin_exists_sig, mixin_exists, env);
register_function(ctx, feature_exists_sig, feature_exists, env);
register_function(ctx, call_sig, call, env);
// Boolean Functions
register_function(ctx, not_sig, sass_not, env);
Expand Down
17 changes: 17 additions & 0 deletions functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <iomanip>
#include <iostream>
#include <random>
#include <set>

#define ARG(argname, argtype) get_arg<argtype>(argname, env, sig, path, position, backtrace)
#define ARGR(argname, argtype, lo, hi) get_arg_r(argname, env, sig, path, position, lo, hi, backtrace)
Expand Down Expand Up @@ -114,6 +115,9 @@ namespace Sass {
static random_device rd;
static mt19937 rand(rd());

// features
static set<string> features;

////////////////
// RGB FUNCTIONS
////////////////
Expand Down Expand Up @@ -1423,6 +1427,19 @@ namespace Sass {
}
}

Signature feature_exists_sig = "feature-exists($name)";
BUILT_IN(feature_exists)
{
string s = unquote(ARG("$name", String_Constant)->value());

if(features.find(s) == features.end()) {
return new (ctx.mem) Boolean(path, position, false);
}
else {
return new (ctx.mem) Boolean(path, position, true);
}
}

Signature call_sig = "call($name, $args...)";
BUILT_IN(call)
{
Expand Down
2 changes: 2 additions & 0 deletions functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ namespace Sass {
extern Signature global_variable_exists_sig;
extern Signature function_exists_sig;
extern Signature mixin_exists_sig;
extern Signature feature_exists_sig;
extern Signature call_sig;
extern Signature not_sig;
extern Signature if_sig;
Expand Down Expand Up @@ -167,6 +168,7 @@ namespace Sass {
BUILT_IN(global_variable_exists);
BUILT_IN(function_exists);
BUILT_IN(mixin_exists);
BUILT_IN(feature_exists);
BUILT_IN(call);
BUILT_IN(sass_not);
BUILT_IN(sass_if);
Expand Down

0 comments on commit 1738c7f

Please sign in to comment.