haml-edge 2.3.17 → 2.3.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/EDGE_GEM_VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.17
1
+ 2.3.18
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.17
1
+ 2.3.18
data/lib/haml/helpers.rb CHANGED
@@ -14,8 +14,12 @@ module Haml
14
14
  # when it shouldn't be.
15
15
  class ErrorReturn
16
16
  # @param message [String] The error message to raise when \{#to\_s} is called
17
- def initialize(message)
18
- @message = message
17
+ def initialize(method)
18
+ @message = <<MESSAGE
19
+ #{method} outputs directly to the Haml template.
20
+ Disregard its return value and use the - operator,
21
+ or use capture_haml to get the value as a String.
22
+ MESSAGE
19
23
  end
20
24
 
21
25
  # Raises an error.
@@ -23,6 +27,21 @@ module Haml
23
27
  # @raise [Haml::Error] The error
24
28
  def to_s
25
29
  raise Haml::Error.new(@message)
30
+ rescue Haml::Error => e
31
+ e.backtrace.shift
32
+
33
+ # If the ErrorReturn is used directly in the template,
34
+ # we don't want Haml's stuff to get into the backtrace,
35
+ # so we get rid of the format_script line.
36
+ #
37
+ # We also have to subtract one from the Haml line number
38
+ # since the value is passed to format_script the line after
39
+ # it's actually used.
40
+ if e.backtrace.first =~ /^\(eval\):\d+:in `format_script/
41
+ e.backtrace.shift
42
+ e.backtrace.first.gsub!(/^\(haml\):(\d+)/) {|s| "(haml):#{$1.to_i - 1}"}
43
+ end
44
+ raise e
26
45
  end
27
46
 
28
47
  # @return [String] A human-readable string representation
@@ -338,7 +357,7 @@ END
338
357
  # @param text [#to_s] The text to output
339
358
  def haml_concat(text = "")
340
359
  haml_buffer.buffer << haml_indent << text.to_s << "\n"
341
- nil
360
+ ErrorReturn.new("haml_concat")
342
361
  end
343
362
 
344
363
  # @return [String] The indentation string for the current line
@@ -399,11 +418,7 @@ END
399
418
  # @overload haml_tag(name, text, *flags, attributes = {})
400
419
  # @param text [#to_s] The text within the tag
401
420
  def haml_tag(name, *rest, &block)
402
- ret = ErrorReturn.new(<<MESSAGE)
403
- haml_tag outputs directly to the Haml template.
404
- Disregard its return value and use the - operator,
405
- or use capture_haml to get the value as a String.
406
- MESSAGE
421
+ ret = ErrorReturn.new("haml_tag")
407
422
 
408
423
  name = name.to_s
409
424
  text = rest.shift.to_s unless [Symbol, Hash, NilClass].any? {|t| rest.first.is_a? t}
@@ -8,6 +8,12 @@ class ActionView::Base
8
8
  end
9
9
  end
10
10
 
11
+ module Haml::Helpers
12
+ def something_that_uses_haml_concat
13
+ haml_concat('foo').to_s
14
+ end
15
+ end
16
+
11
17
  class HelperTest < Test::Unit::TestCase
12
18
  Post = Struct.new('Post', :body)
13
19
 
@@ -221,7 +227,29 @@ HAML
221
227
  def test_content_tag_nested
222
228
  assert_equal "<span><div>something</div></span>", render("= nested_tag", :action_view).strip
223
229
  end
224
-
230
+
231
+ def test_error_return
232
+ assert_raise(Haml::Error, <<MESSAGE) {render("= haml_concat 'foo'")}
233
+ haml_concat outputs directly to the Haml template.
234
+ Disregard its return value and use the - operator,
235
+ or use capture_haml to get the value as a String.
236
+ MESSAGE
237
+ end
238
+
239
+ def test_error_return_line
240
+ render("%p foo\n= haml_concat 'foo'\n%p bar")
241
+ assert false, "Expected Haml::Error"
242
+ rescue Haml::Error => e
243
+ assert_equal 2, e.backtrace[0].scan(/:(\d+)/).first.first.to_i
244
+ end
245
+
246
+ def test_error_return_line_in_helper
247
+ render("- something_that_uses_haml_concat")
248
+ assert false, "Expected Haml::Error"
249
+ rescue Haml::Error => e
250
+ assert_equal 13, e.backtrace[0].scan(/:(\d+)/).first.first.to_i
251
+ end
252
+
225
253
  class ActsLikeTag
226
254
  # We want to be able to have people include monkeypatched ActionView helpers
227
255
  # without redefining is_haml?.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml-edge
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.17
4
+ version: 2.3.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum