Sha256: c0d99c8d9cee05089d5e1fcb01b3f845782841b197e48b5eefee38426eca6f8b
Contents?: true
Size: 1.41 KB
Versions: 1
Compression:
Stored size: 1.41 KB
Contents
module HappyHelpers module Helpers module Html def html_tag(name, options = nil, escape = true, &block) "<#{name} #{html_tag_attributes(options, escape) if options}#{block_given? ? ">#{yield if block_given?}</#{name}>" : " />"}" end def html_tag_attributes(options, escape = true) options.map do |k,v| if v v == true ? "#{k}" : "#{k}=\"#{ escape_html(v) }\"" end end.compact.join(" ") end def escape_html(t) #Rack::Utils.escape_html(t.to_s) CGI::escape_html(t.to_s) end def preserve(t) t.chomp("\n").gsub(/\n/, '
').gsub(/\r/, '') end def link_to(name, *target) options = target.last.is_a?(Hash) ? target.pop : {} html_tag(:a, options.merge(:href => url_for(*target))) { name } end def url_for(*what) result = what.flatten.inject('') do |url, item| url << "/%s" % case item when String, Symbol then item.to_s when NilClass then "/" else "%s/%s" % [item.class.to_s.tableize.pluralize, item.try(:to_param) || item.try(:to_id) || item.try(:id)] end url end.gsub(/\/{2,}/, '/').chomp('/') result == "" ? '/' : result end def capture(*args, &block) # TODO: support more than just HAML. :P~ capture_haml(*args, &block) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
happy-helpers-0.1.0.pre7 | lib/happy-helpers/helpers/html.rb |