Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/dom.rb

Direct Known Subclasses

DomString

Constant Summary collapse

AnsiColor =
{
  "1" => "bold",
  "4" => "underline",
  "30" => "black",
  "31" => "red",
  "32" => "green",
  "33" => "yellow",
  "34" => "blue",
  "35" => "magenta",
  "36" => "cyan",
  "37" => "white",
  "40" => "bg-black",
  "41" => "bg-red",
  "42" => "bg-green",
  "43" => "bg-yellow",
  "44" => "bg-blue",
  "45" => "bg-magenta",
  "46" => "bg-cyan",
  "47" => "bg-white",
}

Instance Method Summary collapse

Instance Method Details

#_ansi2htmlObject



87
88
89
90
91
92
93
94
95
96
# File 'lib/dom.rb', line 87

def _ansi2html
  sc = StringScanner.new(self)
  io = StringIO.new
  io.print(
    if sc.scan(/\e\[0?m/o) then '</span>'
    elsif sc.scan(/\e\[0?(\d+)m/o) then '<span class="%s">' % AnsiColor[sc[1]]
    end ||
  sc.scan(/./mo)) until sc.eos?
  io.string
end

#ansi2htmlObject



97
# File 'lib/dom.rb', line 97

def ansi2html; _ansi2html.dom_escaped end

#dom(tag, mounted: nil, **attr) ⇒ Object



56
57
58
59
60
# File 'lib/dom.rb', line 56

def dom tag, mounted: nil, **attr
  _tag = Dom.hyphenize(tag)
  ("<%s%s>%s</%s>" % [_tag, Dom.attr(attr), escape_html(tag)._ansi2html, _tag])
  .dom_escaped.mounted_set(mounted)
end

#dom_escapedObject



65
# File 'lib/dom.rb', line 65

def dom_escaped; DomString.new(self) end

#escape_html(tag = nil) ⇒ Object



62
63
64
# File 'lib/dom.rb', line 62

def escape_html tag = nil
  case tag; when :style, :script then self else Dom::Coder.encode(self) end
end

#jsonml(tag, attr = nil) ⇒ Object



66
# File 'lib/dom.rb', line 66

def jsonml tag, attr = nil; [Dom.hyphenize(tag), *([Dom.json_attr(attr)] if attr), self] end

#mountedObject



61
# File 'lib/dom.rb', line 61

def mounted; nil end