Skip to content

Commit

Permalink
Add get method for environment class
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Mar 17, 2018
1 parent 6e79ff7 commit 090bab3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/environment.cpp
Expand Up @@ -206,6 +206,20 @@ namespace Sass {
}
};

// use array access for getter and setter functions
template <typename T>
T& Environment<T>::get(const std::string& key)
{
auto cur = this;
while (cur) {
if (cur->has_local(key)) {
return cur->get_local(key);
}
cur = cur->parent_;
}
return get_local(key);
}

// use array access for getter and setter functions
template <typename T>
T& Environment<T>::operator[](const std::string& key)
Expand Down
5 changes: 5 additions & 0 deletions src/environment.hpp
Expand Up @@ -7,6 +7,7 @@

namespace Sass {

// this defeats the whole purpose of environment being templatable!!
typedef environment_map<std::string, AST_Node_Obj>::iterator EnvIter;

class EnvResult {
Expand Down Expand Up @@ -92,6 +93,10 @@ namespace Sass {
// include all scopes available
bool has(const std::string& key) const;

// look on the full stack for key
// include all scopes available
T& get(const std::string& key);

// look on the full stack for key
// include all scopes available
EnvResult find(const std::string& key);
Expand Down

0 comments on commit 090bab3

Please sign in to comment.