code-ruby 1.8.10 → 1.8.12
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 +14 -1
- data/lib/code/object/string.rb +22 -0
- data/spec/code_spec.rb +14 -0
- 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: fb3e1b31e839dba96ab92f56d22b75ccbc4cd8dbe9438723d80a52e9879f442f
|
|
4
|
+
data.tar.gz: 6e9bbb17dbc604462f1321b56c0626d2f70187a45c29ce4bea89abf710211512
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f8a270b56aeab04407826bf87623ef1c6f5ad04ad55d3645d7884fe941db774cfe1e65626e44470c44d98a84182f1c2c97df3cd6ff872f191619632d09e522f7
|
|
7
|
+
data.tar.gz: c6d5d99bb099906a95f92a956d1295fa6286485cf79503307205ad023ce67b4c619a025aee526c3792db470ba06697a6c717fb49b0b83f70b89a9a9db8eff4bc
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.8.
|
|
1
|
+
1.8.12
|
data/lib/code/object/html.rb
CHANGED
|
@@ -36,6 +36,9 @@ class Code
|
|
|
36
36
|
when "escape"
|
|
37
37
|
sig(args) { Object.maybe }
|
|
38
38
|
code_escape(*code_arguments.raw, **globals)
|
|
39
|
+
when "unescape"
|
|
40
|
+
sig(args) { Object.maybe }
|
|
41
|
+
code_unescape(*code_arguments.raw, **globals)
|
|
39
42
|
when "join"
|
|
40
43
|
sig(args) { [Object.maybe, Object.maybe] }
|
|
41
44
|
code_join(*code_arguments.raw, **globals)
|
|
@@ -103,7 +106,17 @@ class Code
|
|
|
103
106
|
code_value = value_or_function.to_code
|
|
104
107
|
end
|
|
105
108
|
|
|
106
|
-
String.new(CGI.escapeHTML(
|
|
109
|
+
String.new(CGI.escapeHTML(code_value.to_s))
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def self.code_unescape(value_or_function = nil, **globals)
|
|
113
|
+
if value_or_function.is_a?(Function)
|
|
114
|
+
code_value = value_or_function.to_code.call(**globals)
|
|
115
|
+
else
|
|
116
|
+
code_value = value_or_function.to_code
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
String.new(Nokogiri::HTML.fragment(code_value.to_s).text)
|
|
107
120
|
end
|
|
108
121
|
|
|
109
122
|
def self.code_join(first = nil, second = nil, **globals)
|
data/lib/code/object/string.rb
CHANGED
|
@@ -43,6 +43,15 @@ class Code
|
|
|
43
43
|
when "starts_with?"
|
|
44
44
|
sig(args) { String }
|
|
45
45
|
code_starts_with?(code_value)
|
|
46
|
+
when "start_with?"
|
|
47
|
+
sig(args) { String }
|
|
48
|
+
code_start_with?(code_value)
|
|
49
|
+
when "ends_with?"
|
|
50
|
+
sig(args) { String }
|
|
51
|
+
code_ends_with?(code_value)
|
|
52
|
+
when "end_with?"
|
|
53
|
+
sig(args) { String }
|
|
54
|
+
code_end_with?(code_value)
|
|
46
55
|
when "first"
|
|
47
56
|
sig(args) { Integer.maybe }
|
|
48
57
|
code_first(code_value)
|
|
@@ -95,6 +104,19 @@ class Code
|
|
|
95
104
|
Boolean.new(raw.start_with?(code_value.raw))
|
|
96
105
|
end
|
|
97
106
|
|
|
107
|
+
def code_start_with?(value)
|
|
108
|
+
code_starts_with?(value)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def code_end_with?(value)
|
|
112
|
+
code_value = value.to_code
|
|
113
|
+
Boolean.new(raw.end_with?(code_value.raw))
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def code_ends_with?(value)
|
|
117
|
+
code_end_with?(value)
|
|
118
|
+
end
|
|
119
|
+
|
|
98
120
|
def code_plus(other)
|
|
99
121
|
code_other = other.to_code
|
|
100
122
|
String.new(raw + code_other.to_s)
|
data/spec/code_spec.rb
CHANGED
|
@@ -190,6 +190,12 @@ RSpec.describe Code do
|
|
|
190
190
|
%w[9975×14÷8 17456.25],
|
|
191
191
|
%w["Hello".starts_with?("He") true],
|
|
192
192
|
%w["Hello".starts_with?("lo") false],
|
|
193
|
+
%w["Hello".start_with?("He") true],
|
|
194
|
+
%w["Hello".start_with?("lo") false],
|
|
195
|
+
%w["Hello".ends_with?("lo") true],
|
|
196
|
+
%w["Hello".ends_with?("He") false],
|
|
197
|
+
%w["Hello".end_with?("lo") true],
|
|
198
|
+
%w["Hello".end_with?("He") false],
|
|
193
199
|
%w[:Hello.include?(:H) true],
|
|
194
200
|
%w[:admin? :admin?],
|
|
195
201
|
%w[:hello :hello],
|
|
@@ -418,6 +424,14 @@ RSpec.describe Code do
|
|
|
418
424
|
"Html.div { Html.raw(\"<span>ok</span>\") }.to_html",
|
|
419
425
|
"'<div><span>ok</span></div>'"
|
|
420
426
|
],
|
|
427
|
+
[
|
|
428
|
+
"Html.escape(\"<span>&</span>\")",
|
|
429
|
+
"'<span>&</span>'"
|
|
430
|
+
],
|
|
431
|
+
[
|
|
432
|
+
"Html.unescape(\"A B & C\")",
|
|
433
|
+
"'A B & C'"
|
|
434
|
+
],
|
|
421
435
|
["[1, 2, 3].any?", "true"],
|
|
422
436
|
["[1, 2, 3].any?(&:even?)", "true"],
|
|
423
437
|
["[1, 2, 3].none?", "false"],
|