Parser¶
Parser is in charge to find every @import rules in given Sass content.
It has been built following Sass Reference about @import rule.
Note
Sass indented syntax parser has a flaw which cause multiline comments to be
incorrectly parsed. If you have commented @import in multiline comments
they will be matched as true importations to resolve and inspect, it can leads
to some errors.
The only way is to not use multiline comments when you use the Sass index syntax.
- class boussole.parser.ScssImportsParser[source]¶
SCSS parser to find
@importrules.This does not support the old Sass syntax (also known as “indented syntax”).
It’s a mixin, meaning without own
__init__method so it’s should be safe enough to inherit it from another class.- REGEX_IMPORT_RULE¶
Compiled regex used to find
@importrules.
- REGEX_COMMENTS¶
Compiled regex used to find and remove comments.
- strip_quotes(content)[source]¶
Unquote given rule.
- Parameters
content (str) – An import rule.
- Raises
InvalidImportRule – Raise exception if the rule is badly quoted (not started or not ended quotes).
- Returns
The given rule unquoted.
- Return type
string
- remove_comments(content)[source]¶
Remove all comment kind (inline and multiline) from given content.
- Parameters
content (str) – A SCSS source.
- Returns
Given SCSS source with all comments removed.
- Return type
string
- filter_rules(path)[source]¶
Lambda to filter items that: * Starts with http:// or https:// (this for external load only) * Ends with “.css” (they are not intended to be compiled)
- flatten_rules(declarations)[source]¶
Flatten returned import rules from regex.
Because import rules can contains multiple items in the same rule (called multiline import rule), the regex
REGEX_IMPORT_RULEreturn a list of unquoted items for each rule.- Parameters
declarations (list) – A SCSS source.
- Returns
Given SCSS source with all comments removed.
- Return type
list
- class boussole.parser.SassImportsParser[source]¶
Sass indented syntax parser to find
@importrules.Multiline comments are not supported, it is actually too difficult to manage since they don’t have a closing pattern
*/and depend only on indentation continuation.- REGEX_IMPORT_RULE¶
Compiled regex used to find
@importrules.