Skip to content

Instantly share code, notes, and snippets.

@mraaroncruz
Created May 19, 2012 22:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mraaroncruz/2732533 to your computer and use it in GitHub Desktop.
Save mraaroncruz/2732533 to your computer and use it in GitHub Desktop.
Data attribute helper for slim templating
.posts*data(id: post.id, url: post.permalink)
| ...
#=> <div class="post" data-id="123" data-url="/posts/kitten-tossing-banned-in-west-virginia" >...</div>
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