haml-edge 3.1.23 → 3.1.24
Sign up to get free protection for your applications and to get access to all the features.
- data/EDGE_GEM_VERSION +1 -1
- data/VERSION +1 -1
- data/lib/haml/engine.rb +8 -3
- data/lib/haml/template/plugin.rb +2 -0
- data/lib/haml/template.rb +5 -1
- data/lib/haml/util.rb +135 -0
- data/lib/sass/css.rb +27 -5
- data/lib/sass/engine.rb +37 -3
- data/lib/sass/files.rb +5 -3
- data/lib/sass/script/parser.rb +1 -1
- data/lib/sass/scss/parser.rb +4 -5
- data/lib/sass/tree/import_node.rb +3 -1
- data/test/haml/engine_test.rb +202 -1
- data/test/sass/engine_test.rb +95 -0
- data/test/test_helper.rb +1 -0
- metadata +2 -2
data/EDGE_GEM_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.1.
|
1
|
+
3.1.24
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.1.
|
1
|
+
3.1.24
|
data/lib/haml/engine.rb
CHANGED
@@ -85,8 +85,15 @@ module Haml
|
|
85
85
|
:format => :xhtml,
|
86
86
|
:escape_html => false,
|
87
87
|
}
|
88
|
+
|
89
|
+
|
90
|
+
template = check_haml_encoding(template) do |msg, line|
|
91
|
+
raise Haml::Error.new(msg, line)
|
92
|
+
end
|
93
|
+
|
88
94
|
unless ruby1_8?
|
89
|
-
@options[:encoding] = Encoding.default_internal ||
|
95
|
+
@options[:encoding] = Encoding.default_internal || template.encoding
|
96
|
+
@options[:encoding] = "utf-8" if @options[:encoding].name == "US-ASCII"
|
90
97
|
end
|
91
98
|
@options.merge! options.reject {|k, v| v.nil?}
|
92
99
|
@index = 0
|
@@ -99,8 +106,6 @@ module Haml
|
|
99
106
|
@options[:encoding] = @options[:encoding].name
|
100
107
|
end
|
101
108
|
|
102
|
-
template = check_encoding(template) {|msg, line| raise Haml::Error.new(msg, line)}
|
103
|
-
|
104
109
|
# :eod is a special end-of-document marker
|
105
110
|
@template = (template.rstrip).split(/\r\n|\r|\n/) + [:eod, :eod]
|
106
111
|
@template_index = 0
|
data/lib/haml/template/plugin.rb
CHANGED
data/lib/haml/template.rb
CHANGED
@@ -43,7 +43,11 @@ module Haml
|
|
43
43
|
end
|
44
44
|
|
45
45
|
unless Haml::Util.rails_env == "development"
|
46
|
-
Haml::Template.options[:ugly]
|
46
|
+
Haml::Template.options[:ugly] ||= true
|
47
|
+
end
|
48
|
+
|
49
|
+
if ActionPack::VERSION::MAJOR >= 3
|
50
|
+
Haml::Template.options[:format] ||= :html5
|
47
51
|
end
|
48
52
|
|
49
53
|
# Decide how we want to load Haml into Rails.
|
data/lib/haml/util.rb
CHANGED
@@ -2,6 +2,7 @@ require 'erb'
|
|
2
2
|
require 'set'
|
3
3
|
require 'enumerator'
|
4
4
|
require 'stringio'
|
5
|
+
require 'strscan'
|
5
6
|
require 'haml/root'
|
6
7
|
require 'haml/util/subset_map'
|
7
8
|
|
@@ -434,6 +435,109 @@ MSG
|
|
434
435
|
return str
|
435
436
|
end
|
436
437
|
|
438
|
+
# Like {\#check\_encoding}, but also checks for a Ruby-style `-# coding:` comment
|
439
|
+
# at the beginning of the template and uses that encoding if it exists.
|
440
|
+
#
|
441
|
+
# The Sass encoding rules are simple.
|
442
|
+
# If a `-# coding:` comment exists,
|
443
|
+
# we assume that that's the original encoding of the document.
|
444
|
+
# Otherwise, we use whatever encoding Ruby has.
|
445
|
+
#
|
446
|
+
# Haml uses the same rules for parsing coding comments as Ruby.
|
447
|
+
# This means that it can understand Emacs-style comments
|
448
|
+
# (e.g. `-*- encoding: "utf-8" -*-`),
|
449
|
+
# and also that it cannot understand non-ASCII-compatible encodings
|
450
|
+
# such as `UTF-16` and `UTF-32`.
|
451
|
+
#
|
452
|
+
# @param str [String] The Haml template of which to check the encoding
|
453
|
+
# @yield [msg] A block in which an encoding error can be raised.
|
454
|
+
# Only yields if there is an encoding error
|
455
|
+
# @yieldparam msg [String] The error message to be raised
|
456
|
+
# @return [String] The original string encoded properly
|
457
|
+
# @raise [ArgumentError] if the document declares an unknown encoding
|
458
|
+
def check_haml_encoding(str, &block)
|
459
|
+
return check_encoding(str, &block) if ruby1_8?
|
460
|
+
|
461
|
+
bom, encoding = parse_haml_magic_comment(str)
|
462
|
+
if encoding; str.force_encoding(encoding)
|
463
|
+
elsif bom; str.force_encoding("UTF-8")
|
464
|
+
end
|
465
|
+
|
466
|
+
return check_encoding(str, &block)
|
467
|
+
end
|
468
|
+
|
469
|
+
# Like {\#check\_encoding}, but also checks for a `@charset` declaration
|
470
|
+
# at the beginning of the file and uses that encoding if it exists.
|
471
|
+
#
|
472
|
+
# The Sass encoding rules are simple.
|
473
|
+
# If a `@charset` declaration exists,
|
474
|
+
# we assume that that's the original encoding of the document.
|
475
|
+
# Otherwise, we use whatever encoding Ruby has.
|
476
|
+
# Then we convert that to UTF-8 to process internally.
|
477
|
+
# The UTF-8 end result is what's returned by this method.
|
478
|
+
#
|
479
|
+
# @param str [String] The string of which to check the encoding
|
480
|
+
# @yield [msg] A block in which an encoding error can be raised.
|
481
|
+
# Only yields if there is an encoding error
|
482
|
+
# @yieldparam msg [String] The error message to be raised
|
483
|
+
# @return [(String, Encoding)] The original string encoded as UTF-8,
|
484
|
+
# and the source encoding of the string (or `nil` under Ruby 1.8)
|
485
|
+
# @raise [Encoding::UndefinedConversionError] if the source encoding
|
486
|
+
# cannot be converted to UTF-8
|
487
|
+
# @raise [ArgumentError] if the document uses an unknown encoding with `@charset`
|
488
|
+
def check_sass_encoding(str, &block)
|
489
|
+
return check_encoding(str, &block), nil if ruby1_8?
|
490
|
+
# We allow any printable ASCII characters but double quotes in the charset decl
|
491
|
+
bin = str.dup.force_encoding("BINARY")
|
492
|
+
encoding = Haml::Util::ENCODINGS_TO_CHECK.find do |enc|
|
493
|
+
bin =~ Haml::Util::CHARSET_REGEXPS[enc]
|
494
|
+
end
|
495
|
+
charset, bom = $1, $2
|
496
|
+
if charset
|
497
|
+
charset = charset.force_encoding(encoding).encode("UTF-8")
|
498
|
+
if endianness = encoding[/[BL]E$/]
|
499
|
+
begin
|
500
|
+
Encoding.find(charset + endianness)
|
501
|
+
charset << endianness
|
502
|
+
rescue ArgumentError # Encoding charset + endianness doesn't exist
|
503
|
+
end
|
504
|
+
end
|
505
|
+
str.force_encoding(charset)
|
506
|
+
elsif bom
|
507
|
+
str.force_encoding(encoding)
|
508
|
+
end
|
509
|
+
|
510
|
+
str = check_encoding(str, &block)
|
511
|
+
return str.encode("UTF-8"), str.encoding
|
512
|
+
end
|
513
|
+
|
514
|
+
unless ruby1_8?
|
515
|
+
# @private
|
516
|
+
def _enc(string, encoding)
|
517
|
+
string.encode(encoding).force_encoding("BINARY")
|
518
|
+
end
|
519
|
+
|
520
|
+
# We could automatically add in any non-ASCII-compatible encodings here,
|
521
|
+
# but there's not really a good way to do that
|
522
|
+
# without manually checking that each encoding
|
523
|
+
# encodes all ASCII characters properly,
|
524
|
+
# which takes long enough to affect the startup time of the CLI.
|
525
|
+
ENCODINGS_TO_CHECK = %w[UTF-8 UTF-16BE UTF-16LE UTF-32BE UTF-32LE]
|
526
|
+
|
527
|
+
CHARSET_REGEXPS = Hash.new do |h, e|
|
528
|
+
h[e] =
|
529
|
+
begin
|
530
|
+
# /\A(?:\uFEFF)?@charset "(.*?)"|\A(\uFEFF)/
|
531
|
+
Regexp.new(/\A(?:#{_enc("\uFEFF", e)})?#{
|
532
|
+
_enc('@charset "', e)}(.*?)#{_enc('"', e)}|\A(#{
|
533
|
+
_enc("\uFEFF", e)})/)
|
534
|
+
rescue
|
535
|
+
# /\A@charset "(.*?)"/
|
536
|
+
Regexp.new(/\A#{_enc('@charset "', e)}(.*?)#{_enc('"', e)}/)
|
537
|
+
end
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
437
541
|
# Checks to see if a class has a given method.
|
438
542
|
# For example:
|
439
543
|
#
|
@@ -623,5 +727,36 @@ METHOD
|
|
623
727
|
return lcs_backtrace(c, x, y, i, j-1, &block) if c[i][j-1] > c[i-1][j]
|
624
728
|
return lcs_backtrace(c, x, y, i-1, j, &block)
|
625
729
|
end
|
730
|
+
|
731
|
+
# Parses a magic comment at the beginning of a Haml file.
|
732
|
+
# The parsing rules are basically the same as Ruby's.
|
733
|
+
#
|
734
|
+
# @return [(Boolean, String or nil)]
|
735
|
+
# Whether the document begins with a UTF-8 BOM,
|
736
|
+
# and the declared encoding of the document (or nil if none is declared)
|
737
|
+
def parse_haml_magic_comment(str)
|
738
|
+
scanner = StringScanner.new(str.dup.force_encoding("BINARY"))
|
739
|
+
bom = scanner.scan(/\xEF\xBB\xBF/n)
|
740
|
+
return bom unless scanner.scan(/-\s*#\s*/n)
|
741
|
+
if coding = try_parse_haml_emacs_magic_comment(scanner)
|
742
|
+
return bom, coding
|
743
|
+
end
|
744
|
+
|
745
|
+
return bom unless scanner.scan(/.*?coding[=:]\s*([\w-]+)/in)
|
746
|
+
return bom, scanner[1]
|
747
|
+
end
|
748
|
+
|
749
|
+
def try_parse_haml_emacs_magic_comment(scanner)
|
750
|
+
pos = scanner.pos
|
751
|
+
return unless scanner.scan(/.*?-\*-\s*/n)
|
752
|
+
# From Ruby's parse.y
|
753
|
+
return unless scanner.scan(/([^\s'":;]+)\s*:\s*("(?:\\.|[^"])*"|[^"\s;]+?)[\s;]*-\*-/n)
|
754
|
+
name, val = scanner[1], scanner[2]
|
755
|
+
return unless name =~ /(en)?coding/in
|
756
|
+
val = $1 if val =~ /^"(.*)"$/n
|
757
|
+
return val
|
758
|
+
ensure
|
759
|
+
scanner.pos = pos
|
760
|
+
end
|
626
761
|
end
|
627
762
|
end
|
data/lib/sass/css.rb
CHANGED
@@ -14,7 +14,12 @@ module Sass
|
|
14
14
|
# Sass::CSS.new("p { color: blue }").render(:sass) #=> "p\n color: blue"
|
15
15
|
# Sass::CSS.new("p { color: blue }").render(:scss) #=> "p {\n color: blue; }"
|
16
16
|
class CSS
|
17
|
-
# @param template [String] The CSS
|
17
|
+
# @param template [String] The CSS stylesheet.
|
18
|
+
# This stylesheet can be encoded using any encoding
|
19
|
+
# that can be converted to Unicode.
|
20
|
+
# If the stylesheet contains an `@charset` declaration,
|
21
|
+
# that overrides the Ruby encoding
|
22
|
+
# (see {file:SASS_REFERENCE.md#encodings the encoding documentation})
|
18
23
|
# @option options :old [Boolean] (false)
|
19
24
|
# Whether or not to output old property syntax
|
20
25
|
# (`:color blue` as opposed to `color: blue`).
|
@@ -37,18 +42,35 @@ module Sass
|
|
37
42
|
# @return [String] The resulting Sass or SCSS code
|
38
43
|
# @raise [Sass::SyntaxError] if there's an error parsing the CSS template
|
39
44
|
def render(fmt = :sass)
|
40
|
-
|
41
|
-
raise Sass::SyntaxError.new(msg, :line => line)
|
42
|
-
end
|
43
|
-
|
45
|
+
check_encoding!
|
44
46
|
build_tree.send("to_#{fmt}", @options).strip + "\n"
|
45
47
|
rescue Sass::SyntaxError => err
|
46
48
|
err.modify_backtrace(:filename => @options[:filename] || '(css)')
|
47
49
|
raise err
|
48
50
|
end
|
49
51
|
|
52
|
+
# Returns the original encoding of the document,
|
53
|
+
# or `nil` under Ruby 1.8.
|
54
|
+
#
|
55
|
+
# @return [Encoding, nil]
|
56
|
+
# @raise [Encoding::UndefinedConversionError] if the source encoding
|
57
|
+
# cannot be converted to UTF-8
|
58
|
+
# @raise [ArgumentError] if the document uses an unknown encoding with `@charset`
|
59
|
+
def source_encoding
|
60
|
+
check_encoding!
|
61
|
+
@original_encoding
|
62
|
+
end
|
63
|
+
|
50
64
|
private
|
51
65
|
|
66
|
+
def check_encoding!
|
67
|
+
return if @checked_encoding
|
68
|
+
@checked_encoding = true
|
69
|
+
@template, @original_encoding = Haml::Util.check_sass_encoding(@template) do |msg, line|
|
70
|
+
raise Sass::SyntaxError.new(msg, :line => line)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
52
74
|
# Parses the CSS template and applies various transformations
|
53
75
|
#
|
54
76
|
# @return [Tree::Node] The root node of the parsed tree
|
data/lib/sass/engine.rb
CHANGED
@@ -133,6 +133,11 @@ module Sass
|
|
133
133
|
}.freeze
|
134
134
|
|
135
135
|
# @param template [String] The Sass template.
|
136
|
+
# This template can be encoded using any encoding
|
137
|
+
# that can be converted to Unicode.
|
138
|
+
# If the template contains an `@charset` declaration,
|
139
|
+
# that overrides the Ruby encoding
|
140
|
+
# (see {file:SASS_REFERENCE.md#encodings the encoding documentation})
|
136
141
|
# @param options [{Symbol => Object}] An options hash;
|
137
142
|
# see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}
|
138
143
|
def initialize(template, options={})
|
@@ -155,9 +160,12 @@ module Sass
|
|
155
160
|
#
|
156
161
|
# @return [String] The CSS
|
157
162
|
# @raise [Sass::SyntaxError] if there's an error in the document
|
163
|
+
# @raise [Encoding::UndefinedConversionError] if the source encoding
|
164
|
+
# cannot be converted to UTF-8
|
165
|
+
# @raise [ArgumentError] if the document uses an unknown encoding with `@charset`
|
158
166
|
def render
|
159
|
-
return
|
160
|
-
Haml::Util.silence_haml_warnings {
|
167
|
+
return _render unless @options[:quiet]
|
168
|
+
Haml::Util.silence_haml_warnings {_render}
|
161
169
|
end
|
162
170
|
alias_method :to_css, :render
|
163
171
|
|
@@ -170,10 +178,28 @@ module Sass
|
|
170
178
|
Haml::Util.silence_haml_warnings {_to_tree}
|
171
179
|
end
|
172
180
|
|
181
|
+
# Returns the original encoding of the document,
|
182
|
+
# or `nil` under Ruby 1.8.
|
183
|
+
#
|
184
|
+
# @return [Encoding, nil]
|
185
|
+
# @raise [Encoding::UndefinedConversionError] if the source encoding
|
186
|
+
# cannot be converted to UTF-8
|
187
|
+
# @raise [ArgumentError] if the document uses an unknown encoding with `@charset`
|
188
|
+
def source_encoding
|
189
|
+
check_encoding!
|
190
|
+
@original_encoding
|
191
|
+
end
|
192
|
+
|
173
193
|
private
|
174
194
|
|
195
|
+
def _render
|
196
|
+
rendered = _to_tree.render
|
197
|
+
return rendered if ruby1_8?
|
198
|
+
return rendered.encode(source_encoding)
|
199
|
+
end
|
200
|
+
|
175
201
|
def _to_tree
|
176
|
-
|
202
|
+
check_encoding!
|
177
203
|
|
178
204
|
if @options[:syntax] == :scss
|
179
205
|
root = Sass::SCSS::Parser.new(@template).parse
|
@@ -190,6 +216,14 @@ module Sass
|
|
190
216
|
raise e
|
191
217
|
end
|
192
218
|
|
219
|
+
def check_encoding!
|
220
|
+
return if @checked_encoding
|
221
|
+
@checked_encoding = true
|
222
|
+
@template, @original_encoding = check_sass_encoding(@template) do |msg, line|
|
223
|
+
raise Sass::SyntaxError.new(msg, :line => line)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
193
227
|
def tabulate(string)
|
194
228
|
tab_str = nil
|
195
229
|
comment_tab_str = nil
|
data/lib/sass/files.rb
CHANGED
@@ -17,7 +17,9 @@ module Sass
|
|
17
17
|
# @raise [Sass::SyntaxError] if there's an error in the document.
|
18
18
|
# The caller has responsibility for setting backtrace information, if necessary
|
19
19
|
def tree_for(filename, options)
|
20
|
-
|
20
|
+
default_options = Sass::Engine::DEFAULT_OPTIONS.dup
|
21
|
+
default_options.delete(:syntax)
|
22
|
+
options = default_options.merge!(options)
|
21
23
|
text = File.read(filename)
|
22
24
|
|
23
25
|
if options[:cache] || options[:read_cache]
|
@@ -32,9 +34,9 @@ module Sass
|
|
32
34
|
|
33
35
|
options = options.merge(:filename => filename)
|
34
36
|
if filename =~ /\.scss$/
|
35
|
-
options =
|
37
|
+
options = {:syntax => :scss}.merge(options)
|
36
38
|
elsif filename =~ /\.sass$/
|
37
|
-
options =
|
39
|
+
options = {:syntax => :sass}.merge(options)
|
38
40
|
end
|
39
41
|
|
40
42
|
engine = Sass::Engine.new(text, options)
|
data/lib/sass/script/parser.rb
CHANGED
@@ -186,7 +186,7 @@ RUBY
|
|
186
186
|
production :equals, :interpolation, :single_eq
|
187
187
|
|
188
188
|
def try_op_before_interp(op, prev = nil)
|
189
|
-
return unless @lexer.peek.type == :begin_interpolation
|
189
|
+
return unless @lexer.peek && @lexer.peek.type == :begin_interpolation
|
190
190
|
wb = @lexer.whitespace?(op)
|
191
191
|
str = Script::String.new(Lexer::OPERATORS_REVERSE[op.type])
|
192
192
|
str.line = @lexer.line
|
data/lib/sass/scss/parser.rb
CHANGED
@@ -6,7 +6,9 @@ module Sass
|
|
6
6
|
# The parser for SCSS.
|
7
7
|
# It parses a string of code into a tree of {Sass::Tree::Node}s.
|
8
8
|
class Parser
|
9
|
-
# @param str [String, StringScanner] The source document to parse
|
9
|
+
# @param str [String, StringScanner] The source document to parse.
|
10
|
+
# Note that `Parser` *won't* raise a nice error message if this isn't properly parsed;
|
11
|
+
# for that, you should use the higher-level {Sass::Engine} or {Sass::CSS}.
|
10
12
|
# @param line [Fixnum] The line on which the source string appeared,
|
11
13
|
# if it's part of another document
|
12
14
|
def initialize(str, line = 1)
|
@@ -46,10 +48,7 @@ module Sass
|
|
46
48
|
if @template.is_a?(StringScanner)
|
47
49
|
@template
|
48
50
|
else
|
49
|
-
StringScanner.new(
|
50
|
-
Haml::Util.check_encoding(@template) do |msg, line|
|
51
|
-
raise Sass::SyntaxError.new(msg, :line => line)
|
52
|
-
end.gsub("\r", ""))
|
51
|
+
StringScanner.new(@template.gsub("\r", ""))
|
53
52
|
end
|
54
53
|
end
|
55
54
|
|
@@ -70,7 +70,9 @@ module Sass
|
|
70
70
|
# variable and mixin values
|
71
71
|
def perform!(environment)
|
72
72
|
environment.push_frame(:filename => @filename, :line => @line)
|
73
|
-
|
73
|
+
options = @options.dup
|
74
|
+
options.delete(:syntax)
|
75
|
+
root = Sass::Files.tree_for(full_filename, options)
|
74
76
|
@template = root.template
|
75
77
|
self.children = root.children
|
76
78
|
self.children = perform_children(environment)
|
data/test/haml/engine_test.rb
CHANGED
@@ -1546,7 +1546,6 @@ HAML
|
|
1546
1546
|
unless Haml::Util.ruby1_8?
|
1547
1547
|
def test_default_encoding
|
1548
1548
|
assert_equal(Encoding.find("utf-8"), render(<<HAML.encode("us-ascii")).encoding)
|
1549
|
-
HTML
|
1550
1549
|
%p bar
|
1551
1550
|
%p foo
|
1552
1551
|
HAML
|
@@ -1605,6 +1604,202 @@ HAML
|
|
1605
1604
|
assert_equal(3, e.line)
|
1606
1605
|
assert_equal('Invalid UTF-16LE character "\xFE"', e.message)
|
1607
1606
|
end
|
1607
|
+
|
1608
|
+
def test_same_coding_comment_as_encoding
|
1609
|
+
assert_renders_encoded(<<HTML, <<HAML)
|
1610
|
+
<p>bâr</p>
|
1611
|
+
<p>föö</p>
|
1612
|
+
HTML
|
1613
|
+
-# coding: utf-8
|
1614
|
+
%p bâr
|
1615
|
+
%p föö
|
1616
|
+
HAML
|
1617
|
+
end
|
1618
|
+
|
1619
|
+
def test_different_coding_comment_than_encoding
|
1620
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1621
|
+
<p>bâr</p>
|
1622
|
+
<p>föö</p>
|
1623
|
+
HTML
|
1624
|
+
-# coding: ibm866
|
1625
|
+
%p bâr
|
1626
|
+
%p föö
|
1627
|
+
HAML
|
1628
|
+
end
|
1629
|
+
|
1630
|
+
def test_different_coding_than_system
|
1631
|
+
assert_renders_encoded(<<HTML.encode("IBM866"), <<HAML.encode("IBM866"))
|
1632
|
+
<p>тАЬ</p>
|
1633
|
+
HTML
|
1634
|
+
%p тАЬ
|
1635
|
+
HAML
|
1636
|
+
end
|
1637
|
+
|
1638
|
+
def test_case_insensitive_coding_comment
|
1639
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1640
|
+
<p>bâr</p>
|
1641
|
+
<p>föö</p>
|
1642
|
+
HTML
|
1643
|
+
-# CodINg: IbM866
|
1644
|
+
%p bâr
|
1645
|
+
%p föö
|
1646
|
+
HAML
|
1647
|
+
end
|
1648
|
+
|
1649
|
+
def test_whitespace_insensitive_coding_comment
|
1650
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1651
|
+
<p>bâr</p>
|
1652
|
+
<p>föö</p>
|
1653
|
+
HTML
|
1654
|
+
-#coding:ibm866
|
1655
|
+
%p bâr
|
1656
|
+
%p föö
|
1657
|
+
HAML
|
1658
|
+
end
|
1659
|
+
|
1660
|
+
def test_equals_coding_comment
|
1661
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1662
|
+
<p>bâr</p>
|
1663
|
+
<p>föö</p>
|
1664
|
+
HTML
|
1665
|
+
-# CodINg= ibm866
|
1666
|
+
%p bâr
|
1667
|
+
%p föö
|
1668
|
+
HAML
|
1669
|
+
end
|
1670
|
+
|
1671
|
+
def test_prefixed_coding_comment
|
1672
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1673
|
+
<p>bâr</p>
|
1674
|
+
<p>föö</p>
|
1675
|
+
HTML
|
1676
|
+
-# foo BAR FAOJcoding: ibm866
|
1677
|
+
%p bâr
|
1678
|
+
%p föö
|
1679
|
+
HAML
|
1680
|
+
end
|
1681
|
+
|
1682
|
+
def test_suffixed_coding_comment
|
1683
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1684
|
+
<p>bâr</p>
|
1685
|
+
<p>föö</p>
|
1686
|
+
HTML
|
1687
|
+
-# coding: ibm866 ASFJ (&(&#!$
|
1688
|
+
%p bâr
|
1689
|
+
%p föö
|
1690
|
+
HAML
|
1691
|
+
end
|
1692
|
+
|
1693
|
+
def test_emacs_prefixed_coding_comment
|
1694
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1695
|
+
<p>bâr</p>
|
1696
|
+
<p>föö</p>
|
1697
|
+
HTML
|
1698
|
+
-# -*- coding: ibm866
|
1699
|
+
%p bâr
|
1700
|
+
%p föö
|
1701
|
+
HAML
|
1702
|
+
end
|
1703
|
+
|
1704
|
+
def test_emacs_suffixed_coding_comment
|
1705
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1706
|
+
<p>bâr</p>
|
1707
|
+
<p>föö</p>
|
1708
|
+
HTML
|
1709
|
+
-# coding: ibm866 -*- coding: blah
|
1710
|
+
%p bâr
|
1711
|
+
%p föö
|
1712
|
+
HAML
|
1713
|
+
end
|
1714
|
+
|
1715
|
+
def test_emacs_coding_comment
|
1716
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1717
|
+
<p>bâr</p>
|
1718
|
+
<p>föö</p>
|
1719
|
+
HTML
|
1720
|
+
-# -*- coding: ibm866 -*-
|
1721
|
+
%p bâr
|
1722
|
+
%p föö
|
1723
|
+
HAML
|
1724
|
+
end
|
1725
|
+
|
1726
|
+
def test_emacs_encoding_comment
|
1727
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1728
|
+
<p>bâr</p>
|
1729
|
+
<p>föö</p>
|
1730
|
+
HTML
|
1731
|
+
-# -*- encoding: ibm866 -*-
|
1732
|
+
%p bâr
|
1733
|
+
%p föö
|
1734
|
+
HAML
|
1735
|
+
end
|
1736
|
+
|
1737
|
+
def test_quoted_emacs_coding_comment
|
1738
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1739
|
+
<p>bâr</p>
|
1740
|
+
<p>föö</p>
|
1741
|
+
HTML
|
1742
|
+
-# -*- coding: "ibm866" -*-
|
1743
|
+
%p bâr
|
1744
|
+
%p föö
|
1745
|
+
HAML
|
1746
|
+
end
|
1747
|
+
|
1748
|
+
def test_whitespace_insensitive_emacs_coding_comment
|
1749
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1750
|
+
<p>bâr</p>
|
1751
|
+
<p>föö</p>
|
1752
|
+
HTML
|
1753
|
+
-#-*-coding:ibm866-*-
|
1754
|
+
%p bâr
|
1755
|
+
%p föö
|
1756
|
+
HAML
|
1757
|
+
end
|
1758
|
+
|
1759
|
+
def test_whitespace_insensitive_emacs_coding_comment
|
1760
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1761
|
+
<p>bâr</p>
|
1762
|
+
<p>föö</p>
|
1763
|
+
HTML
|
1764
|
+
-#-*-coding:ibm866-*-
|
1765
|
+
%p bâr
|
1766
|
+
%p föö
|
1767
|
+
HAML
|
1768
|
+
end
|
1769
|
+
|
1770
|
+
def test_one_of_several_emacs_comments
|
1771
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1772
|
+
<p>bâr</p>
|
1773
|
+
<p>föö</p>
|
1774
|
+
HTML
|
1775
|
+
-# -*- foo: bar; coding: ibm866; baz: bang -*-
|
1776
|
+
%p bâr
|
1777
|
+
%p föö
|
1778
|
+
HAML
|
1779
|
+
end
|
1780
|
+
|
1781
|
+
def test_prefixed_emacs_coding_comment
|
1782
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1783
|
+
<p>bâr</p>
|
1784
|
+
<p>föö</p>
|
1785
|
+
HTML
|
1786
|
+
-# foo bar coding: baz -*- coding: ibm866 -*-
|
1787
|
+
%p bâr
|
1788
|
+
%p föö
|
1789
|
+
HAML
|
1790
|
+
end
|
1791
|
+
|
1792
|
+
def test_suffixed_emacs_coding_comment
|
1793
|
+
assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
|
1794
|
+
<p>bâr</p>
|
1795
|
+
<p>föö</p>
|
1796
|
+
HTML
|
1797
|
+
-# -*- coding: ibm866 -*- foo bar coding: baz
|
1798
|
+
%p bâr
|
1799
|
+
%p föö
|
1800
|
+
HAML
|
1801
|
+
end
|
1802
|
+
|
1608
1803
|
end
|
1609
1804
|
|
1610
1805
|
private
|
@@ -1619,4 +1814,10 @@ HAML
|
|
1619
1814
|
<p>föö</p>
|
1620
1815
|
HTML
|
1621
1816
|
end
|
1817
|
+
|
1818
|
+
def assert_renders_encoded(html, haml)
|
1819
|
+
result = render(haml)
|
1820
|
+
assert_equal html.encoding, result.encoding
|
1821
|
+
assert_equal html, result
|
1822
|
+
end
|
1622
1823
|
end
|
data/test/sass/engine_test.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
2
3
|
require File.dirname(__FILE__) + '/../test_helper'
|
3
4
|
require 'sass/engine'
|
4
5
|
require 'stringio'
|
@@ -2038,6 +2039,94 @@ SASS
|
|
2038
2039
|
assert_equal(3, e.sass_line)
|
2039
2040
|
assert_equal('Invalid UTF-16LE character "\xFE"', e.message)
|
2040
2041
|
end
|
2042
|
+
|
2043
|
+
def test_same_charset_as_encoding
|
2044
|
+
assert_renders_encoded(<<CSS, <<SASS)
|
2045
|
+
@charset "utf-8";
|
2046
|
+
fóó {
|
2047
|
+
a: b; }
|
2048
|
+
CSS
|
2049
|
+
@charset "utf-8"
|
2050
|
+
fóó
|
2051
|
+
a: b
|
2052
|
+
SASS
|
2053
|
+
end
|
2054
|
+
|
2055
|
+
def test_different_charset_than_encoding
|
2056
|
+
assert_renders_encoded(<<CSS.force_encoding("IBM866"), <<SASS)
|
2057
|
+
@charset "ibm866";
|
2058
|
+
fóó {
|
2059
|
+
a: b; }
|
2060
|
+
CSS
|
2061
|
+
@charset "ibm866"
|
2062
|
+
fóó
|
2063
|
+
a: b
|
2064
|
+
SASS
|
2065
|
+
end
|
2066
|
+
|
2067
|
+
def test_different_encoding_than_system
|
2068
|
+
assert_renders_encoded(<<CSS.encode("IBM866"), <<SASS.encode("IBM866"))
|
2069
|
+
тАЬ {
|
2070
|
+
a: b; }
|
2071
|
+
CSS
|
2072
|
+
тАЬ
|
2073
|
+
a: b
|
2074
|
+
SASS
|
2075
|
+
end
|
2076
|
+
|
2077
|
+
def test_multibyte_charset
|
2078
|
+
assert_renders_encoded(<<CSS.encode("UTF-16BE"), <<SASS.encode("UTF-16BE").force_encoding("UTF-8"))
|
2079
|
+
@charset "utf-16be";
|
2080
|
+
fóó {
|
2081
|
+
a: b; }
|
2082
|
+
CSS
|
2083
|
+
@charset "utf-16be"
|
2084
|
+
fóó
|
2085
|
+
a: b
|
2086
|
+
SASS
|
2087
|
+
end
|
2088
|
+
|
2089
|
+
def test_multibyte_charset_without_endian_specifier
|
2090
|
+
assert_renders_encoded(<<CSS.encode("UTF-32LE"), <<SASS.encode("UTF-32LE").force_encoding("UTF-8"))
|
2091
|
+
@charset "utf-32";
|
2092
|
+
fóó {
|
2093
|
+
a: b; }
|
2094
|
+
CSS
|
2095
|
+
@charset "utf-32"
|
2096
|
+
fóó
|
2097
|
+
a: b
|
2098
|
+
SASS
|
2099
|
+
end
|
2100
|
+
|
2101
|
+
def test_utf8_bom
|
2102
|
+
assert_renders_encoded(<<CSS, <<SASS.force_encoding("BINARY"))
|
2103
|
+
fóó {
|
2104
|
+
a: b; }
|
2105
|
+
CSS
|
2106
|
+
\uFEFFfóó
|
2107
|
+
a: b
|
2108
|
+
SASS
|
2109
|
+
end
|
2110
|
+
|
2111
|
+
def test_utf16le_bom
|
2112
|
+
assert_renders_encoded(<<CSS.encode("UTF-16LE"), <<SASS.encode("UTF-16LE").force_encoding("BINARY"))
|
2113
|
+
fóó {
|
2114
|
+
a: b; }
|
2115
|
+
CSS
|
2116
|
+
\uFEFFfóó
|
2117
|
+
a: b
|
2118
|
+
SASS
|
2119
|
+
end
|
2120
|
+
|
2121
|
+
def test_utf32be_bom
|
2122
|
+
assert_renders_encoded(<<CSS.encode("UTF-32BE"), <<SASS.encode("UTF-32BE").force_encoding("BINARY"))
|
2123
|
+
fóó {
|
2124
|
+
a: b; }
|
2125
|
+
CSS
|
2126
|
+
\uFEFFfóó
|
2127
|
+
a: b
|
2128
|
+
SASS
|
2129
|
+
end
|
2041
2130
|
end
|
2042
2131
|
|
2043
2132
|
private
|
@@ -2046,6 +2135,12 @@ SASS
|
|
2046
2135
|
expected.each {|k, v| assert_equal(v, hash[k])}
|
2047
2136
|
end
|
2048
2137
|
|
2138
|
+
def assert_renders_encoded(css, sass)
|
2139
|
+
result = render(sass)
|
2140
|
+
assert_equal css.encoding, result.encoding
|
2141
|
+
assert_equal css, result
|
2142
|
+
end
|
2143
|
+
|
2049
2144
|
def render(sass, options = {})
|
2050
2145
|
munge_filename options
|
2051
2146
|
Sass::Engine.new(sass, options).render
|
data/test/test_helper.rb
CHANGED
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: 3.1.
|
4
|
+
version: 3.1.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Weizenbaum
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2010-05-
|
14
|
+
date: 2010-05-30 00:00:00 -04:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|