0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Deas template helpers for creating HTML tags using Erb.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.3

Runtime

~> 0.23
 Project Readme

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)

  # ...

end

Methods

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>\n

Note: 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>\n

mail_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.com

image_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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request