mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Accept multiple hashes as old attributes
This commit is contained in:
parent
9301172d0f
commit
8d975affc9
2 changed files with 30 additions and 13 deletions
|
@ -10,18 +10,22 @@ module Hamlit
|
|||
class Attribute
|
||||
include Concerns::AttributeBuilder
|
||||
|
||||
def self.build(quote, base, attributes = {})
|
||||
def self.build(quote, *args)
|
||||
builder = self.new(quote)
|
||||
builder.build(base, attributes)
|
||||
builder.build(*args)
|
||||
end
|
||||
|
||||
def initialize(quote)
|
||||
@quote = quote
|
||||
end
|
||||
|
||||
def build(base, attributes)
|
||||
def build(*args)
|
||||
result = ''
|
||||
merge_attributes(base, attributes).each do |key, value|
|
||||
attributes = args.inject({}) do |attributes, arg|
|
||||
merge_attributes(attributes, arg)
|
||||
end
|
||||
|
||||
attributes.each do |key, value|
|
||||
if value == true
|
||||
result += " #{key}"
|
||||
next
|
||||
|
|
|
@ -56,15 +56,6 @@ describe Hamlit::Engine do
|
|||
HTML
|
||||
end
|
||||
|
||||
it 'renders runtime hash attribute' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- hash = { foo: 'bar' }
|
||||
%span{ hash }
|
||||
HAML
|
||||
<span foo='bar'></span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders multi-byte chars as static attribute value' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
%img{ alt: 'こんにちは' }
|
||||
|
@ -73,6 +64,28 @@ describe Hamlit::Engine do
|
|||
HTML
|
||||
end
|
||||
|
||||
describe 'runtime attributes' do
|
||||
it 'renders runtime hash attribute' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- hash = { foo: 'bar' }
|
||||
%span{ hash }
|
||||
HAML
|
||||
<span foo='bar'></span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders multiples hashes' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- h1 = { a: 'b' }
|
||||
- h2 = { c: 'd' }
|
||||
- h3 = { e: 'f' }
|
||||
%span{ h1, h2, h3 }
|
||||
HAML
|
||||
<span a='b' c='d' e='f'></span>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
|
||||
describe 'joinable attributes' do
|
||||
it 'joins class with a space' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
|
|
Loading…
Add table
Reference in a new issue