class DataFormatter::Tag
Attributes
content[R]
css_class[R]
sanitizer[R]
surround[R]
tag_name[R]
Public Class Methods
new(args)
click to toggle source
# File lib/data_formatter/tag.rb, line 8 def initialize(args) @sanitizer = args.fetch(:sanitizer, Rack::Utils) @tag_name = args.fetch(:tag_name, "span") @content = args.fetch(:content) @surround = args.fetch(:surround, nil) @css_class = Array(args.fetch(:css_class, "")).compact.join(" ") end
Public Instance Methods
to_s()
click to toggle source
# File lib/data_formatter/tag.rb, line 16 def to_s [open_tag, safe_content, close_tag].join end
Protected Instance Methods
close_tag()
click to toggle source
# File lib/data_formatter/tag.rb, line 42 def close_tag %[</#{ tag_name }>] end
escaped_surround()
click to toggle source
# File lib/data_formatter/tag.rb, line 22 def escaped_surround "\\" + surround end
open_tag()
click to toggle source
# File lib/data_formatter/tag.rb, line 38 def open_tag %[<#{ tag_name } class="#{ css_class }">] end
safe_content()
click to toggle source
# File lib/data_formatter/tag.rb, line 34 def safe_content sanitizer.escape_html(surrounded_content) end
surrounded_content()
click to toggle source
# File lib/data_formatter/tag.rb, line 26 def surrounded_content if surround [surround, content.gsub(surround, escaped_surround), surround].join else content end end