Permalink
Browse files

Implemented the ie-hex-str built-in function.

  • Loading branch information...
1 parent c8971fe commit cb7d0661c57f3208f5b10f72de1ee913ccb733af Aaron Leung committed Nov 27, 2012
Showing with 35 additions and 1 deletion.
  1. +2 −1 context.cpp
  2. +10 −0 functions.cpp
  3. +3 −0 functions.hpp
  4. +1 −0 node.hpp
  5. +19 −0 node_emitters.cpp
View
@@ -144,7 +144,8 @@ namespace Sass {
// Other Color Functions
register_function(adjust_color_sig, adjust_color);
register_function(scale_color_sig, scale_color);
- register_function(change_color_sig, change_color);
+ register_function(change_color_sig, change_color);
+ register_function(ie_hex_str_sig, ie_hex_str);
// String Functions
register_function(unquote_sig, unquote);
register_function(quote_sig, quote);
View
@@ -737,6 +737,16 @@ namespace Sass {
return Node();
}
+ extern Signature ie_hex_str_sig = "ie-hex-str($color)";
+ Node ie_hex_str(const Node parameter_names, Environment& bindings, Node_Factory& new_Node, Backtrace& bt, string& path, size_t line) {
+ Node color(arg(ie_hex_str_sig, path, line, parameter_names, bindings, 0, Node::numeric_color, bt));
+ Node result(new_Node(Node::ie_hex_str, color.path(), color.line(), 4));
+ result << color[0] << color[1] << color[2] << color[3];
+ Node wrapped_result(new_Node(Node::concatenation, color.path(), color.line(), 1));
+ wrapped_result << result;
+ return wrapped_result;
+ }
+
////////////////////////////////////////////////////////////////////////
// String Functions ////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
View
@@ -158,6 +158,9 @@ namespace Sass {
extern Signature change_color_sig;
Node change_color(const Node, Environment&, Node_Factory&, Backtrace&, string& path, size_t line);
+ extern Signature ie_hex_str_sig;
+ Node ie_hex_str(const Node, Environment&, Node_Factory&, Backtrace&, string& path, size_t line);
+
// String Functions ////////////////////////////////////////////////////
extern Signature unquote_sig;
View
@@ -142,6 +142,7 @@ namespace Sass {
numeric_percentage,
numeric_dimension,
numeric_color,
+ ie_hex_str,
boolean,
important,
View
@@ -278,6 +278,25 @@ namespace Sass {
return ss.str();
}
} break;
+
+ case ie_hex_str: {
+ stringstream ss;
+ ss << '#' << std::setw(2) << std::setfill('0') << std::hex;
+
+ double x = at(3).numeric_value() * 255;
+ if (x > 0xff) x = 0xff;
+ else if (x < 0) x = 0;
+ ss << std::hex << std::setw(2) << std::uppercase << static_cast<unsigned long>(std::floor(x+0.5));
+
+ for (size_t i = 0; i < 3; ++i) {
+ double x = at(i).numeric_value();
+ if (x > 0xff) x = 0xff;
+ else if (x < 0) x = 0;
+ ss << std::hex << std::setw(2) << std::uppercase << static_cast<unsigned long>(std::floor(x+0.5));
+ }
+
+ return ss.str();
+ } break;
case uri: {
string result("url(");

0 comments on commit cb7d066

Please sign in to comment.