code-ruby 1.8.0 → 1.8.1

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: d066f06aab2a2ae00bcbcbeedea154305c0fbc19f920ca13cb4cef1d787a1884
4
+ data.tar.gz: eca3f011e3bd8811743a3412947fff667c8c1e0f5838ccc8c4e7d3e2360ab6e8
5
5
  SHA512:
6
- metadata.gz: eedb4f5942efc5ef5ea2f4ee28a1cac8f136d05a9f465949cc8d2b4ad81bdc8f4ef1008358dfcbabb3cf939cbdfe4662f817204a652fdbb1b393f9649a1b0ec9
7
- data.tar.gz: '089de3a0fb083295533c6f5ea5024754eaa450e84201792416313dff0544638f75c12e13442714ae3461d8c239b679edb5b2c38300c555d4ded3316cb3f5fd0b'
6
+ metadata.gz: bdc06dddc2a05ce5c88f8dabfa25eb8b3a44811f94d99dcb65011dc8ed05daeabcbc68a2431d3705ec90435838f13fe88663a6cd4299f1dbb1da454972694c57
7
+ data.tar.gz: 0cc4c89d00285ff43b96916c05855dbd74671c001b115dcf4a303323af6f563b2b813e872080cc115f4a26f3b5cc30f812011e191044ae70d94125b7ae6cd5b6
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.1)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.0
1
+ 1.8.1
@@ -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
 
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié