Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 090bab3

Browse files
committed
Add get method for environment class
1 parent 6e79ff7 commit 090bab3

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/environment.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,20 @@ namespace Sass {
206206
}
207207
};
208208

209+
// use array access for getter and setter functions
210+
template <typename T>
211+
T& Environment<T>::get(const std::string& key)
212+
{
213+
auto cur = this;
214+
while (cur) {
215+
if (cur->has_local(key)) {
216+
return cur->get_local(key);
217+
}
218+
cur = cur->parent_;
219+
}
220+
return get_local(key);
221+
}
222+
209223
// use array access for getter and setter functions
210224
template <typename T>
211225
T& Environment<T>::operator[](const std::string& key)

src/environment.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Sass {
99

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

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

96+
// look on the full stack for key
97+
// include all scopes available
98+
T& get(const std::string& key);
99+
95100
// look on the full stack for key
96101
// include all scopes available
97102
EnvResult find(const std::string& key);

0 commit comments

Comments
 (0)