diff options
author | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2014-08-24 13:31:25 -0700 |
---|---|---|
committer | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2014-08-24 13:31:25 -0700 |
commit | b210e43ee010063c3b9a698d5fe63f5f8d167f70 (patch) | |
tree | b08bf556cd285e966632d1bf602be402f5953ec5 /scss/compiler.py | |
parent | c486c4ffe05f480fc1286c12f38e72d4c2b7ec1b (diff) | |
download | pyscss-b210e43ee010063c3b9a698d5fe63f5f8d167f70.tar.gz |
Fix debug_info and live_errors.
The live_errors code only existed in the only 'compile' method; oops.
debug_info just wasn't being passed in by Scss. Also, due to changes in
SourceFile, it wasn't being generated for fake files. I don't mind
loosening that restriction, since hopefully we'll have source map
support fairly soon.
Diffstat (limited to 'scss/compiler.py')
-rw-r--r-- | scss/compiler.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/scss/compiler.py b/scss/compiler.py index 040e8f0..23b9487 100644 --- a/scss/compiler.py +++ b/scss/compiler.py @@ -115,9 +115,24 @@ class Compiler(object): def make_compilation(self): return Compilation(self) + def call_and_catch_errors(self, f, *args, **kwargs): + """Call the given function with the given arguments. If it succeeds, + return its return value. If it raises a :class:`scss.errors.SassError` + and `live_errors` is turned on, return CSS containing a traceback and + error message. + """ + try: + return f(*args, **kwargs) + except SassError as e: + if self.live_errors: + # TODO should this setting also capture and display warnings? + return e.to_css() + else: + raise + def compile(self): compilation = self.make_compilation() - compilation.run() + return self.call_and_catch_errors(compilation.run) class Compilation(object): @@ -185,16 +200,6 @@ class Compilation(object): return final_cont - def compile(self, *args, **kwargs): - try: - return self.Compilation(*args, **kwargs) - except SassError as e: - if self.live_errors: - # TODO should this setting also capture and display warnings? - return e.to_css() - else: - raise - def parse_selectors(self, raw_selectors): """ Parses out the old xCSS "foo extends bar" syntax. @@ -1435,10 +1440,10 @@ class Compilation(object): result = tb * (i + nesting) + "@media -sass-debug-info{filename{font-family:file\:\/\/%s}line{font-family:\\00003%s}}" % (filename, lineno) + nl return result - if rule.lineno and rule.source_file and rule.source_file.is_real_file: + if rule.lineno and rule.source_file: result += _print_debug_info(rule.source_file.path, rule.lineno) - if rule.from_lineno and rule.from_source_file and rule.from_source_file.is_real_file: + if rule.from_lineno and rule.from_source_file: result += _print_debug_info(rule.from_source_file.path, rule.from_lineno) if header.is_selector: |