dom 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dom.rb +18 -4
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af86488c43e306be0a7fc24c9343b9c2aab9cb8e
4
- data.tar.gz: a046070bdf9b9031aab60bd4e61c8b7f8280e503
3
+ metadata.gz: 49c3fb432d27f5488f5955f5b99153e274ab55a1
4
+ data.tar.gz: 41b6f84db64138f97586c68287bbf7b7e7f6c3ed
5
5
  SHA512:
6
- metadata.gz: 0d70cc43b27b7b5e473fb6c5c73613f8f6ec579f5a60f0f5a6ece248587bacb3228bcb78f38590d55d711cbac8e61db9bea31f9930932ce2a2f2e554e44f81b4
7
- data.tar.gz: 7583a410834679d1f060451978da8e488828691fdde6f27e508ff3de43d25f1300b1b8eb8d8496ad74aa911afdc7d965484f36acc50bdc0db2752f2b96941b01
6
+ metadata.gz: 8161f52adbecfdcc1ad7ffcdc473a73c5b5441cbe4d8d1fa0265280b1e65f21bcec23ebe612c2f5957c7d49a48063dbca59a901cb7aaca4b0db01fb74e6de06e
7
+ data.tar.gz: 6fde54d4c5a320f265590de3532e28e69941e4f239119c93edbcc20e2ac16cce5d3c14193ac4010a5b6b6e6355b5438d1bb95b8b9738816892242b7a50def64c
data/lib/dom.rb CHANGED
@@ -16,6 +16,7 @@ module Dom
16
16
  "<!--#$/#{"-->#{join_compact(a, tag, "<!--#$/-->")}<!--".gsub(/^/, " ")}#$/-->"
17
17
  end
18
18
  def self.attr h; h.map{|k, v| " #{hyphenize(k)}=\"#{v}\""}.join end
19
+ def self.json_attr h; Hash[h.map{|k, v| [hyphenize(k), v]}] end
19
20
  def self.hyphenize sym; sym.to_s.tr("_", "-") end
20
21
  end
21
22
 
@@ -24,6 +25,7 @@ module Kernel
24
25
  def dom tag, attr = {}
25
26
  "<#{Dom.hyphenize(tag)}#{Dom.attr(attr)} />".escaped
26
27
  end
28
+ def jsonml tag, attr = nil; [Dom.hyphenize(tag), *([Dom.json_attr(attr)] if attr)] end
27
29
  end
28
30
 
29
31
  class String
@@ -36,8 +38,12 @@ class String
36
38
  case tag; when :style, :script then self else CGI.escapeHTML(self) end
37
39
  end
38
40
  def escaped; DomString.new(self) end
41
+ def jsonml tag, attr = nil; [Dom.hyphenize(tag), *([Dom.json_attr(attr)] if attr), self] end
39
42
  AnsiColor = {
40
43
  "1" => "bold",
44
+ "4" => "underline",
45
+ "5" => "blink",
46
+ "7" => "inverse",
41
47
  "30" => "black",
42
48
  "31" => "red",
43
49
  "32" => "green",
@@ -46,16 +52,23 @@ class String
46
52
  "35" => "magenta",
47
53
  "36" => "cyan",
48
54
  "37" => "white",
49
- "90" => "grey"
55
+ "40" => "bg-black",
56
+ "41" => "bg-red",
57
+ "42" => "bg-green",
58
+ "43" => "bg-yellow",
59
+ "44" => "bg-blue",
60
+ "45" => "bg-magenta",
61
+ "46" => "bg-cyan",
62
+ "47" => "bg-white",
50
63
  }
51
64
  def ansi2html
52
65
  ansi = StringScanner.new(escape_html)
53
66
  html = StringIO.new
54
67
  until ansi.eos?
55
- if ansi.scan(/\e\[(3[0-7]|90|1)m/)
56
- html.print(%{<span class="#{AnsiColor[ansi[1]]}">})
57
- elsif ansi.scan(/\e\[0?m/)
68
+ if ansi.scan(/\e\[0?m/)
58
69
  html.print(%{</span>})
70
+ elsif ansi.scan(/\e\[0?(\d+)m/)
71
+ html.print(%{<span class="#{AnsiColor[ansi[1]]}">})
59
72
  else
60
73
  html.print(ansi.scan(/./m))
61
74
  end
@@ -78,6 +91,7 @@ class Array
78
91
  "#{Dom.join(self, tag)}"\
79
92
  "</#{Dom.hyphenize(tag)}>".escaped
80
93
  end
94
+ def jsonml tag, attr = nil; [Dom.hyphenize(tag), *([Dom.json_attr(attr)] if attr), *self] end
81
95
  end
82
96
 
83
97
  Dom.nested
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-30 00:00:00.000000000 Z
11
+ date: 2013-11-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ''
14
14
  email: []
@@ -26,17 +26,17 @@ require_paths:
26
26
  - lib
27
27
  required_ruby_version: !ruby/object:Gem::Requirement
28
28
  requirements:
29
- - - '>='
29
+ - - ">="
30
30
  - !ruby/object:Gem::Version
31
31
  version: '0'
32
32
  required_rubygems_version: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - '>='
34
+ - - ">="
35
35
  - !ruby/object:Gem::Version
36
36
  version: '0'
37
37
  requirements: []
38
38
  rubyforge_project:
39
- rubygems_version: 2.0.6
39
+ rubygems_version: 2.2.0.preview.1
40
40
  signing_key:
41
41
  specification_version: 4
42
42
  summary: Creates HTML DOM strings