Text-Sass-XS
view release on metacpan or search on metacpan
libsass/inspect.cpp view on Meta::CPAN
#include "inspect.hpp"
#include "ast.hpp"
#include "context.hpp"
#include <cmath>
#include <iostream>
#include <iomanip>
namespace Sass {
using namespace std;
Inspect::Inspect(Context* ctx) : buffer(""), indentation(0), ctx(ctx) { }
Inspect::~Inspect() { }
// statements
void Inspect::operator()(Block* block)
{
if (!block->is_root()) {
buffer += " {\n";
++indentation;
}
for (size_t i = 0, L = block->length(); i < L; ++i) {
indent();
(*block)[i]->perform(this);
// extra newline at the end of top-level statements
if (block->is_root()) buffer += '\n';
buffer += '\n';
}
if (!block->is_root()) {
--indentation;
indent();
buffer += "}";
}
// remove extra newline that gets added after the last top-level block
if (block->is_root()) {
size_t l = buffer.length();
if (l > 2 && buffer[l-1] == '\n' && buffer[l-2] == '\n')
buffer.erase(l-1);
}
}
void Inspect::operator()(Ruleset* ruleset)
{
ruleset->selector()->perform(this);
ruleset->block()->perform(this);
}
void Inspect::operator()(Propset* propset)
{
propset->property_fragment()->perform(this);
buffer += ": ";
propset->block()->perform(this);
}
void Inspect::operator()(Media_Block* media_block)
{
buffer += "@media ";
media_block->media_queries()->perform(this);
media_block->block()->perform(this);
}
void Inspect::operator()(At_Rule* at_rule)
{
buffer += at_rule->keyword();
if (at_rule->selector()) {
buffer += ' ';
at_rule->selector()->perform(this);
}
if (at_rule->block()) {
at_rule->block()->perform(this);
}
else {
buffer += ';';
}
}
void Inspect::operator()(Declaration* dec)
{
dec->property()->perform(this);
buffer += ": ";
dec->value()->perform(this);
if (dec->is_important()) buffer += " !important";
buffer += ';';
}
void Inspect::operator()(Assignment* assn)
{
buffer += assn->variable();
buffer += ": ";
assn->value()->perform(this);
if (assn->is_guarded()) buffer += " !default";
buffer += ';';
}
void Inspect::operator()(Import* import)
{
if (!import->urls().empty()) {
buffer += "@import ";
import->urls().front()->perform(this);
buffer += ';';
for (size_t i = 1, S = import->urls().size(); i < S; ++i) {
buffer += "\n@import ";
import->urls()[i]->perform(this);
buffer += ';';
}
}
}
void Inspect::operator()(Import_Stub* import)
{
buffer += "@import ";
buffer += import->file_name();
( run in 0.814 second using v1.01-cache-2.11-cpan-71847e10f99 )