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:
parent
ad518a4dc1
commit
e99f6654e1
2 changed files with 53 additions and 0 deletions
|
@ -185,9 +185,20 @@ END
|
||||||
'Line Comments. Emit comments in the generated CSS indicating the corresponding sass line.') do
|
'Line Comments. Emit comments in the generated CSS indicating the corresponding sass line.') do
|
||||||
@options[:for_engine][:line_comments] = true
|
@options[:for_engine][:line_comments] = true
|
||||||
end
|
end
|
||||||
|
opts.on('-i', '--interactive',
|
||||||
|
'Run an interactive SassScript shell.') do
|
||||||
|
@options[:interactive] = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_result
|
def process_result
|
||||||
|
if @options[:interactive]
|
||||||
|
require 'sass'
|
||||||
|
require 'sass/repl'
|
||||||
|
::Sass::Repl.run
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
super
|
super
|
||||||
input = @options[:input]
|
input = @options[:input]
|
||||||
output = @options[:output]
|
output = @options[:output]
|
||||||
|
|
42
lib/sass/repl.rb
Normal file
42
lib/sass/repl.rb
Normal 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
|
Loading…
Add table
Reference in a new issue