module Egalite::HTMLTagBuilder
Public Class Methods
a(url, s)
click to toggle source
# File lib/egalite/helper.rb, line 42 def a(url, s) tag('a', s, :href=>url) end
li(array)
click to toggle source
# File lib/egalite/helper.rb, line 45 def li(array) array.map{ |s| "<li>#{escape_html(s)}</li>" }.join("\n") end
ol(array)
click to toggle source
# File lib/egalite/helper.rb, line 48 def ol(array) "<ol>#{li(array)}</ol>" end
tag(tag, s, attributes = {})
click to toggle source
# File lib/egalite/helper.rb, line 31 def tag(tag, s, attributes = {}) tag_open(tag, attributes) + escape_html(s) + tag_close(tag, {}) end
ul(array)
click to toggle source
# File lib/egalite/helper.rb, line 51 def ul(array) "<ul>#{li(array)}</ul>" end
Public Instance Methods
_tag(name , soc, attributes)
click to toggle source
# File lib/egalite/helper.rb, line 8 def _tag(name , soc, attributes) close = soc == :close ? '/' : '' solo = soc == :solo ? '/' : '' atr = if attributes and not attributes.empty? s = attributes.map { |k,v| "#{escape_html(k)}='#{escape_html(v)}'" }.join(' ') " #{s}" else "" end NonEscapeString.new("<#{close}#{escape_html(name)}#{atr}#{solo}>") end
escape_html(s)
click to toggle source
# File lib/egalite/helper.rb, line 5 def escape_html(s) s.is_a?(NonEscapeString) ? s : NonEscapeString.new(Rack::Utils.escape_html(s)) end
tag_close(name, attributes = {})
click to toggle source
# File lib/egalite/helper.rb, line 26 def tag_close(name, attributes = {}) _tag(name, :close, attributes) end
tag_open(name, attributes = {})
click to toggle source
# File lib/egalite/helper.rb, line 23 def tag_open(name, attributes = {}) _tag(name, :open, attributes) end
tag_solo(name, attributes = {})
click to toggle source
# File lib/egalite/helper.rb, line 20 def tag_solo(name, attributes = {}) _tag(name, :solo, attributes) end