1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Support multi lines in Haml::AttributeParser

This commit is contained in:
Takashi Kokubun 2017-04-19 01:51:09 +09:00
parent 9621fa2102
commit 91e89d087f
2 changed files with 8 additions and 2 deletions

View file

@ -13,6 +13,8 @@ module Haml
TYPE = 1
TEXT = 2
IGNORED_TYPES = %i[on_sp on_ignored_nl]
class << self
# @return [Boolean] - return true if AttributeParser.parse can be used.
def available?
@ -46,7 +48,7 @@ module Haml
# @param [Array] tokens - Ripper tokens. Scanned tokens will be destructively removed from this argument.
# @return [String] - attribute name in String
def shift_key!(tokens)
while !tokens.empty? && tokens.first[TYPE] == :on_sp
while !tokens.empty? && IGNORED_TYPES.include?(tokens.first[TYPE])
tokens.shift # ignore spaces
end
@ -128,7 +130,7 @@ module Haml
open_tokens[:paren] += 1
when :on_rparen
open_tokens[:paren] -= 1
when :on_sp
when *IGNORED_TYPES
next if attr_tokens.empty?
end

View file

@ -65,6 +65,10 @@ class AttributeParserTeset < Haml::TestCase
it { assert_parse(nil, '%Q[f#{o}o] => bar ') }
end
describe 'multi lines' do
it { assert_parse({ 'a' => 'b', 'c' => 'd' }, "{a: b,\nc: d}") }
end
if RUBY_VERSION >= '2.2.0'
describe '"foo": bar' do
it { assert_parse({ 'foo' => '()' }, '{"foo":()}') }