gems.sass-3.2.8.lib.sass.repl.rb Maven / Gradle / Ivy
Go to download
Sass makes CSS fun again. Sass is an extension of CSS3, adding nested rules, variables, mixins, selector
inheritance, and more. It's translated to well-formatted, standard CSS using the command line tool or a
web-framework plugin.
This is a repackaged GEM in a JAR format of the sass-lang.gem package. The sass-gems package version
follows the sass-lang.gem versions located http://rubyforge.org/frs/?group_id=9702. Simply change
the version of this package to download and repackage the same GEM version.
require 'readline'
module Sass
# Runs a SassScript read-eval-print loop.
# It presents a prompt on the terminal,
# reads in SassScript expressions,
# evaluates them,
# and prints the result.
class Repl
# @param options [{Symbol => Object}] An options hash.
def initialize(options = {})
@options = options
end
# Starts the read-eval-print loop.
def run
environment = Environment.new
@line = 0
loop do
@line += 1
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 = !!$3
val = Script::Parser.parse($2, @line, text.size - ($3 || '').size - $2.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)
end
rescue Sass::SyntaxError => e
puts "SyntaxError: #{e.message}"
if @options[:trace]
e.backtrace.each do |e|
puts "\tfrom #{e}"
end
end
end
end
end