In Files

Parent

Class Index [+]

Quicksearch

Sass::Repl

Runs a SassScript read-eval-print loop. It presents a prompt on the terminal, reads in SassScript expressions, evaluates them, and prints the result.

Public Class Methods

new(options = {}) click to toggle source

@param options [{Symbol => Object}] An options hash.

    # File lib/sass/repl.rb, line 11
11:     def initialize(options = {})
12:       @options = options
13:     end

Public Instance Methods

run() click to toggle source

Starts the read-eval-print loop.

    # File lib/sass/repl.rb, line 16
16:     def run
17:       environment = Environment.new
18:       environment.set_var('important', Script::String.new('!important'))
19:       @line = 0
20:       loop do
21:         @line += 1
22:         unless text = Readline.readline('>> ')
23:           puts
24:           return
25:         end
26: 
27:         Readline::HISTORY << text
28:         parse_input(environment, text)
29:       end
30:     end

Private Instance Methods

parse_input(environment, text) click to toggle source
    # File lib/sass/repl.rb, line 34
34:     def parse_input(environment, text)
35:       case text
36:       when Script::MATCH
37:         name = $1
38:         guarded = $3 == '||=' || $4
39:         val = Script::Parser.parse($3, @line, text.size - $3.size)
40: 
41:         unless guarded && environment.var(name)
42:           environment.set_var(name, val.perform(environment))
43:         end
44: 
45:         p environment.var(name)
46:       else
47:         p Script::Parser.parse(text, @line, 0).perform(environment)
48:       end
49:     rescue Sass::SyntaxError => e
50:       puts "SyntaxError: #{e.message}"
51:       if @options[:trace]
52:         e.backtrace.each do |e|
53:           puts "\tfrom #{e}"
54:         end
55:       end
56:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.