Skip to content

Instantly share code, notes, and snippets.

@johno
Last active September 9, 2017 17:47
Show Gist options
  • Save johno/cb362ccfeca926b78082ecbd24fa51ec to your computer and use it in GitHub Desktop.
Save johno/cb362ccfeca926b78082ecbd24fa51ec to your computer and use it in GitHub Desktop.
Example of Tachyons + Erb helpers
module THelpers
# Common button styled anchor
#
# Usage:
#
# <%= button(text: 'Foo', class: 'b--green', attrs: { title: 'Foo' }) %>
def button(text:, href: '!#', padding: 'pa3', class: '', attrs = {})
cx = attrs.delete(:class)
<<-HTML.dedent
<a
href="#{href}"
class="br1 link dim #{padding} #{cx}"
attributify(attrs)
>
#{text}
</a>
HTML
end
private
def attributify(attrs)
attrs.map { |k, v| %Q(#{k}="#{v}") }.join(' ')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment