code-ruby 1.8.0 → 1.8.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93a5aca92120dbf487443b4cf2f88e3c407326246c38b059bd865f2db1fba0c3
4
- data.tar.gz: bd1b6b84eb2adb4f63ce11ccdb81e7666feeece6339ba3cca9a84b33490f076b
3
+ metadata.gz: 55e60830750c2edd542fbb6b1abc4a8a14f8a5dbd72aec0f063b4053588ce54f
4
+ data.tar.gz: 897d7b444866649e87bdac233d23682ab38f72ca59199e91a9b6d7f12b71185d
5
5
  SHA512:
6
- metadata.gz: eedb4f5942efc5ef5ea2f4ee28a1cac8f136d05a9f465949cc8d2b4ad81bdc8f4ef1008358dfcbabb3cf939cbdfe4662f817204a652fdbb1b393f9649a1b0ec9
7
- data.tar.gz: '089de3a0fb083295533c6f5ea5024754eaa450e84201792416313dff0544638f75c12e13442714ae3461d8c239b679edb5b2c38300c555d4ded3316cb3f5fd0b'
6
+ metadata.gz: 9e9d5d59a84835e1d1910bcd8b12c4718d6a6973fa0bbe3f373c1d01ea2b59fa0f4da760ce06d1f26f297baed8f50342fd8e8edf743cd71e36f3149101aafcd4
7
+ data.tar.gz: b629ba0f907f66f8a3d24eb6931b9799e6b22edf81c4e95e10cd73016e66ed2caff78c2bcb77fb3cb4743174e2bad15d58fc758ecea5d6bd1f4b83a8e4fb7151
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-ruby (1.8.0)
4
+ code-ruby (1.8.2)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.0
1
+ 1.8.2
@@ -11,6 +11,18 @@ class Code
11
11
  code_value = code_arguments.code_first
12
12
 
13
13
  case code_operator.to_s
14
+ when "present?"
15
+ sig(args)
16
+ code_present?
17
+ when "blank?"
18
+ sig(args)
19
+ code_blank?
20
+ when "presence"
21
+ sig(args)
22
+ code_presence
23
+ when "presence_in"
24
+ sig(args) { Object::List }
25
+ code_presence_in(code_value)
14
26
  when "new"
15
27
  sig(args) { Object.repeat }
16
28
  code_new(*code_arguments.raw)
@@ -98,6 +110,9 @@ class Code
98
110
  when "to_string"
99
111
  sig(args)
100
112
  code_to_string
113
+ when "inspect"
114
+ sig(args)
115
+ code_inspect
101
116
  when "to_time"
102
117
  sig(args)
103
118
  code_to_time
@@ -448,6 +463,32 @@ class Code
448
463
  def code_methods
449
464
  Object::List.new(methods)
450
465
  end
466
+
467
+ def present?
468
+ true
469
+ end
470
+
471
+ def blank?
472
+ !present?
473
+ end
474
+
475
+ def code_present?
476
+ Object::Boolean.new(present?)
477
+ end
478
+
479
+ def code_blank?
480
+ Object::Boolean.new(blank?)
481
+ end
482
+
483
+ def code_presence
484
+ present? ? self : Object::Nothing.new
485
+ end
486
+
487
+ def code_presence_in(list = [])
488
+ code_list = list.to_code
489
+
490
+ code_list.code_include?(self).truthy? ? self : Object::Nothing.new
491
+ end
451
492
  end
452
493
  end
453
494
  end
@@ -49,6 +49,10 @@ class Code
49
49
  def truthy?
50
50
  raw
51
51
  end
52
+
53
+ def present?
54
+ raw.present?
55
+ end
52
56
  end
53
57
  end
54
58
  end
@@ -1028,6 +1028,10 @@ class Code
1028
1028
 
1029
1029
  -1
1030
1030
  end
1031
+
1032
+ def present?
1033
+ raw.present?
1034
+ end
1031
1035
  end
1032
1036
  end
1033
1037
  end
@@ -37,7 +37,7 @@ class Code
37
37
  sig(args) { Object.maybe }
38
38
  code_escape(*code_arguments.raw, **globals)
39
39
  when "join"
40
- sig(args) { Object.repeat }
40
+ sig(args) { [Object.maybe, Object.maybe] }
41
41
  code_join(*code_arguments.raw, **globals)
42
42
  when "text"
43
43
  sig(args) { Object.maybe }
@@ -106,22 +106,34 @@ class Code
106
106
  String.new(CGI.escapeHTML(value.to_s))
107
107
  end
108
108
 
109
- def self.code_join(*contents_or_function, **globals)
110
- if contents_or_function.is_a?(Function)
111
- code_contents = contents_or_function.to_code.call(**globals)
109
+ def self.code_join(first = nil, second = nil, **globals)
110
+ if second.is_a?(Function)
111
+ code_contents = second.to_code.call(**globals)
112
+ code_separator = first.to_code
112
113
  else
113
- code_contents = contents_or_function.to_code
114
+ code_contents = first.to_code
115
+ code_separator = second.to_code
114
116
  end
115
117
 
116
118
  fragment = Nokogiri::HTML::DocumentFragment.parse("")
117
119
 
118
- code_contents.raw.each do |code_content|
120
+ return Html.new(fragment) if code_contents.nothing?
121
+ return Html.new(fragment) unless code_contents.is_a?(List)
122
+
123
+ code_contents.raw.each.with_index do |code_content, index|
119
124
  if code_content.is_an?(Html)
120
125
  content = Nokogiri::HTML::DocumentFragment.parse(code_content.to_html)
121
126
  else
122
127
  content = Nokogiri::XML::Text.new(code_content.to_s, fragment.document)
123
128
  end
124
129
 
130
+ if code_separator.is_an?(Html)
131
+ separator = Nokogiri::HTML::DocumentFragment.parse(code_separator.to_html)
132
+ else
133
+ separator = Nokogiri::XML::Text.new(code_separator.to_s, fragment.document)
134
+ end
135
+
136
+ fragment.add_child(separator) unless index.zero?
125
137
  fragment.add_child(content)
126
138
  end
127
139
 
@@ -1035,6 +1035,10 @@ class Code
1035
1035
  def any?
1036
1036
  code_any?.truthy?
1037
1037
  end
1038
+
1039
+ def present?
1040
+ raw.present?
1041
+ end
1038
1042
  end
1039
1043
  end
1040
1044
  end
@@ -11,6 +11,10 @@ class Code
11
11
  false
12
12
  end
13
13
 
14
+ def present?
15
+ false
16
+ end
17
+
14
18
  def nothing?
15
19
  true
16
20
  end
@@ -118,6 +118,10 @@ class Code
118
118
  def code_size
119
119
  Integer.new(raw.size)
120
120
  end
121
+
122
+ def present?
123
+ raw.present?
124
+ end
121
125
  end
122
126
  end
123
127
  end
data/spec/code_spec.rb CHANGED
@@ -385,8 +385,8 @@ RSpec.describe Code do
385
385
  "'<div><p><span>hello</span></p></div>'"
386
386
  ],
387
387
  [
388
- "Html.join(Html.p { :hello }, Html.p { :world }).to_html",
389
- "'<p>hello</p><p>world</p>'"
388
+ "Html.join([Html.p { :hello }, Html.p { :world }], Html.br).to_html",
389
+ "'<p>hello</p><br><p>world</p>'"
390
390
  ],
391
391
  ["Html.join.to_html", "''"],
392
392
  [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié