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 +4 -4
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/code/object/html.rb +18 -6
- data/spec/code_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d066f06aab2a2ae00bcbcbeedea154305c0fbc19f920ca13cb4cef1d787a1884
|
|
4
|
+
data.tar.gz: eca3f011e3bd8811743a3412947fff667c8c1e0f5838ccc8c4e7d3e2360ab6e8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bdc06dddc2a05ce5c88f8dabfa25eb8b3a44811f94d99dcb65011dc8ed05daeabcbc68a2431d3705ec90435838f13fe88663a6cd4299f1dbb1da454972694c57
|
|
7
|
+
data.tar.gz: 0cc4c89d00285ff43b96916c05855dbd74671c001b115dcf4a303323af6f563b2b813e872080cc115f4a26f3b5cc30f812011e191044ae70d94125b7ae6cd5b6
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.8.
|
|
1
|
+
1.8.1
|
data/lib/code/object/html.rb
CHANGED
|
@@ -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.
|
|
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(
|
|
110
|
-
if
|
|
111
|
-
code_contents =
|
|
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 =
|
|
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
|
-
|
|
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
|
[
|