Created
May 19, 2012 22:04
-
-
Save mraaroncruz/2732533 to your computer and use it in GitHub Desktop.
Data attribute helper for slim templating
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.posts*data(id: post.id, url: post.permalink) | |
| ... | |
#=> <div class="post" data-id="123" data-url="/posts/kitten-tossing-banned-in-west-virginia" >...</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DataHelper | |
def data(hash) | |
hash.keys.each_with_object({}){ |key, data_hash| data_hash["data-#{key}"] = hash[key] } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment