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

[RFC] Add an option for allowing the old .css import behaviour #1964

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 3 additions & 1 deletion src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ namespace Sass {
c_importers (std::vector<Sass_Importer_Entry>()),
c_functions (std::vector<Sass_Function_Entry>()),

css_imports (false),

indent (safe_str(c_options.indent, " ")),
linefeed (safe_str(c_options.linefeed, "\n")),

Expand Down Expand Up @@ -239,7 +241,7 @@ namespace Sass {
for (size_t i = 0, S = include_paths.size(); vec.size() == 0 && i < S; ++i)
{
// call resolve_includes and individual base path and append all results
std::vector<Include> resolved(resolve_includes(include_paths[i], import.imp_path));
std::vector<Include> resolved(resolve_includes(include_paths[i], import.imp_path, c_options.css_imports));
if (resolved.size()) vec.insert(vec.end(), resolved.begin(), resolved.end());
}
// return vector
Expand Down
1 change: 1 addition & 0 deletions src/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace Sass {
void add_c_importer(Sass_Importer_Entry importer);
void add_c_function(Sass_Function_Entry function);

const bool css_imports; // should @import consider .css files
const std::string indent; // String to be used for indentation
const std::string linefeed; // String to be used for line feeds
const std::string input_path; // for relative paths in src-map
Expand Down
11 changes: 8 additions & 3 deletions src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,18 @@ namespace Sass {
// (2) underscore + given
// (3) underscore + given + extension
// (4) given + extension
std::vector<Include> resolve_includes(const std::string& root, const std::string& file)
std::vector<Include> resolve_includes(const std::string& root, const std::string& file, const bool css_imports)
{
std::string filename = join_paths(root, file);
// supported extensions
const std::vector<std::string> exts = {
".scss", ".sass", ".css"
std::vector<std::string> exts = {
".sass", ".scss"
};

if (css_imports) {
exts.push_back(".css");
}

// split the filename
std::string base(dir_name(file));
std::string name(base_name(file));
Expand Down
2 changes: 1 addition & 1 deletion src/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace Sass {

namespace File {

std::vector<Include> resolve_includes(const std::string& root, const std::string& file);
std::vector<Include> resolve_includes(const std::string& root, const std::string& file, const bool css_imports = false);

}

Expand Down
2 changes: 2 additions & 0 deletions src/sass_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ extern "C" {
options->precision = 5;
options->indent = " ";
options->linefeed = LFEED;
options->css_imports = false;
}

Sass_Options* ADDCALL sass_make_options (void)
Expand Down Expand Up @@ -655,6 +656,7 @@ extern "C" {
IMPLEMENT_SASS_OPTION_ACCESSOR(bool, source_map_contents);
IMPLEMENT_SASS_OPTION_ACCESSOR(bool, omit_source_map_url);
IMPLEMENT_SASS_OPTION_ACCESSOR(bool, is_indented_syntax_src);
IMPLEMENT_SASS_OPTION_ACCESSOR(bool, css_imports);
IMPLEMENT_SASS_OPTION_ACCESSOR(Sass_Function_List, c_functions);
IMPLEMENT_SASS_OPTION_ACCESSOR(Sass_Importer_List, c_importers);
IMPLEMENT_SASS_OPTION_ACCESSOR(Sass_Importer_List, c_headers);
Expand Down
6 changes: 5 additions & 1 deletion src/sass_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ struct Sass_Options : Sass_Output_Options {
// Treat source_string as sass (as opposed to scss)
bool is_indented_syntax_src;

// Whether .css files should be considered
// when resolving @import
bool css_imports;

// The input path is used for source map
// generation. It can be used to define
// something with string compilation or to
Expand Down Expand Up @@ -124,4 +128,4 @@ struct Sass_Compiler {
Sass::Block* root;
};

#endif
#endif