Module: Niles::Helpers::Html
- Included in:
- Niles::Helpers
- Defined in:
- lib/niles/helpers/html.rb
Instance Method Summary collapse
- #escape_html(t) ⇒ Object
- #html_tag(name, options = nil, escape = true, &block) ⇒ Object
- #html_tag_attributes(options, escape = true) ⇒ Object
- #preserve(t) ⇒ Object
Instance Method Details
#escape_html(t) ⇒ Object
16 17 18 |
# File 'lib/niles/helpers/html.rb', line 16 def escape_html(t) Rack::Utils.escape_html(t.to_s) end |
#html_tag(name, options = nil, escape = true, &block) ⇒ Object
4 5 6 |
# File 'lib/niles/helpers/html.rb', line 4 def html_tag(name, = nil, escape = true, &block) "<#{name} #{html_tag_attributes(, escape) if }#{block_given? ? ">#{yield if block_given?}</#{name}>" : " />"}" end |
#html_tag_attributes(options, escape = true) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/niles/helpers/html.rb', line 8 def html_tag_attributes(, escape = true) .map do |k,v| if v v == true ? "#{k}" : "#{k}=\"#{ escape_html(v) }\"" end end.compact.join(" ") end |
#preserve(t) ⇒ Object
20 21 22 |
# File 'lib/niles/helpers/html.rb', line 20 def preserve(t) t.chomp("\n").gsub(/\n/, '
').gsub(/\r/, '') end |