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



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

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

#ansi2htmlObject



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

def ansi2html; _ansi2html.dom_escaped end

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



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

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

#dom_escapedObject



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

def dom_escaped; DomString.new(self) end

#escape_html(tag = nil) ⇒ Object



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

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

#jsonml(tag, attr = nil) ⇒ Object



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

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

#mountedObject



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

def mounted; nil end