Module: EUtils
- Defined in:
- lib/el/utils.rb
Class Method Summary collapse
- .html_tag_attrs(attrs) ⇒ Object
- .html_tag_requisites(escape, *args) ⇒ Object
- .requisites_for_link_to(escape, controller, action_or_link = nil, anchor = nil, attributes = {}, &proc) ⇒ Object
Class Method Details
.html_tag_attrs(attrs) ⇒ Object
12 13 14 15 16 |
# File 'lib/el/utils.rb', line 12 def html_tag_attrs attrs attrs.inject('') do |s,kv| s << ' %s="%s"' % kv.map {|x| CGI.escape_html(x.to_s)} end end |
.html_tag_requisites(escape, *args) ⇒ Object
2 3 4 5 6 7 8 9 |
# File 'lib/el/utils.rb', line 2 def html_tag_requisites escape, *args content, attrs = nil, {} args.each {|a| a.is_a?(Hash) ? attrs.update(a) : content = a} [ escape && content ? CGI.escape_html(content.to_s) : content, html_tag_attrs(attrs) ] end |
.requisites_for_link_to(escape, controller, action_or_link = nil, anchor = nil, attributes = {}, &proc) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/el/utils.rb', line 19 def requisites_for_link_to escape, controller, action_or_link = nil, anchor = nil, attributes = {}, &proc if action_or_link.is_a?(Hash) attributes = action_or_link action_or_link = nil elsif anchor.is_a?(Hash) attributes = anchor anchor = nil end (route = controller[action_or_link]) && (action_or_link = route) anchor ||= proc ? proc.call : action_or_link [ action_or_link ? CGI.escapeHTML(action_or_link.to_s) : 'javascript:void(null);', attributes.is_a?(Hash) ? EUtils.html_tag_attrs(attributes) : '', escape && anchor ? CGI.escapeHTML(anchor.to_s) : anchor ] end |