dom 0.3.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dom.rb +13 -7
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 725c0601cc16a957eb12880a87ce87e01eeb2b47
4
- data.tar.gz: 17d99811b313bafb2e4cd609f445f07192e62359
3
+ metadata.gz: d8584195bab3ab80020115f6f91c2707f9d8d452
4
+ data.tar.gz: f3cf38faf00c31a4b11823fc920147a6a312355c
5
5
  SHA512:
6
- metadata.gz: 7a3e1d5914cb1f676c16bfda0c424857e73fb07f978aec79c702bcbf4ebf61de83185bf1644acd91af76dfd6a3d42610ee50009eda6a162a79426d7f6ca45a99
7
- data.tar.gz: f3b0ae8b55c37bd98edb33b60dd7242d9375282d1d08a08ea05c7d382a9fc8587884975434ead579a53f404837aad88753764da4d86ef9671f9c3565a51bdcd6
6
+ metadata.gz: 719fce10bc791310d7f138db495fc8670443a845e0bfbc153a352835ea873202fd785875f4565ff4d0cac86bfc8ca19d4c8e345bfdfd88afb16dc1ecc3b16b8a
7
+ data.tar.gz: 860b198dab65fdaf52b040090b3db0f95ac51e130b68b771efef308796ebefaa767b1de367a6becf0d1655ef8614c17c7d3f8d57127a7fd3ba73f3df1ddb76a4
data/lib/dom.rb CHANGED
@@ -27,7 +27,14 @@ module Dom
27
27
  end
28
28
  def self.attr h
29
29
  " ".concat(h.map do
30
- |k, v| ("%s=\"%s\"".freeze % [hyphenize(k), v == true ? "".freeze : v]) if v
30
+ |k, v|
31
+ v = case v
32
+ when nil then next
33
+ when false then "none".freeze
34
+ when true then "".freeze
35
+ else v
36
+ end
37
+ "%s=\"%s\"".freeze % [hyphenize(k), v]
31
38
  end.compact.join" ".freeze)
32
39
  end
33
40
  def self.json_attr h; h.map{|k, v| [hyphenize(k), v]}.to_h end
@@ -47,14 +54,13 @@ end
47
54
  class String
48
55
  def dom tag, mounted: nil, **attr
49
56
  _tag = Dom.hyphenize(tag)
50
- ("<%s%s>%s</%s>".freeze % [_tag, Dom.attr(attr), escape_html(tag).ansi2html, _tag])
57
+ ("<%s%s>%s</%s>".freeze % [_tag, Dom.attr(attr), escape_html(tag)._ansi2html, _tag])
51
58
  .dom_escaped.mounted_set(mounted)
52
59
  end
53
60
  def mounted; nil end
54
61
  def escape_html tag = nil
55
62
  case tag; when :style, :script then self else Dom::Coder.encode(self) end
56
63
  end
57
- def unescape_html; Dom::Coder.decode(self) end
58
64
  def dom_escaped; DomString.new(self) end
59
65
  def jsonml tag, attr = nil; [Dom.hyphenize(tag), *([Dom.json_attr(attr)] if attr), self] end
60
66
  AnsiColor = {
@@ -77,7 +83,7 @@ class String
77
83
  "46" => "bg-cyan",
78
84
  "47" => "bg-white",
79
85
  }
80
- def ansi2html
86
+ def _ansi2html
81
87
  sc = StringScanner.new(self)
82
88
  io = StringIO.new
83
89
  io.print(
@@ -87,15 +93,15 @@ class String
87
93
  sc.scan(/./mo)) until sc.eos?
88
94
  io.string
89
95
  end
96
+ def ansi2html; _ansi2html.dom_escaped end
90
97
  end
91
98
 
92
99
  class DomString < String
93
100
  def to_s; self end
94
101
  def escape_html tag = nil; self end
95
102
  def dom_escaped; self end
96
- def % v; super(v).dom_escaped end
97
- def * v; super(v).dom_escaped end
98
- def + v; super(v).dom_escaped end
103
+ # def % v; super(v).dom_escaped end
104
+ # def + v; super(v).dom_escaped end
99
105
  def mounted_set *mounted
100
106
  mounted.compact!
101
107
  if mounted.empty?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sawa