haml-edge 2.3.50 → 2.3.51
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 +1 -1
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/haml/helpers.rb +3 -6
- data/lib/haml/precompiler.rb +24 -14
- data/lib/haml/util.rb +4 -0
- data/test/haml/engine_test.rb +24 -20
- data/test/haml/util_test.rb +5 -0
- data/test/linked_rails.rb +10 -0
- metadata +1 -1
data/EDGE_GEM_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3.
|
1
|
+
2.3.51
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3.
|
1
|
+
2.3.51
|
data/lib/haml/helpers.rb
CHANGED
@@ -113,9 +113,7 @@ MESSAGE
|
|
113
113
|
# @yield The block within which to escape newlines
|
114
114
|
def find_and_preserve(input = nil, tags = haml_buffer.options[:preserve], &block)
|
115
115
|
return find_and_preserve(capture_haml(&block), input || tags) if block
|
116
|
-
|
117
|
-
input = input.to_s
|
118
|
-
input.gsub(/<(#{tags.map(&Regexp.method(:escape)).join('|')})([^>]*)>(.*?)(<\/\1>)/im) do
|
116
|
+
input.to_s.gsub(/<(#{tags.map(&Regexp.method(:escape)).join('|')})([^>]*)>(.*?)(<\/\1>)/im) do
|
119
117
|
"<#{$1}#{$2}>#{preserve($3)}</#{$1}>"
|
120
118
|
end
|
121
119
|
end
|
@@ -132,10 +130,9 @@ MESSAGE
|
|
132
130
|
# Escapes newlines within a block of Haml code.
|
133
131
|
#
|
134
132
|
# @yield The block within which to escape newlines
|
135
|
-
def preserve(input =
|
133
|
+
def preserve(input = nil, &block)
|
136
134
|
return preserve(capture_haml(&block)) if block
|
137
|
-
|
138
|
-
input.chomp("\n").gsub(/\n/, '
').gsub(/\r/, '')
|
135
|
+
input.to_s.chomp("\n").gsub(/\n/, '
').gsub(/\r/, '')
|
139
136
|
end
|
140
137
|
alias_method :flatten, :preserve
|
141
138
|
|
data/lib/haml/precompiler.rb
CHANGED
@@ -329,7 +329,10 @@ END
|
|
329
329
|
end
|
330
330
|
|
331
331
|
if contains_interpolation?(text)
|
332
|
-
|
332
|
+
options[:escape_html] = self.options[:escape_html] if options[:escape_html].nil?
|
333
|
+
push_script(
|
334
|
+
unescape_interpolation(text, :escape_html => options[:escape_html]),
|
335
|
+
:escape_html => false)
|
333
336
|
else
|
334
337
|
push_text text
|
335
338
|
end
|
@@ -665,30 +668,37 @@ END
|
|
665
668
|
nuke_inner_whitespace ||= preserve_tag
|
666
669
|
preserve_tag &&= !options[:ugly]
|
667
670
|
|
671
|
+
escape_html = (action == '&' || (action != '!' && @options[:escape_html]))
|
672
|
+
|
668
673
|
case action
|
669
674
|
when '/'; self_closing = true
|
670
675
|
when '~'; parse = preserve_script = true
|
671
676
|
when '='
|
672
677
|
parse = true
|
673
|
-
|
678
|
+
if value[0] == ?=
|
679
|
+
value = unescape_interpolation(value[1..-1].strip, :escape_html => escape_html)
|
680
|
+
escape_html = false
|
681
|
+
end
|
674
682
|
when '&', '!'
|
675
683
|
if value[0] == ?= || value[0] == ?~
|
676
684
|
parse = true
|
677
685
|
preserve_script = (value[0] == ?~)
|
678
|
-
value
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
686
|
+
if value[1] == ?=
|
687
|
+
value = unescape_interpolation(value[2..-1].strip, :escape_html => escape_html)
|
688
|
+
escape_html = false
|
689
|
+
else
|
690
|
+
value = value[1..-1].strip
|
691
|
+
end
|
684
692
|
elsif contains_interpolation?(value)
|
693
|
+
value = unescape_interpolation(value, :escape_html => escape_html)
|
685
694
|
parse = true
|
686
|
-
|
695
|
+
escape_html = false
|
687
696
|
end
|
688
697
|
else
|
689
698
|
if contains_interpolation?(value)
|
699
|
+
value = unescape_interpolation(value, :escape_html => escape_html)
|
690
700
|
parse = true
|
691
|
-
|
701
|
+
escape_html = false
|
692
702
|
end
|
693
703
|
end
|
694
704
|
|
@@ -697,8 +707,6 @@ END
|
|
697
707
|
value = ''
|
698
708
|
end
|
699
709
|
|
700
|
-
escape_html = (action == '&' || (action != '!' && @options[:escape_html]))
|
701
|
-
|
702
710
|
object_ref = "nil" if object_ref.nil? || @options[:suppress_eval]
|
703
711
|
|
704
712
|
attributes = parse_class_and_id(attributes)
|
@@ -936,7 +944,7 @@ END
|
|
936
944
|
str.include?('#{')
|
937
945
|
end
|
938
946
|
|
939
|
-
def unescape_interpolation(str)
|
947
|
+
def unescape_interpolation(str, opts = {})
|
940
948
|
res = ''
|
941
949
|
rest = Haml::Shared.handle_interpolation str.dump do |scan|
|
942
950
|
escapes = (scan[2].size - 1) / 2
|
@@ -944,7 +952,9 @@ END
|
|
944
952
|
if escapes % 2 == 1
|
945
953
|
res << '#{'
|
946
954
|
else
|
947
|
-
|
955
|
+
content = eval('"' + balance(scan, ?{, ?}, 1)[0][0...-1] + '"')
|
956
|
+
content = "Haml::Helpers.html_escape(#{content})" if opts[:escape_html]
|
957
|
+
res << '#{' + content + "}"# Use eval to get rid of string escapes
|
948
958
|
end
|
949
959
|
end
|
950
960
|
res + rest
|
data/lib/haml/util.rb
CHANGED
@@ -122,6 +122,8 @@ module Haml
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
+
## Cross-Ruby-Version Compatibility
|
126
|
+
|
125
127
|
# Whether or not this is running under Ruby 1.8 or lower.
|
126
128
|
#
|
127
129
|
# @return [Boolean]
|
@@ -171,6 +173,8 @@ MSG
|
|
171
173
|
ruby1_8? ? enum.enum_with_index : enum.each_with_index
|
172
174
|
end
|
173
175
|
|
176
|
+
## Static Method Stuff
|
177
|
+
|
174
178
|
# The context in which the ERB for \{#def\_static\_method} will be run.
|
175
179
|
class StaticConditionalContext
|
176
180
|
# @param set [#include?] The set of variables that are defined for this context.
|
data/test/haml/engine_test.rb
CHANGED
@@ -168,6 +168,10 @@ class EngineTest < Test::Unit::TestCase
|
|
168
168
|
assert_equal("<p>\n 2\n</p>\n", render("%p\n \#{1 + 1}"))
|
169
169
|
end
|
170
170
|
|
171
|
+
def test_escaped_interpolation
|
172
|
+
assert_equal("<p>Foo & Bar & Baz</p>\n", render('%p& Foo #{"&"} Bar & Baz'))
|
173
|
+
end
|
174
|
+
|
171
175
|
def test_nil_tag_value_should_render_as_empty
|
172
176
|
assert_equal("<p></p>\n", render("%p= nil"))
|
173
177
|
end
|
@@ -603,53 +607,53 @@ HAML
|
|
603
607
|
end
|
604
608
|
|
605
609
|
def test_string_double_equals_should_be_esaped
|
606
|
-
assert_equal("<p>4
|
607
|
-
assert_equal("<p>4
|
610
|
+
assert_equal("<p>4&<</p>\n", render("%p== \#{2+2}&\#{'<'}", :escape_html => true))
|
611
|
+
assert_equal("<p>4&<</p>\n", render("%p== \#{2+2}&\#{'<'}", :escape_html => false))
|
608
612
|
end
|
609
613
|
|
610
614
|
def test_escaped_inline_string_double_equals
|
611
|
-
assert_equal("<p>4
|
612
|
-
assert_equal("<p>4
|
615
|
+
assert_equal("<p>4&<</p>\n", render("%p&== \#{2+2}&\#{'<'}", :escape_html => true))
|
616
|
+
assert_equal("<p>4&<</p>\n", render("%p&== \#{2+2}&\#{'<'}", :escape_html => false))
|
613
617
|
end
|
614
618
|
|
615
619
|
def test_unescaped_inline_string_double_equals
|
616
|
-
assert_equal("<p>4
|
617
|
-
assert_equal("<p>4
|
620
|
+
assert_equal("<p>4&<</p>\n", render("%p!== \#{2+2}&\#{'<'}", :escape_html => true))
|
621
|
+
assert_equal("<p>4&<</p>\n", render("%p!== \#{2+2}&\#{'<'}", :escape_html => false))
|
618
622
|
end
|
619
623
|
|
620
624
|
def test_escaped_string_double_equals
|
621
|
-
assert_equal("<p>\n 4
|
622
|
-
assert_equal("<p>\n 4
|
625
|
+
assert_equal("<p>\n 4&<\n</p>\n", render("%p\n &== \#{2+2}&\#{'<'}", :escape_html => true))
|
626
|
+
assert_equal("<p>\n 4&<\n</p>\n", render("%p\n &== \#{2+2}&\#{'<'}", :escape_html => false))
|
623
627
|
end
|
624
628
|
|
625
629
|
def test_unescaped_string_double_equals
|
626
|
-
assert_equal("<p>\n 4
|
627
|
-
assert_equal("<p>\n 4
|
630
|
+
assert_equal("<p>\n 4&<\n</p>\n", render("%p\n !== \#{2+2}&\#{'<'}", :escape_html => true))
|
631
|
+
assert_equal("<p>\n 4&<\n</p>\n", render("%p\n !== \#{2+2}&\#{'<'}", :escape_html => false))
|
628
632
|
end
|
629
633
|
|
630
634
|
def test_string_interpolation_should_be_esaped
|
631
|
-
assert_equal("<p>4
|
632
|
-
assert_equal("<p>4
|
635
|
+
assert_equal("<p>4&<</p>\n", render("%p \#{2+2}&\#{'<'}", :escape_html => true))
|
636
|
+
assert_equal("<p>4&<</p>\n", render("%p \#{2+2}&\#{'<'}", :escape_html => false))
|
633
637
|
end
|
634
638
|
|
635
639
|
def test_escaped_inline_string_interpolation
|
636
|
-
assert_equal("<p>4
|
637
|
-
assert_equal("<p>4
|
640
|
+
assert_equal("<p>4&<</p>\n", render("%p& \#{2+2}&\#{'<'}", :escape_html => true))
|
641
|
+
assert_equal("<p>4&<</p>\n", render("%p& \#{2+2}&\#{'<'}", :escape_html => false))
|
638
642
|
end
|
639
643
|
|
640
644
|
def test_unescaped_inline_string_interpolation
|
641
|
-
assert_equal("<p>4
|
642
|
-
assert_equal("<p>4
|
645
|
+
assert_equal("<p>4&<</p>\n", render("%p! \#{2+2}&\#{'<'}", :escape_html => true))
|
646
|
+
assert_equal("<p>4&<</p>\n", render("%p! \#{2+2}&\#{'<'}", :escape_html => false))
|
643
647
|
end
|
644
648
|
|
645
649
|
def test_escaped_string_interpolation
|
646
|
-
assert_equal("<p>\n 4
|
647
|
-
assert_equal("<p>\n 4
|
650
|
+
assert_equal("<p>\n 4&<\n</p>\n", render("%p\n & \#{2+2}&\#{'<'}", :escape_html => true))
|
651
|
+
assert_equal("<p>\n 4&<\n</p>\n", render("%p\n & \#{2+2}&\#{'<'}", :escape_html => false))
|
648
652
|
end
|
649
653
|
|
650
654
|
def test_unescaped_string_interpolation
|
651
|
-
assert_equal("<p>\n 4
|
652
|
-
assert_equal("<p>\n 4
|
655
|
+
assert_equal("<p>\n 4&<\n</p>\n", render("%p\n ! \#{2+2}&\#{'<'}", :escape_html => true))
|
656
|
+
assert_equal("<p>\n 4&<\n</p>\n", render("%p\n ! \#{2+2}&\#{'<'}", :escape_html => false))
|
653
657
|
end
|
654
658
|
|
655
659
|
def test_scripts_should_respect_escape_html_option
|
data/test/haml/util_test.rb
CHANGED
@@ -54,6 +54,11 @@ class UtilTest < Test::Unit::TestCase
|
|
54
54
|
powerset([1, 2, 3]))
|
55
55
|
end
|
56
56
|
|
57
|
+
def test_merge_adjacent_strings
|
58
|
+
assert_equal(["foo bar baz", :bang, "biz bop", 12],
|
59
|
+
merge_adjacent_strings(["foo ", "bar ", "baz", :bang, "biz", " bop", 12]))
|
60
|
+
end
|
61
|
+
|
57
62
|
def test_has
|
58
63
|
assert(has?(:instance_method, String, :chomp!))
|
59
64
|
assert(has?(:private_instance_method, Haml::Engine, :set_locals))
|
data/test/linked_rails.rb
CHANGED
@@ -10,3 +10,13 @@ else
|
|
10
10
|
end
|
11
11
|
require 'action_controller'
|
12
12
|
require 'action_view'
|
13
|
+
|
14
|
+
ActionController::Base.logger = Logger.new(nil)
|
15
|
+
|
16
|
+
# Load plugins from test/plugins.
|
17
|
+
# This will only work with very basic plugins,
|
18
|
+
# since we don't want to load the entirety of Rails.
|
19
|
+
Dir[File.dirname(__FILE__) + '/plugins/*'].each do |plugin|
|
20
|
+
$: << plugin + '/lib'
|
21
|
+
Object.new.instance_eval(File.read(plugin + '/init.rb'))
|
22
|
+
end
|