1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Add a SassScript repl.

This commit is contained in:
Nathan Weizenbaum 2008-10-16 16:23:45 -07:00
parent ad518a4dc1
commit e99f6654e1
2 changed files with 53 additions and 0 deletions

View file

@ -185,9 +185,20 @@ END
'Line Comments. Emit comments in the generated CSS indicating the corresponding sass line.') do
@options[:for_engine][:line_comments] = true
end
opts.on('-i', '--interactive',
'Run an interactive SassScript shell.') do
@options[:interactive] = true
end
end
def process_result
if @options[:interactive]
require 'sass'
require 'sass/repl'
::Sass::Repl.run
return
end
super
input = @options[:input]
output = @options[:output]

42
lib/sass/repl.rb Normal file
View file

@ -0,0 +1,42 @@
require 'readline'
module Sass
module Repl
class << self
def run
environment = Environment.new
environment.set_var('important', Script::String.new('!important'))
loop do
unless text = Readline.readline('>> ')
puts
return
end
Readline::HISTORY << text
parse_input(environment, text)
end
end
private
def parse_input(environment, text)
case text
when Script::MATCH
name = $1
guarded = $2 == '||='
val = Script::Parser.parse($3)
unless guarded && environment.var(name)
environment.set_var(name, val.perform(environment))
end
p environment.var(name)
else
p Script::Parser.parse(text).perform(environment)
end
rescue Sass::SyntaxError => e
puts "SyntaxError: #{e.message}"
end
end
end
end