Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.2] Bubble media queries #800

Merged
merged 4 commits into from
Jan 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ SOURCES = \
context.cpp \
contextualize.cpp \
copy_c_str.cpp \
cssize.cpp \
error_handling.cpp \
eval.cpp \
expand.cpp \
Expand Down Expand Up @@ -127,14 +128,14 @@ SOURCES = \

CSOURCES = cencode.c

RESOURCES =
RESOURCES =

LIBRARIES = lib/libsass.so

ifeq (MinGW,$(UNAME))
ifeq (shared,$(BUILD))
CFLAGS += -D ADD_EXPORTS
CXXFLAGS += -D ADD_EXPORTS
CFLAGS += -D ADD_EXPORTS
CXXFLAGS += -D ADD_EXPORTS
LIBRARIES += lib/libsass.dll
RESOURCES += res/resource.rc
endif
Expand Down
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ libsass_la_SOURCES = \
eval.cpp eval.hpp \
expand.cpp expand.hpp \
extend.cpp extend.hpp \
cssize.cpp cssize.hpp \
file.cpp file.hpp \
functions.cpp functions.hpp \
inspect.cpp inspect.hpp \
Expand Down
49 changes: 46 additions & 3 deletions ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ namespace Sass {
virtual ~Vectorized() = 0;
size_t length() const { return elements_.size(); }
bool empty() const { return elements_.empty(); }
T last() { return elements_.back(); }
T& operator[](size_t i) { return elements_[i]; }
const T& operator[](size_t i) const { return elements_[i]; }
Vectorized& operator<<(T element)
Expand All @@ -187,6 +188,11 @@ namespace Sass {
for (size_t i = 0, L = v->length(); i < L; ++i) *this << (*v)[i];
return *this;
}
Vectorized& unshift(T element)
{
elements_.insert(elements_.begin(), element);
return *this;
}
vector<T>& elements() { return elements_; }
const vector<T>& elements() const { return elements_; }
vector<T>& elements(vector<T>& e) { elements_ = e; return elements_; }
Expand Down Expand Up @@ -258,11 +264,30 @@ namespace Sass {
/////////////////////////////////////////////////////////////////////////
class Statement : public AST_Node {
public:
Statement(string path, Position position) : AST_Node(path, position) { }
enum Statement_Type {
NONE,
RULESET,
MEDIA,
DIRECTIVE,
KEYFRAME,
FEATURE,
BUBBLE
};
private:
ADD_PROPERTY(Block*, block);
ADD_PROPERTY(Statement_Type, statement_type);
ADD_PROPERTY(size_t, tabs);
ADD_PROPERTY(bool, group_end);
public:
Statement(string path, Position position, Statement_Type st = NONE, size_t t = 0)
: AST_Node(path, position),
statement_type_(st), tabs_(t), group_end_(false)
{ }
virtual ~Statement() = 0;
// needed for rearranging nested rulesets during CSS emission
virtual bool is_hoistable() { return false; }
virtual bool is_invisible() { return false; }
virtual bool bubbles() { return false; }
virtual Block* block() { return 0; }
};
inline Statement::~Statement() { }
Expand Down Expand Up @@ -314,7 +339,7 @@ namespace Sass {
public:
Ruleset(string path, Position position, Selector* s, Block* b)
: Has_Block(path, position, b), selector_(s)
{ }
{ statement_type(RULESET); }
bool is_invisible();
// nested rulesets need to be hoisted out of their enclosing blocks
bool is_hoistable() { return true; }
Expand All @@ -334,6 +359,20 @@ namespace Sass {
ATTACH_OPERATIONS();
};

/////////////////
// Bubble.
/////////////////
class Bubble : public Statement {
ADD_PROPERTY(Statement*, node);
ADD_PROPERTY(Statement*, group_end);
public:
Bubble(string path, Position position, Statement* n, Statement* g = 0, size_t t = 0)
: Statement(path, position, Statement::BUBBLE, t), node_(n), group_end_(g)
{ }
bool bubbles() { return true; }
ATTACH_OPERATIONS();
};

/////////////////
// Media queries.
/////////////////
Expand All @@ -344,7 +383,11 @@ namespace Sass {
public:
Media_Block(string path, Position position, List* mqs, Block* b)
: Has_Block(path, position, b), media_queries_(mqs), selector_(0)
{ }
{ statement_type(MEDIA); }
Media_Block(string path, Position position, List* mqs, Block* b, Selector* s)
: Has_Block(path, position, b), media_queries_(mqs), selector_(s)
{ statement_type(MEDIA); }
bool bubbles() { return true; }
bool is_hoistable() { return true; }
bool is_invisible() {
bool is_invisible = true;
Expand Down
1 change: 1 addition & 0 deletions ast_fwd_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Sass {
class Block;
class Ruleset;
class Propset;
class Bubble;
class Media_Block;
class Feature_Block;
class At_Rule;
Expand Down
3 changes: 3 additions & 0 deletions context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "expand.hpp"
#include "eval.hpp"
#include "contextualize.hpp"
#include "cssize.hpp"
#include "extend.hpp"
#include "remove_placeholders.hpp"
#include "copy_c_str.hpp"
Expand Down Expand Up @@ -282,10 +283,12 @@ namespace Sass {
Eval eval(*this, &tge, &backtrace);
Contextualize contextualize(*this, &eval, &tge, &backtrace);
Expand expand(*this, &eval, &contextualize, &tge, &backtrace);
Cssize cssize(*this, &tge);
// Inspect inspect(this);
// Output_Nested output_nested(*this);

root = root->perform(&expand)->block();
root = root->perform(&cssize)->block();
if (!subset_map.empty()) {
Extend extend(*this, subset_map);
root->perform(&extend);
Expand Down
Loading