Skip to content

Instantly share code, notes, and snippets.

@gunn
Created January 14, 2011 10:40
Show Gist options
  • Save gunn/779462 to your computer and use it in GitHub Desktop.
Save gunn/779462 to your computer and use it in GitHub Desktop.
Methods of creating data attributes in haml.
require "rubygems"
require "haml"
class Symbol
def -(string)
"#{self}-#{string}".intern
end
end
def method_missing name, *args, &block
name.to_s
end
puts Haml::Engine.new(DATA.read).render
__END__
%h1 Methods for creating a data-edit attribute in haml
%h3 Official
%p{:data=>{:edit=>'whatever'}} content
%h3 Cleaner and flexible
%p{:'data-edit'=>'whatever'} content
%h3 Clean but inflexible
%p(data-edit='whatever') content
%h3 Possibly a mistake
%p{:data-edit=>'whatever'} content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment