genki (owner)

Revisions

gist: 154428 Download_button fork
public
Public Clone URL: git://gist.github.com/154428.git
Embed All Files: show embed
tag_helper.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Sinatra
  module TagHelper
    def tag(name, contents = nil, attrs = {}, &block)
      attrs, contents = contents, nil if contents.is_a?(Hash)
      contents = capture(&block) if block_given?
      open_tag(name, attrs) + contents.to_s + close_tag(name)
    end
 
    def open_tag(name, attrs = nil)
      "<#{name}#{' ' + attrs.to_html_attributes unless attrs.blank?}>"
    end
 
    def close_tag(name)
      "</#{name}>"
    end
 
    def self_closing_tag(name, attrs = nil)
      "<#{name}#{' ' + attrs.to_html_attributes if attrs && !attrs.empty?}/>"
    end
  end
 
  helpers TagHelper
end