GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Fork of nex3/haml
Description: HTML Abstraction Markup Language - A Markup Haiku
Homepage: http://haml.hamptoncatlin.com
Clone URL: git://github.com/chriseppstein/haml.git
Nicen up executable error output.

git-svn-id: svn://hamptoncatlin.com/haml/trunk@686 
7063305b-7217-0410-af8c-cdc13e5119b9
nex3 (author)
Fri Dec 07 20:06:36 -0800 2007
commit  c035771d1ce88381e79fe9c8307140bd372f06cf
tree    42f3a3d5f643d196337bd722d16920660ad0352e
parent  131cf788e470bf0ba03acf909909106ea3663b83
...
26
27
28
29
30
 
 
31
32
33
34
35
36
 
37
38
39
...
43
44
45
 
 
 
 
 
 
46
47
48
49
50
 
51
52
53
...
161
162
163
164
 
 
 
 
 
 
 
 
165
166
167
...
182
183
184
185
 
 
 
 
 
 
 
 
 
 
 
 
 
186
187
188
...
26
27
28
 
 
29
30
31
 
 
 
 
 
32
33
34
35
...
39
40
41
42
43
44
45
46
47
48
49
50
51
 
52
53
54
55
...
163
164
165
 
166
167
168
169
170
171
172
173
174
175
176
...
191
192
193
 
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
0
@@ -26,14 +26,10 @@ module Haml
0
         rescue Exception => e
0
           raise e if e.is_a? SystemExit
0
 
0
- line = e.backtrace[0].scan(/:(.*)/)[0]
0
- puts "#{e.class} on line #{line}: #{e.message}"
0
+ $stderr.print "#{e.class} on line #{get_line e}: " if @options[:trace]
0
+ $stderr.puts e.message
0
 
0
- if @options[:trace]
0
- e.backtrace[1..-1].each { |t| puts " #{t}" }
0
- else
0
- puts " Use --trace to see traceback"
0
- end
0
+ e.backtrace[1..-1].each { |t| $stderr.puts " #{t}" } if @options[:trace]
0
 
0
           exit 1
0
         end
0
@@ -43,11 +39,17 @@ module Haml
0
       def to_s
0
         @opts.to_s
0
       end
0
+
0
+ protected
0
+
0
+ def get_line(exception)
0
+ exception.backtrace[0].scan(/:(\d+)/)[0]
0
+ end
0
       
0
       private
0
 
0
       def set_opts(opts)
0
- opts.on('s', '--stdin', :NONE, 'Read input from standard input instead of an input file') do
0
+ opts.on('-s', '--stdin', :NONE, 'Read input from standard input instead of an input file') do
0
           @options[:input] = $stdin
0
         end
0
 
0
@@ -161,7 +163,14 @@ END
0
 
0
         template = input.read()
0
         input.close() if input.is_a? File
0
- result = ::Sass::Engine.new(template).render
0
+
0
+ begin
0
+ result = ::Sass::Engine.new(template).render
0
+ rescue ::Sass::SyntaxError => e
0
+ raise e if @options[:trace]
0
+ raise "Syntax error on line #{get_line e}: #{e.message}"
0
+ end
0
+
0
         output.write(result)
0
         output.close() if output.is_a? File
0
       end
0
@@ -182,7 +191,19 @@ END
0
 
0
         template = input.read()
0
         input.close() if input.is_a? File
0
- result = ::Haml::Engine.new(template).to_html
0
+
0
+ begin
0
+ result = ::Haml::Engine.new(template).to_html
0
+ rescue Exception => e
0
+ raise e if @options[:trace]
0
+
0
+ case e
0
+ when ::Haml::SyntaxError: raise "Syntax error on line #{get_line e}: #{e.message}"
0
+ when ::Haml::HamlError: raise "Haml error on line #{get_line e}: #{e.message}"
0
+ else raise "Exception on line #{get_line e}: #{e.message}\n Use --trace for backtrace."
0
+ end
0
+ end
0
+
0
         output.write(result)
0
         output.close() if output.is_a? File
0
       end

Comments

    No one has commented yet.