diff --git a/lib/haml/exec.rb b/lib/haml/exec.rb index f1ebbedc..900f652d 100644 --- a/lib/haml/exec.rb +++ b/lib/haml/exec.rb @@ -195,7 +195,7 @@ END if @options[:interactive] require 'sass' require 'sass/repl' - ::Sass::Repl.run + ::Sass::Repl.new(@options).run return end diff --git a/lib/sass/repl.rb b/lib/sass/repl.rb index 10280e2e..621780d6 100644 --- a/lib/sass/repl.rb +++ b/lib/sass/repl.rb @@ -1,43 +1,50 @@ require 'readline' module Sass - module Repl - class << self - def run - environment = Environment.new - environment.set_var('important', Script::String.new('!important')) - @line = 0 - loop do - @line += 1 - unless text = Readline.readline('>> ') - puts - return - end + class Repl + def initialize(options = {}) + @options = options + end - Readline::HISTORY << text - parse_input(environment, text) + def run + environment = Environment.new + environment.set_var('important', Script::String.new('!important')) + @line = 0 + loop do + @line += 1 + unless text = Readline.readline('>> ') + puts + return end + + Readline::HISTORY << text + parse_input(environment, text) end + end - private + private - def parse_input(environment, text) - case text - when Script::MATCH - name = $1 - guarded = $2 == '||=' - val = Script::Parser.parse($3, @line, text.size - $3.size) + def parse_input(environment, text) + case text + when Script::MATCH + name = $1 + guarded = $2 == '||=' + val = Script::Parser.parse($3, @line, text.size - $3.size) - unless guarded && environment.var(name) - environment.set_var(name, val.perform(environment)) - end - - p environment.var(name) - else - p Script::Parser.parse(text, @line, 0).perform(environment) + unless guarded && environment.var(name) + environment.set_var(name, val.perform(environment)) + end + + p environment.var(name) + else + p Script::Parser.parse(text, @line, 0).perform(environment) + end + rescue Sass::SyntaxError => e + puts "SyntaxError: #{e.message}" + if @options[:trace] + e.backtrace.each do |e| + puts "\tfrom #{e}" end - rescue Sass::SyntaxError => e - puts "SyntaxError: #{e.message}" end end end