dom 0.4.1 → 0.4.2

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 +21 -16
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8584195bab3ab80020115f6f91c2707f9d8d452
4
- data.tar.gz: f3cf38faf00c31a4b11823fc920147a6a312355c
3
+ metadata.gz: 88b038b2977ed6d5ebca9f8d1069576c54af8173
4
+ data.tar.gz: fa7ba3f5e0791bff501b4027828a790346ef4627
5
5
  SHA512:
6
- metadata.gz: 719fce10bc791310d7f138db495fc8670443a845e0bfbc153a352835ea873202fd785875f4565ff4d0cac86bfc8ca19d4c8e345bfdfd88afb16dc1ecc3b16b8a
7
- data.tar.gz: 860b198dab65fdaf52b040090b3db0f95ac51e130b68b771efef308796ebefaa767b1de367a6becf0d1655ef8614c17c7d3f8d57127a7fd3ba73f3df1ddb76a4
6
+ metadata.gz: 421b0495c1e9fc83ea6512cd23a8db67a8a06352d8f7759e742fdc2f467c91d6204b3635fc95049741b525fc8a8282df44d9c9b417b5c74ace943e4da0111bd0
7
+ data.tar.gz: 424a460427f206fbb60330bbd1edf8fabde0bba3bb3f58e66d9acb04d1e38c4dc4aa6b9d7b83836ddbc8ac5244ce68516cda99df9c8cc15d45173ebe6eba6a64
data/lib/dom.rb CHANGED
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
1
2
  require "stringio"
2
3
  require "strscan"
3
4
  require "htmlentities"
4
5
 
5
6
  class File
6
- def self.relativize f; f.sub(%r{\A/}o, "".freeze) end
7
+ def self.relativize f; f.sub(%r{\A/}o, "") end
7
8
  end
8
9
 
9
10
  module Dom
@@ -21,29 +22,29 @@ module Dom
21
22
  .prepend($/)
22
23
  end
23
24
  def self.join_pre a, tag
24
- a.map{|e| e.to_s.escape_html(tag).prepend("-->".freeze).concat("<!--#$/".freeze)}
25
+ a.map{|e| e.to_s.escape_html(tag).prepend("-->").concat("<!--#$/")}
25
26
  .join.gsub(/^/o, Indent)
26
- .prepend("<!--#$/".freeze).concat("-->".freeze)
27
+ .prepend("<!--#$/").concat("-->")
27
28
  end
28
29
  def self.attr h
29
- " ".concat(h.map do
30
+ (+" ").concat(h.map do
30
31
  |k, v|
31
32
  v = case v
32
33
  when nil then next
33
- when false then "none".freeze
34
- when true then "".freeze
34
+ when false then "none"
35
+ when true then ""
35
36
  else v
36
37
  end
37
- "%s=\"%s\"".freeze % [hyphenize(k), v]
38
- end.compact.join" ".freeze)
38
+ "%s=\"%s\"" % [hyphenize(k), v]
39
+ end.compact.join" ")
39
40
  end
40
41
  def self.json_attr h; h.map{|k, v| [hyphenize(k), v]}.to_h end
41
- def self.hyphenize sym; sym.to_s.tr("_".freeze, "-".freeze) end
42
+ def self.hyphenize sym; sym.to_s.tr("_", "-") end
42
43
  end
43
44
 
44
45
  module Kernel
45
46
  private def dom tag, mounted: nil, **attr
46
- ("<%s%s />".freeze % [Dom.hyphenize(tag), Dom.attr(attr)])
47
+ ("<%s%s />" % [Dom.hyphenize(tag), Dom.attr(attr)])
47
48
  .dom_escaped.mounted_set(mounted)
48
49
  end
49
50
  private def jsonml tag, attr = nil
@@ -54,7 +55,7 @@ end
54
55
  class String
55
56
  def dom tag, mounted: nil, **attr
56
57
  _tag = Dom.hyphenize(tag)
57
- ("<%s%s>%s</%s>".freeze % [_tag, Dom.attr(attr), escape_html(tag)._ansi2html, _tag])
58
+ ("<%s%s>%s</%s>" % [_tag, Dom.attr(attr), escape_html(tag)._ansi2html, _tag])
58
59
  .dom_escaped.mounted_set(mounted)
59
60
  end
60
61
  def mounted; nil end
@@ -87,8 +88,8 @@ class String
87
88
  sc = StringScanner.new(self)
88
89
  io = StringIO.new
89
90
  io.print(
90
- if sc.scan(/\e\[0?m/o) then '</span>'.freeze
91
- elsif sc.scan(/\e\[0?(\d+)m/o) then '<span class="%s">'.freeze % AnsiColor[sc[1]]
91
+ if sc.scan(/\e\[0?m/o) then '</span>'
92
+ elsif sc.scan(/\e\[0?(\d+)m/o) then '<span class="%s">' % AnsiColor[sc[1]]
92
93
  end ||
93
94
  sc.scan(/./mo)) until sc.eos?
94
95
  io.string
@@ -114,13 +115,17 @@ class DomString < String
114
115
  end
115
116
 
116
117
  class Array
117
- def dom tag, mounted: nil, **attr
118
+ def dom tag = nil, mounted: nil, **attr
118
119
  error_objs = select{|e| e.kind_of?(String).!}
119
120
  unless error_objs.empty?
120
121
  raise "All array elements must be a string: #{error_objs.first.inspect}"
121
122
  end
122
- _tag = Dom.hyphenize(tag)
123
- ("<%s%s>%s</%s>".freeze % [_tag, Dom.attr(attr), Dom.join(self, tag), _tag])
123
+ if tag
124
+ _tag = Dom.hyphenize(tag)
125
+ "<%s%s>%s</%s>" % [_tag, Dom.attr(attr), Dom.join(self, tag), _tag]
126
+ else
127
+ Dom.join(self, tag)
128
+ end
124
129
  .dom_escaped.mounted_set(*map(&:mounted), mounted)
125
130
  end
126
131
  def jsonml tag, attr = nil; [Dom.hyphenize(tag), *([Dom.json_attr(attr)] if attr), *self] end
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.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sawa
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  requirements: []
66
66
  rubyforge_project:
67
- rubygems_version: 2.4.5
67
+ rubygems_version: 2.5.1
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: Creates HTML DOM strings