Skip to content

Commit

Permalink
Support building dynamic attributes at runtime (Buffer#attributes())
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Dec 4, 2013
1 parent 25695ed commit 4d1296f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions opal/opal-haml.rb
Expand Up @@ -7,5 +7,26 @@ def buffer
end

alias << append

# allow tags in haml to have dynamic attributes
def attributes(class_id, obj_ref, *attributes_hashes)
attributes = class_id

attributes_hashes.each do |hash|
attributes.update hash
end

result = attributes.collect do |attr, value|
if value == true
next " #{attr}"
elsif value == false
next
else
" #{attr}='#{value}'"
end
end

result.join
end
end
end

0 comments on commit 4d1296f

Please sign in to comment.