Module: Niles::Helpers::Html

Included in:
Niles::Helpers
Defined in:
lib/niles/helpers/html.rb

Instance Method Summary collapse

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, options = nil, escape = true, &block)
  "<#{name} #{html_tag_attributes(options, escape) if options}#{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(options, escape = true)
  options.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/, '&#x000A;').gsub(/\r/, '')
end