Deas::ErbTags
Template helpers for creating html tags using Erb (or Erubis, etc).
Usage
require 'deas-erbtags'
class MyDeasServer
include Deas::Server
# ...
template_helpers(Deas::ErbTags) # include them all
# OR just include some...
template_helpers(Deas::ErbTags::LinkTo)
template_helpers(Deas::ErbTags::ImageTag)
# ...
endMethods
template_helpers(Deas::ErbTags::Tag)All helper methods are based off of the basic tag method. Tag calls should be invoked with <%= ... -%>:
<%= tag(:br) -%> # => <br />
<%= tag(:h1, 'shizam', :title => "boom") -%> # => <h1 title="boom">shizam</h1>Note: all tag methods take an option hash of html attributes (like above). This use-case is assumed in the examples below.
capture_tag
template_helpers(Deas::ErbTags::Capture)The capture_tag method is used to create tags with nested erb markup. Like the tag method, it creates other tags with a similar API. Unlike the tag method, it takes a block that contains nested markup and does not take content as an arg. Capture tags should be invoked with the <% ... %>:
<% content_tag(:div, :id => 'outer') do %>
<%= tag(:div, 'inner') -%>
<% end %>
# => <div id="outer">\n <div>inner</div>\n</div>\nNote: the convention is that if a tag method is called with a block, capture_tag will be used to generate the tag and it should be invoked with <% ... %>.
capture_render
template_helpers(Deas::ErbTags::Capture)The capture_render method is used to make Deas template render calls with nested erb markup. It calls render with the given args, and captures its output. Call it just as you would render, just invoke the call using <% ... %>.
capture_partial
template_helpers(Deas::ErbTags::Capture)The capture_partial method is used to make Deas template partial calls with nested erb markup. It calls partial with the given args, and captures its output. Call it just as you would partial, just invoke the call using <% ... %>.
link_to
template_helpers(Deas::ErbTags::LinkTo)
link_to "http://google.com"
# => <a href="http://google.com">http://google.com</a>
link_to "google", "http://google.com"
# => <a href="http://google.com">google</a>
link_to("http://google.com"){ tag(:span, 'google') }
# => <a href="http://google.com">\n<span>google</span>\n</a>\nmail_to
template_helpers(Deas::ErbTags::MailTo)
mail_to "me@domain.com"
# => <a href="mailto:me@domain.com">me@domain.com</a>
mail_to "me@domain.com", :at => "_at_", :dot => "_dot_"
# => <a href="mailto:me@domain.com">me_at_domain_dot_com</a>
mail_to "me@domain.com", :disabled => true
# => me@domain.comimage_tag
template_helpers(Deas::ErbTags::ImageTag)
image_tag '/logo.jpg' # => <img src="/logo.jpg" />FormTags
TODO
Installation
Add this line to your application's Gemfile:
gem 'deas-erbtags'
And then execute:
$ bundle
Or install it yourself as:
$ gem install deas-erbtags
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request