1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# ----------------------------------------------------------------------------- |
3
|
|
|
# Copyright (c) 2015 Yann Lanthony |
4
|
|
|
# Copyright (c) 2017-2018 Spyder Project Contributors |
5
|
|
|
# |
6
|
|
|
# Licensed under the terms of the MIT License |
7
|
|
|
# (See LICENSE.txt for details) |
8
|
|
|
# ----------------------------------------------------------------------------- |
9
|
|
|
"""Libsass importers.""" |
10
|
|
|
|
11
|
|
|
# Standard library imports |
12
|
|
|
from __future__ import absolute_import |
13
|
|
|
import os |
14
|
|
|
|
15
|
|
|
# Local imports |
16
|
|
|
from qtsass.conformers import scss_conform |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
def qss_importer(where): |
20
|
|
|
""" |
21
|
|
|
Returns a function which conforms imported qss files to valid scss to be |
22
|
|
|
used as an importer for sass.compile. |
23
|
|
|
|
24
|
|
|
:param where: Directory containing scss, css, and sass files |
25
|
|
|
""" |
26
|
|
|
|
27
|
|
|
def find_file(import_file): |
|
|
|
|
28
|
|
|
|
29
|
|
|
if os.path.isfile(import_file): |
30
|
|
|
return import_file |
31
|
|
|
extensions = ['.scss', '.css', '.sass'] |
32
|
|
|
for ext in extensions: |
33
|
|
|
potential_file = import_file + ext |
34
|
|
|
if os.path.isfile(potential_file): |
35
|
|
|
return potential_file |
36
|
|
|
potential_file = os.path.join(where, import_file + ext) |
37
|
|
|
if os.path.isfile(potential_file): |
38
|
|
|
return potential_file |
39
|
|
|
return import_file |
40
|
|
|
|
41
|
|
|
def import_and_conform_file(import_file): |
|
|
|
|
42
|
|
|
|
43
|
|
|
real_import_file = find_file(import_file) |
44
|
|
|
with open(real_import_file, 'r') as f: |
|
|
|
|
45
|
|
|
import_str = f.read() |
46
|
|
|
|
47
|
|
|
return [(import_file, scss_conform(import_str))] |
48
|
|
|
|
49
|
|
|
return import_and_conform_file |
50
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.